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

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

[复制链接]

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

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

admin 楼主

2018-1-10 17:48:41

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

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

x
8 G7 e0 c; F1 f" a# c: H

4 E# P' s% }" l% j: NNX二次开发源码分享: 获取当前Reference Component的通用方法2 ]2 Z# M: o* ^
( d. A7 i( h# K' F' Q1 G# d" M2 J
3 x0 ]5 `" u/ ^$ @
3 {  e" I2 z/ X" {4 ]
) W- q4 s  F8 F  S- a
! {, W: s4 D6 _$ W9 Y3 [
[mw_shl_code=c,true]static logical attribute_exists(Component cmpnt, char *title)1 V6 x" F: S6 C4 }
{
' `' S1 c' o/ ?( E% F, c9 l5 [* D
, j" q) h- C; M/ K//  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.$ y1 J3 l9 e- B( o
    . n4 y1 T4 Q3 N5 j  Q
    logical
! r" A/ R% W9 u7 K0 {' I/ v        hasRefAttr = FALSE;: ~% a* @* a7 [& U7 V/ q8 C2 [
1 O( O0 z+ c# b" R1 k# ~. a3 O: H: V$ v
    hasRefAttr = cmpnt.HasUserAttribute(RO, NXObject::AttributeTypeAny, -1);
  J( s7 V! G3 B4 D9 b5 g5 P8 {+ J, P/ Q* ?1 e
    if(hasRefAttr == TRUE)
9 f2 ?. G8 A( s# t( T  k4 W! Y2 Z    {& l% _5 G$ W& ]/ x! P
        return TRUE;
2 A, O, i; {' N, {  p7 K7 h9 l    }
" f% [& @+ N7 C+ ?* K$ d* V
& a/ d) w0 ?& y4 g  b    return FALSE;: U! y! l" N1 f# T. W3 K

7 r. ?8 q3 W$ G4 t, t3 d}( r: K* C2 V: P1 N8 |4 O2 A; O

3 p5 ~/ Z( b& |3 _3 L. Gstatic tag_t ask_next_of_type(tag_t part, int type, tag_t object)2 Q$ w: w& k2 N( ~; b. y  r
{9 o8 K; Y; m; i; }1 E
    UF_CALL(UF_OBJ_cycle_objs_in_part(part, type, &object));3 V% `! J7 v$ j+ `
    return (object);
8 }% x$ h+ G! u6 ]}
) H1 v: x5 [( u6 {7 N" K+ ?0 V. _1 |
static void do_it(void)
4 t' x# G( [4 y5 I. A" X- }{3 Y& i7 E# w  c+ G5 _8 w1 Z5 ~
    // Assumes that the display part is the top of the assembly2 l4 o# j0 B: S) g0 r

: g5 m, q% n. J( N+ h1 G; O    tag_t* O: l: U1 D6 p/ L
        dispPart = UF_PART_ask_display_part();
5 H  }& H% r8 F: ?/ E: p5 [* X4 a* X
    if(NULL_TAG == dispPart) ; }2 Z* N! P. d* X+ B$ Y- g
    {
4 ]% L: Y4 W% X3 F- l, ?# T$ ~, C        ECHO("Program requires an active displayed part");7 f8 X# O' s5 |. U" s4 |
        return;. ~/ d8 D: k* }: \
    }  ]$ {- ]  {, L, S/ E  [$ s( |, \
5 _) i& s. Y* z% ~+ |' W
    tag_t
; Q0 b5 E7 w9 q- d% ^5 m* J        compTag = NULL_TAG;
) |& h; r% ^) @7 A- X  t: {, V
' D1 b6 b8 _3 X! ^- K; j    while((compTag = ask_next_of_type(dispPart, UF_component_type, compTag)) != NULL_TAG)
  W. L* b5 }9 Q$ u    {
4 v$ G+ I0 D* N) P, F0 [0 i# n        char
5 R% K. d' O/ h, ~) s$ H& F! v, N            msg[512] = {""},) U0 f/ q7 ^: ~) C3 ^" a! q+ W' S
            fSpec[256] = {""};
/ ^8 U# Y3 N. Z: P6 O( T7 F4 }% M1 }$ [/ q; G+ x9 v
            tag_t0 I5 ?9 X' S( \% A
                protoPart = UF_ASSEM_ask_prototype_of_occ(compTag);
% B7 W4 U1 w  X$ n: H# _9 j6 K" p7 z$ i' G8 Y! R0 B$ n
            UF_CALL(UF_PART_ask_part_name(protoPart, fSpec));. _$ z4 I5 W" ~  X

: r% g, g% C, g+ Q  s; g            // uncomment to see all component names:3 p. h" t8 W4 c
            //sprintf(msg, "Component Part: %s\n", fSpec);8 s' V3 S4 ~( \% |" L
            //ECHO(msg);
: C' {$ P( c4 O- _) \$ s+ \$ F2 |, e/ Z" {, G9 d. U' F
            Component *theComponent = (Component *)NXObjectManager::Get(compTag);3 M" h, k# T) d
            if (attribute_exists(*theComponent, RO))
" O) W, k( s  B# }9 t6 e            {
: P8 j+ T6 ^$ p) U6 `                sprintf(msg, "**** Reference-Only Component: %s\n", fSpec);
7 c; u: n+ ]. P+ L                ECHO(msg);! k( d* p: J  s4 D" c; @; @: E# m
            }. f# h+ w2 T, I" {& l
    }( ^7 H7 z/ ^0 M& J0 Q3 w6 i
}[/mw_shl_code]
9 h+ ~( G( i6 B8 z1 F
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了