PLM之家PLMHome-工业软件与AI结合践行者

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

[复制链接]

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

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

admin 楼主

2018-1-10 17:48:41

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

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

x
. I+ q6 z" ~/ J8 H4 _
% K# B! g" V- s$ Y; R
NX二次开发源码分享: 获取当前Reference Component的通用方法
4 w9 }/ ~2 [$ S* K6 R# Y( F; g5 N) ]6 i1 I3 z  S; h

4 Y( `6 L' l9 M
* [, L- i, _  L5 m- i6 f% ]+ x4 t" ?

( j* \0 ~6 [2 `: G3 P/ Z6 ]! A2 m/ q[mw_shl_code=c,true]static logical attribute_exists(Component cmpnt, char *title)
- @$ D# J4 K+ o+ B' O2 ^: _{
5 i" w! B; }5 m, Y! x3 Q* m) d) S* _9 J  O% D/ j, Y
//  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.: f0 g& T/ B1 u- H
    - ^- L# }% X' D7 x
    logical. q/ x. f& J/ W5 n7 ?. a
        hasRefAttr = FALSE;: m4 _; f  m8 H' e: H* x- J
9 a. h# Y. ~3 K
    hasRefAttr = cmpnt.HasUserAttribute(RO, NXObject::AttributeTypeAny, -1);, M& l* x9 [0 b: ]$ F% V

! x3 a( Z4 G4 d# P5 m    if(hasRefAttr == TRUE)  }0 G$ e) G* C
    {
$ C0 a5 b, }$ r. M        return TRUE;  _2 @4 b3 J& f" C& ?% u: @, D& @
    }$ x8 n1 r# s" w. A1 Y6 C

8 Q) T% e  v3 A9 W$ C8 }2 d    return FALSE;
3 [" M2 Y  K4 V. }' V' G- r1 _9 ~: H0 w  M# g. E& O
}8 E5 O8 s" a0 \: N. Z4 m5 i
& `1 W. f4 J6 j2 E2 T2 Y: q& q
static tag_t ask_next_of_type(tag_t part, int type, tag_t object)/ J% l5 }2 v" M" s' I: K% A+ J
{3 B2 N9 T2 V! x0 f$ ~
    UF_CALL(UF_OBJ_cycle_objs_in_part(part, type, &object));  A: J- n2 E9 \$ j& d" Z# e6 g
    return (object);7 _7 h8 ?' I5 x0 X
}3 I, g6 N1 y) g- C
1 d9 d& Y4 x$ z, p% s
static void do_it(void)
; z3 _" n# k! ?2 f! {{) s* j% f6 r& z3 ?5 u( f; T. |
    // Assumes that the display part is the top of the assembly
' c& ]2 Q0 ~/ o2 H% Y; J
9 P# h. P0 u+ R1 w6 ~8 s0 [    tag_t
, |" ^/ m3 T; {, Y  n* V; _4 A0 g        dispPart = UF_PART_ask_display_part();
9 W: x) a* a3 p, ~' n! u& Q5 h2 ?1 j6 U0 G* a  Q4 D2 W
    if(NULL_TAG == dispPart)
* K6 K/ T+ Y1 c2 t0 m0 c8 N. o* T    {
5 C% E, Q! a1 j( y+ k) ?! X7 L        ECHO("Program requires an active displayed part");- `8 j9 U- I  h- P. `  W
        return;
2 M# E  A; |5 ?9 _$ I$ @( Z    }/ e9 o) m; `1 s) N7 p7 d# R" J0 g

# e& [' u9 a4 l  E; L. S! {1 |; |    tag_t
3 Q- u, M. d9 t0 T- k9 D- H3 T        compTag = NULL_TAG;: s4 O. `- C! G8 [8 |5 A5 q
" d. y4 K# z  ]+ L$ @
    while((compTag = ask_next_of_type(dispPart, UF_component_type, compTag)) != NULL_TAG)4 G& P( M0 |2 X
    {
; s% S4 g' c& f        char
9 u* ]; b+ N. V. A2 x            msg[512] = {""},$ P; p6 D" ]6 D4 W* i
            fSpec[256] = {""};
& ^% [0 x/ n8 b& X
- i9 q% s+ G9 _- p            tag_t
, ]5 X9 L+ R% h# x; R: @2 }                protoPart = UF_ASSEM_ask_prototype_of_occ(compTag);) q  _5 d4 z3 }4 o) Y! N2 T* v1 a
8 U1 K5 G/ B* f3 |
            UF_CALL(UF_PART_ask_part_name(protoPart, fSpec));% P" s- T8 X2 Q

3 Z4 O4 U4 e4 u3 f' _+ R            // uncomment to see all component names:
* I+ J/ F. b7 O/ a) u) u4 [            //sprintf(msg, "Component Part: %s\n", fSpec);" O5 Q! T, L, r# _1 y
            //ECHO(msg);
  ?- K. `  I7 B1 \" T1 h" |
7 ^% M5 K* d  ~, G# q            Component *theComponent = (Component *)NXObjectManager::Get(compTag);0 ~1 r/ G# Z& h+ A) m7 @
            if (attribute_exists(*theComponent, RO))
' `# r% v& `0 F0 J8 W) v            {
, u$ |- K7 f$ x/ ]                sprintf(msg, "**** Reference-Only Component: %s\n", fSpec);$ c$ g' u( s& {& `# J
                ECHO(msg);
% a' P3 I4 U3 Y6 q2 V            }
* C' c+ a3 X8 h* o, X4 f1 E    }
. C2 h8 q3 j# W4 M; _  O+ `}[/mw_shl_code]$ C  x# Y, M! L- i. ^: z
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了