PLM之家PLMHome-工业软件践行者

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

[复制链接]

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

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

积分
82170
QQ
发表于 2018-1-10 17:48:41 | 显示全部楼层 |阅读模式

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

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

x
* C# C. Y$ ]+ A, f
2 R0 O( n+ l+ a2 G0 k3 ~
NX二次开发源码分享: 获取当前Reference Component的通用方法7 ^6 [' _2 A% h6 p
  R7 c$ t% x* K  |: X

. v* ^- l9 i  a  O/ ?$ @
6 s" |! ^0 ?, E! ^) S! V
3 Z1 S  Q/ ^7 @( Y/ K) C& o( C+ C5 Z( U9 y% @) t, C
[mw_shl_code=c,true]static logical attribute_exists(Component cmpnt, char *title)/ {& Z6 ~9 _0 K7 Z4 L
{2 _3 {. ]1 Q0 E! y

( F& Y. C+ U! Y( a, Z$ r//  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.
* d5 R# g, q& B6 S) }% }: Z/ J( e: D    ; ~0 a2 i; k* a& h4 `3 v5 u8 s6 }
    logical
- f; C& w0 U% t3 g2 ^/ o        hasRefAttr = FALSE;
9 k: M! y4 i& ]' c# Q0 e8 c( _4 F1 `7 j
    hasRefAttr = cmpnt.HasUserAttribute(RO, NXObject::AttributeTypeAny, -1);
6 D8 O$ K/ \, f- v5 ]8 D; ^5 G& q4 a2 ?5 l: y8 w
    if(hasRefAttr == TRUE)
' L3 t: I# I( G( u    {
! D- H/ d& h0 V& t% {  B        return TRUE;
+ s2 w& I$ K. a! O7 t    }
4 m6 h# r5 t$ o+ e3 g& d  J% w: v, C3 p; S  W
    return FALSE;2 H1 u( E/ }6 @; c

/ ^( t7 d- d2 Q7 W}+ Y3 {6 p% e# i

: A* b( s$ w! h* Z* c8 u* vstatic tag_t ask_next_of_type(tag_t part, int type, tag_t object)
2 \" z& o) I: k; D{
7 `- J& Q) J4 y    UF_CALL(UF_OBJ_cycle_objs_in_part(part, type, &object));; U" c7 V$ I' e$ [  h8 l" m
    return (object);
; V- s- }+ u: m  v}0 z4 _: O/ v$ }3 p

, U1 C9 @- K  i. {static void do_it(void)% I7 V' C# `# A8 s- Q
{% w1 k  V4 q" R. R; l" Z% i$ X
    // Assumes that the display part is the top of the assembly
2 J( D! E  Q0 g6 `, I
: x' T" w' _* J+ _6 E    tag_t' F1 m" Y0 \3 w- b' ?
        dispPart = UF_PART_ask_display_part();
( t' s; I" }$ U* @. l9 h: G/ I& L2 Y2 [6 g1 {* o  E
    if(NULL_TAG == dispPart)
9 D( P5 U4 g7 Q; }' ^: I8 m    {
; D2 Z& c+ R8 c& ]' l. b        ECHO("Program requires an active displayed part");1 p" {0 f7 J' E" r: u( Z- T" B5 G
        return;+ o% ?  i8 H" H9 s
    }8 M/ o) u  @5 N" @8 C! S, x1 S
  |% k  u+ {: e* ~& s
    tag_t' I5 G9 m& `8 m
        compTag = NULL_TAG;) d  h& Y5 k$ d! b
" ^. e6 e* }% g, L( w
    while((compTag = ask_next_of_type(dispPart, UF_component_type, compTag)) != NULL_TAG)' V. @' c7 w" m
    {
: T5 ?6 @& \4 ?: b        char. P( t3 C8 O2 ?; |  @( d9 E( a
            msg[512] = {""},
- T$ t: `5 e. L            fSpec[256] = {""};
0 V# o) l* w4 X0 b6 _# _+ T9 u1 t2 n1 `9 T$ p# `; u- [
            tag_t+ I, E  y. X# |" `2 U
                protoPart = UF_ASSEM_ask_prototype_of_occ(compTag);8 {6 s- T0 h% u) K# W$ M( n. _: }- ?4 X
: \/ O' b" a/ c
            UF_CALL(UF_PART_ask_part_name(protoPart, fSpec));1 _; I6 ?  s/ j" m7 O+ }. \
$ D, n5 `' h# a: }+ b
            // uncomment to see all component names:
& s+ K' F+ |$ S/ O            //sprintf(msg, "Component Part: %s\n", fSpec);: l; B) O0 l9 h7 x; ^/ r: L6 d0 d
            //ECHO(msg);
+ X! n. O, @6 z! e* }+ Y# z3 V5 g' G8 U/ f7 m4 F# B5 ~, {
            Component *theComponent = (Component *)NXObjectManager::Get(compTag);4 l: x$ A3 R: V
            if (attribute_exists(*theComponent, RO))
7 e6 z( e/ |: K! s6 t" v+ P; o            {& C  }+ O3 k% b) a! K- Z: V* b
                sprintf(msg, "**** Reference-Only Component: %s\n", fSpec);7 h. g2 W+ D5 }/ P$ n3 f% C
                ECHO(msg);
, V1 {4 B, b2 g! X8 E7 Z            }
. \* _6 H) X! \. q6 z1 F    }
4 O. @! o% J& c$ N* J}[/mw_shl_code]
6 z  i1 o/ X+ @# j2 {# j9 Z+ W
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了