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

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

[复制链接]

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

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

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

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

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

x

2 Q% a* P# ]1 F4 @
2 X+ a; c7 p% g  z4 ?NX二次开发源码分享: 获取当前Reference Component的通用方法! `4 N- L8 {1 p% Q5 J+ Q

* U0 J" l: ^2 y+ g5 [2 `, o' z2 u; d& a& X

- W6 ?0 t& U2 W2 e0 \- h5 p  {+ h7 a
; }* [6 ^; |! C  _( d4 Y9 w  N" B- a' |# O, \! Y
[mw_shl_code=c,true]static logical attribute_exists(Component cmpnt, char *title)  X# j" v* A0 D, ~" z1 o2 G# I
{9 V+ b5 ^& R6 a# E) A9 g
% a* X6 d  h- @& }
//  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./ p6 b  @; I- L2 o- s1 [% A
   
" A, \8 \( w7 e5 m/ x. d( H. R+ Q    logical
' b: w$ l4 E; B  H# c" i2 K        hasRefAttr = FALSE;5 t" n1 L' ~' i7 h6 W9 U
. L; s3 F( f, I& c1 p
    hasRefAttr = cmpnt.HasUserAttribute(RO, NXObject::AttributeTypeAny, -1);
0 `  Q+ _/ q: ~$ \0 [  Z5 O
# g# x" V! g" p  V; ]& p: m( D* y    if(hasRefAttr == TRUE)
, m1 K) L; Z) a; d% M# ]    {
/ u& L4 f6 ^" h  v9 A        return TRUE;
$ J( L6 g8 @" e' h- ^; ]. b    }  t) H1 q, a' ]! X7 a% x

- n  X0 f+ j: k/ K2 c+ k- i    return FALSE;
+ d" o% @+ R3 [8 x. L
" a, o- X, J# |' ?5 z% ~! P( a* v}
" O/ P3 a) y4 o) Z* P) q. @4 w- i! T% U+ A
static tag_t ask_next_of_type(tag_t part, int type, tag_t object)
6 f; \4 R/ p2 w# i; J- `{
  E& j( Q# f1 }3 _* Z7 f% o    UF_CALL(UF_OBJ_cycle_objs_in_part(part, type, &object));2 B' G: `& X$ y% p3 D5 l8 y1 ?
    return (object);3 h3 O; W& Y; f( V
}5 M! \' l* P% b) g. {
; l+ \7 `: ]/ A
static void do_it(void)
# w1 [% b, B8 u0 Y2 Z2 r6 @5 Q{5 [4 J! k2 {- z  F
    // Assumes that the display part is the top of the assembly* W$ p2 T( k2 N( i! ]# q9 D4 I: g

& _" y- n! c1 S: F    tag_t- G( Z" f% d, f- [5 t
        dispPart = UF_PART_ask_display_part();
. {" e0 J0 J$ C6 _+ D6 N7 L; G+ W8 [
    if(NULL_TAG == dispPart)
. g3 B- ~, u5 K9 n    {
, z  M+ Y) ]/ C/ R# p! a        ECHO("Program requires an active displayed part");
/ i7 f& @0 y' o! |        return;
5 [: R" M$ h) n( z' e! l    }, x9 ?1 d2 L' X7 J, h7 M

7 Y; S' r* t- r8 x    tag_t
; n, H: K: o6 m: [. ~' S7 D+ F. b        compTag = NULL_TAG;1 t) H4 R. w; v) n. u
0 \" ~! U# ^) P  q
    while((compTag = ask_next_of_type(dispPart, UF_component_type, compTag)) != NULL_TAG)
2 p) w, O8 F  `% p6 x: _# m, W  R    {# b+ a) F( l9 r% \
        char0 k0 U, F7 Q( d1 n  K2 u$ X7 W
            msg[512] = {""}," e, t5 i  n1 d8 Y
            fSpec[256] = {""};: H+ _6 f7 v' j( m) g2 J

; g, E5 z( ~. e            tag_t: b2 {8 P" w9 j- B
                protoPart = UF_ASSEM_ask_prototype_of_occ(compTag);
7 H0 F2 I/ i1 f0 P* ]% E7 [+ _5 ^  P% S5 v, J8 @3 t2 ]; B
            UF_CALL(UF_PART_ask_part_name(protoPart, fSpec));/ x6 u# ]$ z, H! N8 M% k
3 y8 k& Z3 N3 B  Y4 h( @
            // uncomment to see all component names:
2 v; d9 |' X; Q. C) F            //sprintf(msg, "Component Part: %s\n", fSpec);
) O9 A: q! A' [" k            //ECHO(msg);8 A* w( G/ h: J' q# t& L
: [: m3 L3 @9 O8 t1 s
            Component *theComponent = (Component *)NXObjectManager::Get(compTag);
+ R# L: T$ B0 l            if (attribute_exists(*theComponent, RO)): y3 P0 o. X+ W4 l' m  w7 e
            {. m  e: v( o. ]) z
                sprintf(msg, "**** Reference-Only Component: %s\n", fSpec);! o% ~  |4 ^* R/ i7 e' G( i
                ECHO(msg);2 _. a2 ~5 f. j2 Q
            }
, ]: T- w  n" w/ e% x    }
4 \: H! ]3 g8 [) y- n}[/mw_shl_code]& [1 A& I: P7 w7 f2 C* i
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了