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

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

[复制链接]

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

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

admin 楼主

2018-1-10 17:48:41

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

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

x
4 x: x5 V; h' V$ \7 d
) X, C+ M% Q& ^$ q
NX二次开发源码分享: 获取当前Reference Component的通用方法* y2 g; U. f) _/ p8 _& p

: V; u" R' H. u% \
5 Q- d: X  F0 ~5 ]* R" i6 y5 Y, E( p' z6 [+ K# B$ H0 C
8 @$ X) |( t6 W* o9 H3 i
. }: F! K+ p2 ]3 {5 H. h2 h
[mw_shl_code=c,true]static logical attribute_exists(Component cmpnt, char *title)
; K$ u, F6 Y/ G* f3 ?0 `9 l; c* r{4 P9 r: a( Q# X: _: p
% H5 \6 B# l; @$ ^
//  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.
% L6 E; g, `1 A- S( d    ; t5 `) o5 ]- q! |. W! A% ]
    logical
4 m, f/ d  {* l        hasRefAttr = FALSE;
( N4 _! @* o; S* ]
# p1 m, w4 x4 ?/ n/ E    hasRefAttr = cmpnt.HasUserAttribute(RO, NXObject::AttributeTypeAny, -1);
0 t7 w& s) e# O' e- y  h/ P$ O
    if(hasRefAttr == TRUE)# T9 j0 A0 b8 r9 d( @
    {) q6 ~8 W0 ?/ x! g( @) y! x/ Q* [
        return TRUE;
5 K  f# z) o4 ^- p0 B- j    }
, w* Z) ]& J5 a" ~0 G4 I: c1 L( |
) ?6 N% t1 h& Q, o& P% O    return FALSE;1 e) @, z+ X1 ^( U2 Q

, @& y. P; Y- W  W9 A' F( m}
' v( S: S" Z2 f1 u7 O
7 [* |! O/ f( z+ }' Dstatic tag_t ask_next_of_type(tag_t part, int type, tag_t object)
7 s9 H* x/ o3 `7 {& Z# T* d/ U; N{
" B7 [) x* T. V  r5 k    UF_CALL(UF_OBJ_cycle_objs_in_part(part, type, &object));' ]% X, {# p8 T! L/ d
    return (object);
& A3 M, f" T# w* y4 `- G" i$ O2 ?: P- `}
5 T( a. g9 q7 A- [0 c0 n+ I% j' K0 [) U6 K  P- t! V: E
static void do_it(void)
% B6 B/ C- g0 P) o7 r2 [( u1 y{8 E2 V& K) R% {3 Z3 }3 m/ ?) M* H
    // Assumes that the display part is the top of the assembly. r5 e2 x  v5 ~# _5 P: O3 M* a$ l
9 q. n8 \" @/ i: s6 ]: Q) Z
    tag_t
: N2 q2 Y7 w  M, ^        dispPart = UF_PART_ask_display_part();& G4 K/ ?+ m' ~! y

; e3 r/ K* \' A: V    if(NULL_TAG == dispPart) 6 E. a" C; W: V' i; H- Z1 i7 W
    {" I0 ^+ [' ^" X! `  l5 t
        ECHO("Program requires an active displayed part");
7 t& S! V3 Q" [4 S( V. L        return;$ X2 [" [3 A5 L0 w' h
    }# H+ q! w1 v& L9 K8 E9 }
- {5 u& w9 E  @5 m2 e6 ?) K7 ^
    tag_t8 Q2 K% Z3 Y" A/ a. h0 S# y9 t
        compTag = NULL_TAG;9 z3 Y' ?6 S4 s
: ?( O: u$ M" @: j: @1 t
    while((compTag = ask_next_of_type(dispPart, UF_component_type, compTag)) != NULL_TAG)
! X, O( A* ~6 v' ]6 S# X% V8 C6 k    {) I8 N# n& x/ P& ]; x
        char* A( L; @2 c6 s. R8 Z3 ^
            msg[512] = {""},
) y% s* z# l9 P& I            fSpec[256] = {""};( Q+ g6 W" _4 C5 |; s1 k

; ^/ y4 V( Q/ s/ r            tag_t$ h, Q3 N4 T: u, e& o8 i3 L; R9 w
                protoPart = UF_ASSEM_ask_prototype_of_occ(compTag);  u) z  [5 p: T" m

0 p) v* k) \, ~9 Q! O            UF_CALL(UF_PART_ask_part_name(protoPart, fSpec));) ]- M. ]6 g$ U5 ~! z

/ X# F; m  j0 |' z# n/ C            // uncomment to see all component names:
4 q9 A+ u. v, I' F  m            //sprintf(msg, "Component Part: %s\n", fSpec);
, E% M* n+ G/ e) W( s' {$ b1 w            //ECHO(msg);8 c0 ]: U. K4 g! @7 C  M
! g! G/ a+ I. Y9 |: I3 l) Y) J
            Component *theComponent = (Component *)NXObjectManager::Get(compTag);7 v4 m4 K& @' S5 Q
            if (attribute_exists(*theComponent, RO)), g! x% F- A% r8 V5 S, O) N. r
            {
6 E5 [$ d6 o' p% _" e( v                sprintf(msg, "**** Reference-Only Component: %s\n", fSpec);
$ _$ S( |  O% L; \7 G                ECHO(msg);: ?- L0 z# }, O+ ~' Z& g8 I! V
            }6 |$ M( L9 @, I
    }
: V. r2 z  n* Y' J+ x$ A' I( P$ f3 d}[/mw_shl_code]
4 ~+ R1 h# \1 r1 q; z8 C
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了