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

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

[复制链接]

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

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

admin 楼主

2018-1-10 17:48:41

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

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

x

* j5 A. R# |6 l% A* c
7 n$ k! m$ M' H* a% ^NX二次开发源码分享: 获取当前Reference Component的通用方法
2 N, w4 f  B# z; ^$ K4 i$ o7 l& c$ c- T: r5 M6 r  c
2 x0 D1 t1 x; W7 U6 G' k

8 v: F* Z' s( F" V. Y2 k4 ^9 q! {
( `0 i' m2 h" F. E4 g' k. c# w1 t! n! C: s0 Y+ w
[mw_shl_code=c,true]static logical attribute_exists(Component cmpnt, char *title): \, J1 K& Q/ g) P) M& L1 X
{
. D& y1 n8 A3 D- M8 w7 R" B: {  E7 G
//  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.& p$ d. p5 S( e3 x9 Y  X& W8 V0 Q$ q
   
3 ^/ A4 f# U+ x& k( R5 h    logical
) X2 C& s6 q9 p9 q# W, c" \2 Z/ o* K: k        hasRefAttr = FALSE;- p( ~0 [) q+ o1 H- ]
0 ^2 ?& l7 F$ {7 W
    hasRefAttr = cmpnt.HasUserAttribute(RO, NXObject::AttributeTypeAny, -1);+ n6 i$ U% ?5 b2 ~0 u5 L3 |' O
* o1 W# j3 s! z- \% d3 Q3 m
    if(hasRefAttr == TRUE)
, T# j( k# s! u# l( M! ^+ S    {% N% ~4 g# m( ^/ w
        return TRUE;
; L0 _5 T0 v) z' G$ n  v+ ?    }2 S6 N; ]- T& N
6 d0 m/ Y9 {) a/ p# q3 b. Y
    return FALSE;" J: }% C$ c. |: \
& P1 o& ]' v: _
}" E! g3 z6 S' g! h$ O' O- ]

: w7 E3 m! F/ Z* \0 L6 E* @static tag_t ask_next_of_type(tag_t part, int type, tag_t object)5 v" m: @8 |" A7 l: d
{: \& ?8 Z. U4 ~6 e
    UF_CALL(UF_OBJ_cycle_objs_in_part(part, type, &object));
7 m1 G/ d: w) M) A0 f5 g5 u% k    return (object);) \8 y3 v$ b/ {' }  Z! S2 t
}6 a) \! z: M, Q# L5 F( L' k

! j1 M4 Y) N. j# ostatic void do_it(void)
; H# }- d2 c9 r8 |# F- Q) g9 f8 T{5 q) ]- O/ Z; C
    // Assumes that the display part is the top of the assembly3 g# v5 E' Q2 u1 i/ q  Y

* g. K! g8 X" J! \5 W; {    tag_t
, d1 Q: U0 D% O( i9 |5 Q        dispPart = UF_PART_ask_display_part();0 m0 k6 W2 e+ O* ~8 e

" C3 e: B2 N: }8 e    if(NULL_TAG == dispPart) + Z( R. G) Q6 J  P" ]; m
    {
0 V% k- k5 V" ?/ ]2 ^        ECHO("Program requires an active displayed part");
9 Z4 b3 N* }+ x; Z        return;+ z9 Q1 Y$ T( D  f* i
    }
! T& @" H" W4 E7 M% G) ^2 q& C( A4 J; ~4 E2 P6 a: @' {
    tag_t' Z, X, b" @! r- a  @5 k, q% F
        compTag = NULL_TAG;* Y* Y: T4 n$ s5 X* Z
: O$ G2 }4 M. p7 j# {% B" t
    while((compTag = ask_next_of_type(dispPart, UF_component_type, compTag)) != NULL_TAG). O% X5 O6 R: a3 [8 o& b
    {
- f6 Y% m% J1 r        char9 l6 W0 `8 w% \" O0 e( `3 k, b
            msg[512] = {""},
' A5 k3 Y* o1 c$ U            fSpec[256] = {""};
  O# ]/ B- F4 y  b6 f* Z) U( D- L! e# t1 |& `, W; ?
            tag_t
/ A& [; S* O/ I+ n* P% p6 L/ T                protoPart = UF_ASSEM_ask_prototype_of_occ(compTag);7 R, K1 X6 b% w5 t4 A# w: I! I8 K$ ^( h
" W3 O5 r# |, O, u4 M5 b
            UF_CALL(UF_PART_ask_part_name(protoPart, fSpec));
. n* O# L4 c. V. y- t; e
. _9 U- V; D7 o! J3 ^            // uncomment to see all component names:+ {6 v; a! V6 D, }* b
            //sprintf(msg, "Component Part: %s\n", fSpec);
8 N# O, Y2 {5 B4 u            //ECHO(msg);
( O7 g; @* H' t+ G  D0 j" |/ k
& M+ P* V) u6 d( S  n# e- R+ L$ I            Component *theComponent = (Component *)NXObjectManager::Get(compTag);& Y. n% g  {' v+ T! B
            if (attribute_exists(*theComponent, RO))2 e; @, e7 X% ?7 S) e" B7 Q% m+ N6 E7 o
            {
4 V8 Z2 H, u/ m7 G0 D$ [1 r/ _                sprintf(msg, "**** Reference-Only Component: %s\n", fSpec);
, \8 B! \( _; c- Y                ECHO(msg);3 G8 j" H. o8 i5 I3 q' @
            }
) s7 F- p$ r" `! t& X3 d    }
5 a$ g. g2 p; R6 `- {) y0 `}[/mw_shl_code]
& _, }* f- v' X" ~4 W; C- S- ~
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了