PLM之家精品课程培训,联系电话:18301858168 QQ: 939801026

  • NX二次开培训

    NX二次开培训

    适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术对于老鸟也值得借鉴!.

    NX CAM二次开发培训报名 NX二次开发基础培训报名
  • PLM之家Catia CAA二次开发培训

    Catia二次开发培训

    Catia二次开发的市场大,这方面开发人才少,难度大。所以只要你掌握了开发,那么潜力巨大,随着时间的积累,你必将有所用武之地!

  • PLM之Teamcenter最佳学习方案

    Teamcenter培训

    用户应用基础培训,管理员基础培训,管理员高级培训,二次开发培训应有尽有,只要你感兴趣肯学习,专业多年经验大师级打造!

  • PLM之Tecnomatix制造领域培训

    Tecnomatix培训

    想了解制造领域数字化吗?想了解工厂,生产线设计吗?数字化双胞胎,工业4.0吗?我们的课程虚位以待!

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

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

[复制链接]

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

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

admin 楼主

2018-1-10 17:48:41

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

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

x

" Y/ g  J4 H; F1 S
9 K+ J7 }) p0 ]1 w9 c0 Z  lNX二次开发源码分享: 获取当前Reference Component的通用方法% f: p( a4 l: h9 K; z. M# j9 X

4 u% X+ C  Y2 J, Z, m/ L4 @4 n
# r+ n& a2 c+ `. B) h- Z$ w& b  d$ K$ a( f& ~% `% o4 r/ [+ s, A3 `: _

4 ~7 H+ C% ?! f
3 Y; c1 q. R0 M' E. M, s9 t0 O[mw_shl_code=c,true]static logical attribute_exists(Component cmpnt, char *title)+ M- |# Z! L3 f/ P
{; o  b) m$ l) F( `( ~
; Z- U1 K8 l$ i7 ~5 x1 f' \
//  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.
, L5 o# T4 s( h/ j* i$ `8 m    6 \# {5 A: p: e% k+ T" R7 y
    logical
3 F1 s# o/ V8 @0 m; D        hasRefAttr = FALSE;
* o% m6 Z+ ]1 ?" P/ b0 u
& D8 @0 \; y0 B' v; D: e    hasRefAttr = cmpnt.HasUserAttribute(RO, NXObject::AttributeTypeAny, -1);
) j( d% R8 |( F7 T: J0 I4 h# W, @7 p8 \& ^8 d
    if(hasRefAttr == TRUE)
2 o. E8 ?+ Z- b( ^    {
: q6 C# I' r) `# V        return TRUE;
+ m( I( M( y) E$ [# m1 h) S. W    }
# X; @# K2 v/ Y$ N3 K( l$ C* L( i! ~$ e7 h4 e. ~) I' R
    return FALSE;% z9 O4 N% h! ?+ j

) v; w) |! z3 K* P0 }9 u7 m( U9 b}
( H. B5 K9 _1 N: `; O. U
' D6 Z9 e1 {- S' e4 Ostatic tag_t ask_next_of_type(tag_t part, int type, tag_t object); }2 P. ?. I9 e3 B
{7 v7 r9 `0 f9 k- {3 m( @
    UF_CALL(UF_OBJ_cycle_objs_in_part(part, type, &object));, @- ^7 K  m9 M# g9 f" b7 Z$ U8 _
    return (object);5 ^9 u( ?( t9 R1 Q
}1 j" T- P8 H8 Q' O4 Y# r0 Q
( S, H9 j+ q' \. A/ z% B
static void do_it(void)
0 h  D, K7 K, F+ a; i{) |2 l% \5 c& r6 d% q$ @
    // Assumes that the display part is the top of the assembly
8 U  Z% h, [: ^1 }" ]  c( Y
6 R' L! q, ]8 ]0 y    tag_t4 k1 c0 `- T! ?! u5 G8 h  ^
        dispPart = UF_PART_ask_display_part();; O# {5 l  g0 |) ?% q
+ c+ k( C+ z, H3 w- S
    if(NULL_TAG == dispPart)
2 C, c3 K7 K7 F, {( t    {
; y+ d& t& ]4 z; N6 ?        ECHO("Program requires an active displayed part");
) T$ \9 P" s6 d1 K        return;
0 S% `4 m2 u- K" n  D    }
: o% y% d9 C0 Z9 m# `7 h" w% w$ D) ^2 P) A# q8 l, {6 P  y
    tag_t0 k- T6 W5 ?5 s! y8 L: Y! u3 |
        compTag = NULL_TAG;
+ E5 _# J2 A( h  @9 k- p' U/ K" c3 J2 o9 y% m9 u
    while((compTag = ask_next_of_type(dispPart, UF_component_type, compTag)) != NULL_TAG)
0 l5 A- U9 V+ }6 Y    {$ P% j( e" c: K! q5 w( B
        char
5 F7 V5 S$ b; ^# m            msg[512] = {""},* L+ ^1 G7 G1 M
            fSpec[256] = {""};
# I* C, \- {5 m4 K0 f/ E/ ~) k6 S/ _4 Q
            tag_t
* }# }9 i) f3 o% u                protoPart = UF_ASSEM_ask_prototype_of_occ(compTag);- d' I/ W& [4 o/ C, G. Q. m+ E

5 b6 v$ H. j  x7 ^6 n! x            UF_CALL(UF_PART_ask_part_name(protoPart, fSpec));
* C( e' r1 v, O( \( z- c5 b6 g% [9 o8 p& v
            // uncomment to see all component names:
+ f+ M; V' K; B0 G# Z            //sprintf(msg, "Component Part: %s\n", fSpec);
$ s' x5 W1 U2 g1 n; X& u            //ECHO(msg);
9 d6 ?$ t- L$ T9 v- S/ Q
: x0 g/ ^8 |: d4 `5 ~0 V" k$ U            Component *theComponent = (Component *)NXObjectManager::Get(compTag);' l- l2 h5 j% m% A
            if (attribute_exists(*theComponent, RO))
( f, t. B. W2 ~! }$ i            {
: m  b! n. ^: n3 O& q* n                sprintf(msg, "**** Reference-Only Component: %s\n", fSpec);1 |" w6 T2 w2 |8 t1 F4 D
                ECHO(msg);
& N: A0 l0 N" e$ ^' Q& w% B- F            }
" Z6 D# x3 `) O7 J    }
$ @- g! }( u: {4 e}[/mw_shl_code]
7 \3 Y% {+ H0 w, x  F9 I
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了