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

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

[复制链接]

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

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

admin 楼主

2018-1-10 17:48:41

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

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

x

. J7 W# e1 J& J# L9 C' \
8 H& o6 }/ j$ d( B* P- j$ SNX二次开发源码分享: 获取当前Reference Component的通用方法
" U+ W) H' b& K0 N3 C  Y0 k8 g( `2 M; \8 R1 ~2 V
$ B3 l/ k% `( p8 F" @* s3 ^
5 Q! {8 B$ L% c1 M8 q' ^. a) w
/ |1 |& N; S$ L" c! U

0 r9 D1 o* F& L, Z( z6 P- F[mw_shl_code=c,true]static logical attribute_exists(Component cmpnt, char *title)
- B) i$ w* R( i9 j+ t8 k{
. C5 s' a2 |  x1 v6 |! u* S* D9 q0 w; n
//  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.
+ ?( S- L7 a9 r% i# @1 m7 s/ g   
7 x' V9 j) w5 J" P7 a9 i    logical
6 u/ j5 f' I7 J" p        hasRefAttr = FALSE;7 M+ P5 i! _  t+ ~& d

0 B) K/ N7 E" v    hasRefAttr = cmpnt.HasUserAttribute(RO, NXObject::AttributeTypeAny, -1);2 o7 s$ Q3 K. s" [0 d" X  G9 m
5 @$ c, X; W3 |& ~8 c
    if(hasRefAttr == TRUE)
# g, B: Q& o3 \5 y6 a$ Z/ |    {( r# L: X* z( E; L
        return TRUE;
0 {5 v/ r. j& l    }
$ B" g% o5 l0 G' W4 A1 E
* G1 X* ^' R- |6 R& Y    return FALSE;: f9 T0 u8 B- U; ?
) e% `4 ]% i& ]) v  x" U5 y9 r
}
" Y; V! b& p' m% B2 ^# a. C
, E# G3 v4 [" o4 y( S# W4 e. b, }static tag_t ask_next_of_type(tag_t part, int type, tag_t object)
* O/ p0 w- _. ~( m8 L{1 D4 Y( H' V8 e5 i$ M
    UF_CALL(UF_OBJ_cycle_objs_in_part(part, type, &object));, ?6 O" _& v+ `- _! B
    return (object);
+ v5 u* [" k4 w6 _$ k9 e4 K! R}5 p* T2 Z0 A" H! ]/ }6 c- G+ r5 i

& }3 W/ y0 }5 I9 V1 Mstatic void do_it(void)3 B1 f& i4 S8 t2 b6 ?0 j7 N
{
4 a/ _& w2 M8 v7 W5 d$ S    // Assumes that the display part is the top of the assembly
( [$ _0 x& y6 {9 m( G  C! i1 \( T# e6 ~* Z
    tag_t
6 p8 i3 s3 R% k* k! Z9 y        dispPart = UF_PART_ask_display_part();- r2 \8 Y! K5 \. k) z: S- Q
' K0 a5 G2 d2 V9 f
    if(NULL_TAG == dispPart)
+ m( ?+ ^. J1 x" v! q1 @* C, a( q! E  W    {) K, Z5 P6 G! j5 w* z. f3 B9 U
        ECHO("Program requires an active displayed part");
  f) x. r& O. o9 x/ }8 z, ^: g        return;
# H- }/ Q7 Y! \" j+ |3 F    }
  d4 d; d$ q8 w( M2 e( x. w( h# J6 n! Q) t/ \2 j4 z
    tag_t
5 O6 [0 x( A* S+ e2 \* {  o4 V        compTag = NULL_TAG;
8 r; \) p9 ^& {3 X) U
1 }1 b7 L. r7 i: X/ D6 A    while((compTag = ask_next_of_type(dispPart, UF_component_type, compTag)) != NULL_TAG)
+ c$ d) O+ a6 N    {2 g7 k5 Q8 b; D6 e
        char+ V& S6 i& J# ^. m+ N7 `
            msg[512] = {""},
& t7 ]" H' q( C- l7 ^            fSpec[256] = {""};
: _. ~# E. i4 F) [1 g7 ^0 @3 M9 ?1 b. `3 l/ N1 X2 G
            tag_t6 Y/ }; \. e! k) x( o
                protoPart = UF_ASSEM_ask_prototype_of_occ(compTag);
7 C$ f" p; }4 [8 G
1 n& [. E. D/ g$ S3 z' A0 w            UF_CALL(UF_PART_ask_part_name(protoPart, fSpec));  i1 O& J3 \* E4 Y5 n- v
# I- o' ^4 p4 E
            // uncomment to see all component names:
5 e+ h# q4 S- Z. N* A. G            //sprintf(msg, "Component Part: %s\n", fSpec);
2 v) H2 `& e0 t! n            //ECHO(msg);
' A6 C4 C2 v0 b; G" F3 U
8 W* @. d( z0 h0 W$ ^5 A, T8 `            Component *theComponent = (Component *)NXObjectManager::Get(compTag);
, C* w0 U" q& p9 ?. U+ J            if (attribute_exists(*theComponent, RO))
* r& Y) Z# [4 G, m3 V' o& [            {
7 f4 L( R$ J5 f$ W( D! `3 v: L                sprintf(msg, "**** Reference-Only Component: %s\n", fSpec);
0 n3 }) [( j$ b! ?( ~( W                ECHO(msg);5 k" U1 N# V; i( z0 h4 A
            }: E, r5 \/ Q1 L9 {* Z: `/ H
    }9 \+ K! E0 y: Q: @8 X4 i4 R
}[/mw_shl_code]
  I+ l" h  }' q; E4 g
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了