查看: 2436|回复: 0

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

[复制链接]

4

主题

3

回帖

48

积分

管理员

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

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

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

×
& E" m: B9 y/ F+ ]' G! h' M

7 l+ Q, e9 G* s& o& p4 W! W; `NX二次开发源码分享: 获取当前Reference Component的通用方法* Y. _1 [  k0 s- q/ [# ?' [
3 ], N1 {1 Z: T  J! \6 r

  v2 p/ f9 J& R: j4 a" S8 M9 \/ J9 g1 u; q% D, ^+ z/ _7 i
' f  _3 y3 W  _7 w9 o" M
3 `- q% w9 O% k- f$ ^
[mw_shl_code=c,true]static logical attribute_exists(Component cmpnt, char *title)+ S3 S* q7 f4 c9 b$ b, j* e
{
/ _" ]& t( d; A9 n* i, P; y4 h
" |  v! x3 d( Z7 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.  ^8 ?5 C* |) u+ M: l
   
' |1 k, }" L) A4 n    logical
+ e) p; x5 p( k# w0 i8 u        hasRefAttr = FALSE;6 E% }( B, H" f  m; N7 \' ^
5 K+ I: |3 S  V9 r6 S
    hasRefAttr = cmpnt.HasUserAttribute(RO, NXObject::AttributeTypeAny, -1);
% x4 @4 i/ Z3 b$ J( Y
) M: |" T9 K- \8 Z7 B8 T: ~. ]    if(hasRefAttr == TRUE)( \; M# B3 w8 K& k$ D5 t2 i# @
    {9 G) Y4 w6 v  e8 y& Y1 B" K
        return TRUE;$ w. @3 u  n: w4 [- n
    }
1 W$ h8 @2 [# h2 J0 O  J* Y3 V) {3 k5 [
    return FALSE;
5 f* {& ]* l! b' O% o7 i
4 U8 H8 f" R0 r8 H8 W1 g}* j  k8 J" |5 q4 Z1 ^: [
" n0 f( @0 B$ V1 }' z! j
static tag_t ask_next_of_type(tag_t part, int type, tag_t object)
7 V! z+ X" l- v: a; T{7 O( N; y, r2 Y) t7 k6 |7 K
    UF_CALL(UF_OBJ_cycle_objs_in_part(part, type, &object));
4 Q$ u5 R( U- u, D# D/ M0 h* y9 c    return (object);
( @8 z9 E* f: D( s( p}
5 F9 A# A# X* y4 h3 Z1 Y6 W9 P9 K1 s5 d8 Z
static void do_it(void)
; }0 C1 F  Y# y5 G, [8 c{& L, q$ g! T7 x; B" u$ ^9 E* |
    // Assumes that the display part is the top of the assembly+ q. H; Y2 E% E& D# o
9 z5 S4 ?5 Z3 f5 J
    tag_t
! ^" S. @  q; s6 b8 R5 p        dispPart = UF_PART_ask_display_part();, P1 p4 P4 p0 i5 E

: A/ T' J" b4 c; L1 @$ @    if(NULL_TAG == dispPart)
* S2 V% ^  ?1 E% B    {) B2 i' u5 q$ h/ v( U) l# r
        ECHO("Program requires an active displayed part");
  J. b+ ]$ T. f        return;
% {8 J2 ^' q1 A* X% m4 U    }
4 P3 r4 l: ~6 J2 ^- Z1 F( m! P" e5 m# d% q: c4 a1 b) X  r
    tag_t; Q' N' Z9 S; ~2 J+ u9 p3 b
        compTag = NULL_TAG;% o# C* J, q# l% V, q

: S8 g  K, v9 t: P5 N. a2 q    while((compTag = ask_next_of_type(dispPart, UF_component_type, compTag)) != NULL_TAG)
0 r) J/ ^4 j. I# }+ B1 F, S0 ?7 `    {
3 ^1 G3 R+ V- l6 X- r        char
: j+ c1 A# S( _            msg[512] = {""},; y9 l1 w9 F4 j# U6 d) ]
            fSpec[256] = {""};
0 p& c: U3 n  E' ^8 I! a
! Z* {$ r0 @4 B2 l            tag_t
. G3 z9 R7 b" s" _/ M                protoPart = UF_ASSEM_ask_prototype_of_occ(compTag);% Z' B$ W6 l2 c' B2 P6 O6 X' z
9 H( x& S2 k# m$ n) N0 m
            UF_CALL(UF_PART_ask_part_name(protoPart, fSpec));
+ E, L) g. P; m/ s1 R- U( u$ ]6 t, g) l
            // uncomment to see all component names:3 M- K2 y8 D; `3 t& G6 F/ {
            //sprintf(msg, "Component Part: %s\n", fSpec);
+ E9 X6 E, {8 x. x9 P' C- s' [            //ECHO(msg);+ A& E& ^# r: H* J1 H* V' i% a
$ g  ?! g# N; x# r6 P
            Component *theComponent = (Component *)NXObjectManager::Get(compTag);& `, F- O, M$ E# l
            if (attribute_exists(*theComponent, RO))9 b$ X1 {( Z  ?  \9 \
            {0 ~9 Y+ B5 N( G
                sprintf(msg, "**** Reference-Only Component: %s\n", fSpec);4 K  Y* f$ Z# |+ b9 r
                ECHO(msg);
! P+ L3 t/ S: x% _$ Q! u            }, [) w7 k7 K! F
    }
( R, Y! m% g8 m* f# \1 ?& ~}[/mw_shl_code]2 _- M$ ]) m' \2 L
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复

使用道具 举报

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

本版积分规则

在本版发帖
关注公众号
QQ客服返回顶部