PLM之家PLMHome-国产软件践行者

[二次开发源码] NX二次开发源码分享: 获取当前Reference Component的通用方法

[复制链接]

2018-1-10 17:48:41 2171 0

admin 发表于 2018-1-10 17:48:41 |阅读模式

admin 楼主

2018-1-10 17:48:41

请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!

您需要 登录 才可以下载或查看,没有账号?注册

x
/ _2 d- [( U. Z0 _" V- e
2 S3 A( Y4 C1 i1 r3 n. X! O
NX二次开发源码分享: 获取当前Reference Component的通用方法: W$ N: I' s8 c3 f; ^

- ]6 `  S9 d  J. G, ]) R, _  a+ ~) B4 f0 v/ a+ U3 w
) S7 |5 j! [6 N' S+ L, x' x, c
9 k6 i  l# d: U* t. W3 R2 q  l
/ S! N! d; F: N9 @# N4 s' D
[mw_shl_code=c,true]static logical attribute_exists(Component cmpnt, char *title)
9 c& N: W* V  i5 i4 {{$ H- O5 L5 K* w6 x( `9 q3 [8 r

) k+ W; ~+ |5 o1 K9 l) M$ u//  The traditional method of asking for all of the components recursively//  does not work if you are looking for reference-only components,//  because they are not retured when you ask for the children.////  Also, asking for the AssembliesGeneralPropertiesBuilder.ReferenceComponent //  Property  does not work in versions earlier than NX12.////  The workaround is to cycle for components the old-fashioned way,//  and then ask whether each one has the REFERENCE_COMPONENT attribute.////  If you have multiple occurrences of a given component in the assembly,//  each one will be reported.
% i0 o! e+ z  {9 q+ ^( k( @   
* R$ A8 B; |6 I4 w; {    logical/ P( P2 ]/ Q+ c$ [
        hasRefAttr = FALSE;' N# R  a5 v/ ]: m; ?

, }) r3 C* L, e; U9 }# ^/ u    hasRefAttr = cmpnt.HasUserAttribute(RO, NXObject::AttributeTypeAny, -1);6 L' F  Y4 n; O% B% O$ S
, d2 i" d/ M( v# }
    if(hasRefAttr == TRUE)
# S1 _9 D" N2 T- x9 W    {
1 D  a. J3 w2 o9 U        return TRUE;
3 G( i, Q, b7 W+ C3 n  {    }
; k: L+ h0 V) k& G! s* X; [2 F  ^! h- W( J  x) Z! q: p; v' H
    return FALSE;2 }  B$ ]; @! J% E4 z! w

6 n* C8 {0 e$ s. a7 S6 m  y6 b( q}
2 Z- J1 l# F' Y0 C2 m
1 B8 ?) B$ }4 y+ Q9 A1 B0 lstatic tag_t ask_next_of_type(tag_t part, int type, tag_t object)
! X1 \" H$ V1 t5 y, `, Z+ |" ]" A{5 J; w# u3 e) r
    UF_CALL(UF_OBJ_cycle_objs_in_part(part, type, &object));# }2 ?* _9 l% O! p3 O
    return (object);
8 }0 H6 V' m( x, R$ v: N}
& K) W( T# L9 @+ g8 g
7 H: V, S( c. A! e2 }& S& ^static void do_it(void)
. l2 {) _) Q: b! p: k1 {2 c{7 C, u' [5 C: O( D9 @* h/ h8 m) r
    // Assumes that the display part is the top of the assembly' F7 ^  R% C& F5 o

3 v' _  F. R" }1 W& C% \    tag_t8 \, I1 H* M+ G
        dispPart = UF_PART_ask_display_part();( P7 U* s0 Q# X6 y- Q' {7 w
5 z/ h: m; e* F( ]4 \
    if(NULL_TAG == dispPart)
1 e2 O2 Y( i/ B  `6 n    {
, g7 ~6 L& @1 J5 |# r* i" ~        ECHO("Program requires an active displayed part");& |0 }4 I7 u0 D  O
        return;
/ \! S5 K( Y2 A3 y: @, p' M    }. w2 `/ A/ K# U9 l5 |0 E4 v& A

) y$ D% w7 @- n! p/ k    tag_t
* H  K  y$ ^0 }" F        compTag = NULL_TAG;
( U% x! ?  d: X& j8 A: g$ x4 U: _2 X. ^8 a7 ^: T
    while((compTag = ask_next_of_type(dispPart, UF_component_type, compTag)) != NULL_TAG)
, `8 B2 h% |* W    {8 [! T9 y4 Y. _" F
        char
' Z; G' D3 Q( @' h1 B( [            msg[512] = {""},! m+ R" s6 A  e" X' V5 W
            fSpec[256] = {""};
4 t" C0 _8 f  v% C; p6 W: H
6 Y, u" N# |* q- D0 b            tag_t
( S8 h$ y9 k5 f+ Q- q: s/ _                protoPart = UF_ASSEM_ask_prototype_of_occ(compTag);' M; K. {! P- S% ?, ~# J

( c" n+ \1 T7 U" K* P0 P            UF_CALL(UF_PART_ask_part_name(protoPart, fSpec));
& G. {1 _  t3 v* a2 `; R
9 e. b2 T2 R7 B            // uncomment to see all component names:
; Y) y- x( Q8 k( Q7 }1 n            //sprintf(msg, "Component Part: %s\n", fSpec);
5 j6 J9 l( u. Y3 t            //ECHO(msg);
) X: M; ?- u& z% V* U" a: a7 a/ j2 V$ C* X8 T
            Component *theComponent = (Component *)NXObjectManager::Get(compTag);
8 _+ C: J. K& L- Q+ S% j6 V            if (attribute_exists(*theComponent, RO))
* L$ U5 _7 R, r& h! Y- A            {
' J& l. _8 ?$ l2 a- ?1 r                sprintf(msg, "**** Reference-Only Component: %s\n", fSpec);3 [! L; y# a7 i2 X
                ECHO(msg);
- I9 i) J5 C) M: a            }
5 k5 U8 K* T' E% i3 O( K) @    }+ \9 h4 J) j9 I0 z( A% h! S3 k" c
}[/mw_shl_code]
% m" X" @7 K$ R
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了