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

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

[复制链接]

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

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

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

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

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

x

  j) T+ b& q; [1 `( h
: \* t7 N1 R6 y+ pNX二次开发源码分享: 获取当前Reference Component的通用方法
- }: t- J% [! Q9 {) L0 I  B' ]& b) M, `) f

( I; j) L3 J& d) J( k4 D
4 G1 D! ^9 \! |$ z+ ~' r0 Z. i$ S
' t8 d0 k2 [- V% H4 s% X+ i- K- E0 @3 t* E% N( l
[mw_shl_code=c,true]static logical attribute_exists(Component cmpnt, char *title)
  }, e" ?1 M& r5 x+ O4 p1 @{& s5 _3 x+ P+ ~

; j3 x( G; |. w. X) ]. @//  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.
( N  s! T' O) Y) O5 A    4 ?; w" y- `6 G  g! R5 \# V
    logical
& _% c6 J+ w6 ~7 }* @5 e* s        hasRefAttr = FALSE;
' M8 k9 C' H( M5 l! J' W: }7 C
3 i: Y3 ?& i. `3 m- q7 }    hasRefAttr = cmpnt.HasUserAttribute(RO, NXObject::AttributeTypeAny, -1);# S& u8 w: Y2 t6 s0 w7 W! U+ N

& z6 P8 ~0 M7 ?% Y1 p5 ]    if(hasRefAttr == TRUE)2 ]. P& n7 w9 ]1 D
    {& q5 r& t9 G+ ]6 {; ~
        return TRUE;
$ M- q4 U& \; @1 n    }6 s) d( d1 S! i( O2 ]7 G

2 j% G- |4 S% o: h' H% P0 Y    return FALSE;! F# ]( }  p% [$ U4 V+ t

! a$ h" m0 ]4 @: ~3 f5 w}
$ \$ x) C& Q3 [% l. a9 _- A6 r& v4 ~
static tag_t ask_next_of_type(tag_t part, int type, tag_t object)
1 @. _$ M& ^9 v" v; @* n: W& K{
" }, A4 c3 H# C    UF_CALL(UF_OBJ_cycle_objs_in_part(part, type, &object));
1 U( E, l7 Q, c9 E    return (object);
1 _9 s% m9 B( o. F) b) g& z, C}7 T$ T! ?7 S3 f* |2 W8 N6 N: Q

! t- g% b! w8 r% M" Nstatic void do_it(void)5 _: L1 e% A/ j# d: ]& J) b
{- O8 g1 i( v0 Y( l. s3 f" k
    // Assumes that the display part is the top of the assembly  j* L0 d" a% H. \% Q

; ]' Q; B  P8 j2 J! v; E    tag_t; F+ [$ E- ]2 s! t' E- {
        dispPart = UF_PART_ask_display_part();; i0 T# Q  {/ ~! _# T. X" s

8 H; p$ c1 W# V6 W  Y& R    if(NULL_TAG == dispPart)
  n( h, ^0 D+ U    {
' j& [: U# u5 u  Z" M4 T        ECHO("Program requires an active displayed part");8 F$ A( N3 H0 P
        return;
. C# V" T8 l- y! k! ~- i    }
  r; }$ r' S& x6 L0 Z3 p. f( @$ P6 p  I
    tag_t5 \6 a4 f1 s' Q* V8 x
        compTag = NULL_TAG;
7 P) R* P- n- v) X5 E7 g. U6 r5 @! G, ~4 r% Y, A# r; E/ F: U$ C
    while((compTag = ask_next_of_type(dispPart, UF_component_type, compTag)) != NULL_TAG)2 R5 ]1 r$ a7 r' }) m2 \$ z5 r# ^
    {$ B3 y' d( b) B5 d- B+ ]
        char2 O7 K. [) {" F; _
            msg[512] = {""},) m6 c0 h) b7 E' E/ }7 b) A% d* W8 X
            fSpec[256] = {""};
" e5 x# I4 B, W9 C* u% H
! h7 o5 }3 x9 M) h& j1 D            tag_t
6 t% o3 @1 O  Z( J* J/ ?( c                protoPart = UF_ASSEM_ask_prototype_of_occ(compTag);
! N4 z+ W6 }# _; Q
" s& e; |5 C+ X. m8 ^- X            UF_CALL(UF_PART_ask_part_name(protoPart, fSpec));8 S8 G8 T  ~1 K3 z8 m9 m8 V/ y

9 x! a6 q+ j6 O) X1 K            // uncomment to see all component names:+ `/ u) N! b+ ?3 y4 D1 B* [
            //sprintf(msg, "Component Part: %s\n", fSpec);
0 {: p3 e9 I1 R; F/ h. ]0 N4 {            //ECHO(msg);, x0 K0 E: m0 `0 F5 L. s) o
9 G+ I5 j6 E' E* g
            Component *theComponent = (Component *)NXObjectManager::Get(compTag);' ~4 d5 u) U0 @' }: y1 Z' f6 b
            if (attribute_exists(*theComponent, RO))9 s7 }9 C6 C3 p: x3 B
            {
3 \1 Z) n, G1 i0 ?                sprintf(msg, "**** Reference-Only Component: %s\n", fSpec);% |3 X( e) r% B( U2 G
                ECHO(msg);
/ |2 t3 W2 y* u* _* _. H) K  ]: h0 R            }+ V  X8 ?. r* s: r
    }
+ @% h" R, u1 A}[/mw_shl_code]
  i  j6 I& S; ]  y5 ~, M3 B( |' V
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了