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

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

[复制链接]

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

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

admin 楼主

2018-1-10 17:48:41

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

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

x
5 `  p6 L* h* b
/ E3 M3 v3 _" L) B6 ^& m! S/ C
NX二次开发源码分享: 获取当前Reference Component的通用方法: h0 \/ g/ P& G0 u; Y0 M) O. `$ p  L1 o

% f6 [8 K3 `$ t5 W% e' X7 x0 S& G
( E4 ^) h/ \6 ], Y' M' d* L( @
8 i. c4 {. {! f+ Y/ Q& G, E& p/ }/ C+ H, }$ |$ h% l

" [& k- N2 n- _7 g2 B/ G  ^[mw_shl_code=c,true]static logical attribute_exists(Component cmpnt, char *title)
3 C3 j, P4 B3 f6 [# @: e6 q{
2 V8 C' M' o; p( ~
$ W4 j$ b1 q- W% Z8 z1 A//  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.$ g, W, Y8 q  }9 a' B& I
    ) c. M* B' u* P/ @4 u' B: F
    logical
# S1 M! X4 m+ P8 J* W; E        hasRefAttr = FALSE;
4 H, E4 a) d4 Z
, q+ {7 b% @' R; E5 s    hasRefAttr = cmpnt.HasUserAttribute(RO, NXObject::AttributeTypeAny, -1);
' Z! z8 `- D, u% E5 j  I6 i" c6 d  V  n
    if(hasRefAttr == TRUE)5 T! r' X0 k( P6 S7 H, x' v9 U
    {* j+ x" F5 q" W9 z% a
        return TRUE;
, R1 J. r9 o9 @: e6 }. B" q    }' J% c' v/ L6 b& e) r5 ]

! B- w8 [- ~4 J( z% \    return FALSE;3 @; J, ~* d7 H6 C# I7 q) C
2 A0 J1 ^/ H+ F6 R8 F0 j8 D; v
}/ M5 N& H; X- @* k1 G7 V

5 m7 _% r5 ]! B" q* bstatic tag_t ask_next_of_type(tag_t part, int type, tag_t object)
6 t- z* `1 y1 N0 W& r* p+ [{6 [$ I5 ?- C9 V5 C  o6 H$ A
    UF_CALL(UF_OBJ_cycle_objs_in_part(part, type, &object));: I9 {% m' y% G, ^
    return (object);( N; g5 [' y4 x1 m" C7 e3 T
}
5 l6 k) b+ r6 ^, |/ n3 r8 b# H4 y+ y& d
static void do_it(void)
, ?5 B7 X5 u/ J" Q) z9 T4 h{% \; j8 N& a$ p4 j$ n; H+ v1 i9 u
    // Assumes that the display part is the top of the assembly, k4 a& o3 N1 v2 y

" z( N% j2 d3 d: x1 d    tag_t' g9 n/ ?1 R' x: r+ m4 T
        dispPart = UF_PART_ask_display_part();
& {$ R+ H( p3 \' Z" S& r' A- b
/ i8 S% R2 O( B  h$ w    if(NULL_TAG == dispPart) 8 k4 P! l; U; G$ `; {* \
    {4 h3 a  G1 |% t% }# o$ W# O
        ECHO("Program requires an active displayed part");
8 h8 o7 M, d4 J' O        return;% z- m! h" {0 R' A3 W" E" t
    }- D0 X# |* r& N% c4 Q

. u& @# D! w1 R9 r    tag_t
, s$ q9 H9 G+ r. f6 k        compTag = NULL_TAG;( p: f, V' l' ], B

8 t; ~, @3 P  t% o  C    while((compTag = ask_next_of_type(dispPart, UF_component_type, compTag)) != NULL_TAG)# P$ ]. t+ E6 p8 f% v4 G$ m
    {
8 w- [. B+ E% A& V        char/ m& E9 F' Z# L! R) X1 q/ G
            msg[512] = {""},
% W% o% n7 O, O            fSpec[256] = {""};
' B" x* f; [& E: O0 M8 u
+ J7 D1 I9 B  h. K$ o, h4 E$ D            tag_t7 Y) d: i0 M5 }
                protoPart = UF_ASSEM_ask_prototype_of_occ(compTag);
% W+ D- m1 W' z$ p6 }0 H3 F+ J
- s) r; m" U3 _* W' l4 u            UF_CALL(UF_PART_ask_part_name(protoPart, fSpec));/ A) b+ @8 F$ N5 E7 ~
5 K9 h6 G/ s6 N* T
            // uncomment to see all component names:
6 b. m; Y0 b2 d# D9 N8 K8 I$ g+ Z            //sprintf(msg, "Component Part: %s\n", fSpec);
8 z: X# n4 i  ^) k% }$ x            //ECHO(msg);
6 L+ Q) U9 k0 ?" T% T
5 @/ T9 W* J3 `$ C0 L            Component *theComponent = (Component *)NXObjectManager::Get(compTag);
% D) b3 J/ Z6 J! q            if (attribute_exists(*theComponent, RO))6 S: H/ D7 M5 U* i$ H. Q4 W
            {4 G( A; D. R' D
                sprintf(msg, "**** Reference-Only Component: %s\n", fSpec);
: p9 E6 `, q  O                ECHO(msg);) j) |4 m+ k! b& h& x1 j5 S
            }
1 n1 B4 }# \3 Z- f2 O9 {    }& H- M# ]" i8 w7 s) C1 F5 _
}[/mw_shl_code]- @# W2 ~0 o- x8 }% \# d  @* D# N
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了