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

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

[复制链接]

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

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

admin 楼主

2018-1-10 17:48:41

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

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

x
- n0 @+ i5 `' S# D5 @/ x3 F9 O
$ D$ G! F% [( m, F* H
NX二次开发源码分享: 获取当前Reference Component的通用方法
, w7 _0 g, i# ?, c) ^7 l/ P( q  |; ]/ B* x7 X# Y

* B& {5 H; U. {& J3 D- y8 b( [& p$ m& a& n1 @! Y5 U
& q" B4 h% q1 X/ P, x% D( U$ J

6 S- E) w$ ]) F5 B4 Y[mw_shl_code=c,true]static logical attribute_exists(Component cmpnt, char *title)" Y5 ^# W, S8 l/ S% T
{
- l  P: O8 ^. `8 _( }" k/ Q: |  @
  q( B1 g7 ^, U+ e* Z- 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.2 ]4 j, P3 P4 i* f" m& v, H
    $ j5 g: `  \. H$ H8 D+ b$ k, M
    logical
, p+ U4 @+ n8 [+ p        hasRefAttr = FALSE;* p1 B# t" P  ~3 R& y

. K2 R4 B5 M4 V' Y1 m% F    hasRefAttr = cmpnt.HasUserAttribute(RO, NXObject::AttributeTypeAny, -1);
% i3 B* I: x  `0 Z' G
0 o( x7 @; r( T    if(hasRefAttr == TRUE)
+ F, o/ v) h" v" o! m6 g1 q  C3 H6 J    {
( i. J; i# ]$ i" C% v0 r        return TRUE;/ L& H+ y5 C+ `' ~
    }
- m0 e, w5 }4 X/ {& f* F2 E2 n0 t$ E  n# U7 A
    return FALSE;/ Z7 X; ~  D. n6 V; f. y1 D* v
" V+ @0 Z+ W' j; m! |7 g
}
4 e4 d+ ~. A4 J) ?' A- z$ [, H
/ C# s  h* |  {  b$ A$ ]static tag_t ask_next_of_type(tag_t part, int type, tag_t object)- Y4 b# p* y2 @" Q1 h5 q
{
4 v5 G, ]8 B. x/ u5 e. R8 }0 J/ N    UF_CALL(UF_OBJ_cycle_objs_in_part(part, type, &object));
$ m6 m1 q# o5 F3 Q) `: N    return (object);
' x6 ]- S& I" L/ U* F7 M}5 O: d" N" o. d3 I' O  O' |# N
# C4 u& i, R8 i% F) g2 v7 b
static void do_it(void)8 K  Y9 p* S7 @
{8 S6 j' ]! b# u! F
    // Assumes that the display part is the top of the assembly
7 W# c6 E4 m$ l
6 H- ]8 v  I8 S    tag_t
" L. e* q$ O) W9 e) ^& V        dispPart = UF_PART_ask_display_part();$ D) l9 r1 s  F5 J0 V9 s

; O  ~( @' L2 T7 Y    if(NULL_TAG == dispPart)
# |0 _$ C0 b+ }1 Z: L5 \/ r% e$ e3 J    {  U% Z" r3 I* y, W
        ECHO("Program requires an active displayed part");+ D& V& ^$ d$ d5 ~
        return;
1 O: W" _: i' o9 b/ M* d. i, ~( K    }
3 f) _9 ]9 n7 ^% E1 y) B. ]
% @1 J  B# F" e" r" E/ _# C    tag_t
8 E% K" ?  N' _( N* L        compTag = NULL_TAG;
$ Z# K- K9 u# r) K& P, y
) m: |" ?3 r( h$ b' e* x    while((compTag = ask_next_of_type(dispPart, UF_component_type, compTag)) != NULL_TAG)+ Q! r5 a& p' l7 C, @5 d' f$ o, j; {
    {! |5 B0 C1 j9 E: P  z
        char
& E- ^+ \2 p& S3 b/ _            msg[512] = {""},
- f: C) R% j& P6 ^- c1 x            fSpec[256] = {""};* l- _/ B+ }7 g2 y& e
1 s& s. b& p$ ^3 x3 Z* C8 f1 R$ L; f
            tag_t
4 ~3 n/ o- i2 J: ]" @% s5 {/ H* [3 f                protoPart = UF_ASSEM_ask_prototype_of_occ(compTag);7 S$ H! T, h5 j1 _( Z) Q" \

2 G4 x) L! q0 ^; u1 ^            UF_CALL(UF_PART_ask_part_name(protoPart, fSpec));& \" _$ a7 |; M  Y! i

8 i$ ?! F7 B& G1 M& {            // uncomment to see all component names:3 V+ P: \2 k+ }8 r' ^6 ^
            //sprintf(msg, "Component Part: %s\n", fSpec);
. y: G) M- h5 u8 v            //ECHO(msg);
1 j) [( C0 r5 `0 X; Y
4 V3 d/ m! E6 x/ s' v7 n1 Z8 [' E9 S. N            Component *theComponent = (Component *)NXObjectManager::Get(compTag);( X- l7 R+ M' s
            if (attribute_exists(*theComponent, RO)), `/ Z: h( M$ \% T" ^0 u, W
            {
4 a. C' M  T# D% E* W( y: l                sprintf(msg, "**** Reference-Only Component: %s\n", fSpec);
* G2 T$ Q8 s- U6 h) L5 f                ECHO(msg);
. b* ]6 G# q$ e0 q7 ~9 x            }
( B* o4 P% n' V  ^* M    }+ L( `" y9 k7 W
}[/mw_shl_code]
! K+ p4 F2 ], s  G: h: C- d  ^
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了