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

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

[复制链接]

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

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

admin 楼主

2018-1-10 17:48:41

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

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

x

& t2 ?8 `( [8 \, @2 N$ X8 e# |' ~/ B+ u8 R/ P
NX二次开发源码分享: 获取当前Reference Component的通用方法" h! E* [% d7 v) N' G

' y6 F# T4 q; \% }& {. l1 ?6 I8 g* J. m; d8 B
6 W: G( r0 a, a- R. k7 @

( h5 d+ T# B" t% o$ v: L1 _* E9 ~  g6 Y5 o( J2 C8 n; q0 B
[mw_shl_code=c,true]static logical attribute_exists(Component cmpnt, char *title); V. Y+ E) e+ j8 i' d0 q0 |. V
{
" b4 |2 c3 P9 Q) c5 f; x  I( f- i2 f) r1 y& ^# E* S7 K/ ^. }- 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.
) v$ f' @  v4 i: s. e* \* E    ! n0 Y- U$ \" [# r
    logical
' B: D% V' d" G. |        hasRefAttr = FALSE;2 }" y9 [7 b) m) x6 U& O

% e4 n7 A0 ?# k. g! Q( r    hasRefAttr = cmpnt.HasUserAttribute(RO, NXObject::AttributeTypeAny, -1);
# n- O+ B' ?) [/ R4 s2 S
5 c' c' a+ l$ Y) u  Z3 }0 [2 l    if(hasRefAttr == TRUE)
- M* o' W- W6 E# V    {
8 `) D3 n6 `. F- N, p. j        return TRUE;
2 `: R$ Z2 W: c' M    }
' _8 D, [1 A3 w; l) P! J9 Q+ }7 R- f( O4 z, K( O
    return FALSE;. e1 w" p( O7 B& g

" \$ F% f; B4 n}0 R% ~/ H, O: a* W
  R6 s' k2 Z+ {2 }/ u
static tag_t ask_next_of_type(tag_t part, int type, tag_t object)# o- I9 J( r' a9 t/ p1 q
{( c# W3 X! t6 ^! h) g
    UF_CALL(UF_OBJ_cycle_objs_in_part(part, type, &object));1 u2 }) c0 B- g; i- }6 p5 R6 i5 F
    return (object);
* P4 b! c7 h  s4 w& [6 M}
+ N; |7 k% j, Z8 f* J7 u
2 S: w2 X$ p4 z& ]; z9 nstatic void do_it(void)4 V6 [5 j" l& q
{
' j) x  Z& ?, o4 v/ y* Q( \    // Assumes that the display part is the top of the assembly4 [$ a8 R1 I( Y( y. Q; N* @8 k; ?0 ]
3 x2 K8 s0 p) s9 l
    tag_t
" i) L+ M0 ]. k- p        dispPart = UF_PART_ask_display_part();( J3 d6 v) j, @" ~4 r8 ]8 T

. Q' {3 D$ H9 B$ f8 E5 k    if(NULL_TAG == dispPart) 9 S2 R. C/ H5 A: z6 e; f, O7 h
    {; R# r$ B7 F) ?4 j+ I  _
        ECHO("Program requires an active displayed part");& B. W2 ~' o$ }# e
        return;& L, ]$ Z( Q# w* d  ~" M; h, s, T
    }
: c8 l$ T1 `8 r8 h3 N& D1 W8 j- t
    tag_t
' c: T3 G& u; |, e  K( I4 G        compTag = NULL_TAG;
' R* Y4 \2 w1 \( T. ~7 N: j& ?1 n% w* s
    while((compTag = ask_next_of_type(dispPart, UF_component_type, compTag)) != NULL_TAG)5 a3 C5 w1 B/ o
    {
' h) J! j& Q7 f' C9 u" @$ ]        char0 H; a5 J, F7 C. z/ [) |) }
            msg[512] = {""},! k) T1 i" m9 g/ z
            fSpec[256] = {""};: g: l/ `. D9 c

. |0 U: n2 B1 C; O            tag_t
3 F' E  N& m* h$ ~/ Z                protoPart = UF_ASSEM_ask_prototype_of_occ(compTag);
. [/ a- W6 f$ b2 G7 N( S/ M; d: U; ]" ]
            UF_CALL(UF_PART_ask_part_name(protoPart, fSpec));- K' m) n4 Q: I

/ o: @9 t2 U; f/ ^% _            // uncomment to see all component names:
* O3 Q+ ?; u& v# j            //sprintf(msg, "Component Part: %s\n", fSpec);
3 a$ {( m0 Z) f$ f; p            //ECHO(msg);7 N+ ~/ Y. H- @

: N1 m, w4 y! o# [# t. H# C            Component *theComponent = (Component *)NXObjectManager::Get(compTag);
$ w7 J! c2 T3 W            if (attribute_exists(*theComponent, RO))8 z& a% [+ @1 R, ~/ G+ ~( C( _0 A
            {% Y9 T# y: }& I! u. L: }
                sprintf(msg, "**** Reference-Only Component: %s\n", fSpec);. u8 h2 d# k% J
                ECHO(msg);. f* y0 D& \) ?$ X
            }
' g9 P: w% a% O  h, k' n8 L    }. x$ r8 M% ?- ^7 }
}[/mw_shl_code]; M9 C. U7 A- T  T
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了