PLM之家精品课程培训,联系电话:18301858168 QQ: 939801026

  • NX二次开培训

    NX二次开培训

    适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术对于老鸟也值得借鉴!.

    NX CAM二次开发培训报名 NX二次开发基础培训报名
  • PLM之家Catia CAA二次开发培训

    Catia二次开发培训

    Catia二次开发的市场大,这方面开发人才少,难度大。所以只要你掌握了开发,那么潜力巨大,随着时间的积累,你必将有所用武之地!

  • PLM之Teamcenter最佳学习方案

    Teamcenter培训

    用户应用基础培训,管理员基础培训,管理员高级培训,二次开发培训应有尽有,只要你感兴趣肯学习,专业多年经验大师级打造!

  • PLM之Tecnomatix制造领域培训

    Tecnomatix培训

    想了解制造领域数字化吗?想了解工厂,生产线设计吗?数字化双胞胎,工业4.0吗?我们的课程虚位以待!

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

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

[复制链接]

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

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

admin 楼主

2018-1-10 17:48:41

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

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

x
; V& |) C$ a0 q) a

# A+ q6 J! `0 a. DNX二次开发源码分享: 获取当前Reference Component的通用方法
/ d, p2 x3 X( N0 y7 n
' S. p1 ?+ d& [$ {8 b: |- g2 K4 X# m0 m

; V' v6 g2 [* N: o2 Z$ t" m
6 ~; [  @3 l2 ~8 h# \$ j( b' H
% H! a) H- u3 @  e" N[mw_shl_code=c,true]static logical attribute_exists(Component cmpnt, char *title)
" F3 H* Y! z" t{. N, W0 }& P: \0 t
, g. }: @/ y, t6 }* b
//  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.% ~, a5 A* K! j( _/ X
    6 u8 e& T- H; P. Z! f
    logical7 P- j& H0 i% z( B( r6 p
        hasRefAttr = FALSE;
% a/ e. c0 u, X
  u; ?3 E0 H& l; x; }( {) H    hasRefAttr = cmpnt.HasUserAttribute(RO, NXObject::AttributeTypeAny, -1);
$ Z5 b1 o: M/ P6 r7 {
* W/ l% f! W7 S, I4 m" {; y8 s: Y    if(hasRefAttr == TRUE)
2 F6 b- j/ ~+ d$ V# X/ r6 c8 z& `    {: i. l: k1 j/ {  F
        return TRUE;
/ R' n; g# J9 o0 W$ N1 k+ ^' B9 W    }6 C1 b4 B* t. K/ I

" ?6 |$ j' ?/ x7 B) Z2 g& l    return FALSE;9 P$ ^8 x  ^2 w$ y! G  Q

: Z: \2 J7 M' s8 [: p( q- \# X: X0 r}
  o, B+ ^) m5 I: i: S9 j0 ]& h4 s8 n- u+ V8 h
static tag_t ask_next_of_type(tag_t part, int type, tag_t object)* s/ j- O$ E" [& j; v" o4 R# H* c" u/ Y
{
0 D" S5 e: m4 X3 m$ H! o1 S" g0 m3 _    UF_CALL(UF_OBJ_cycle_objs_in_part(part, type, &object));
- C' s& l% G8 V7 ?    return (object);
! G& e0 z. k- ?$ k}
3 ?7 b/ R$ [, |' ~5 `$ ~, T. e" |5 E+ l7 V' z' h% {8 j" f
static void do_it(void)
% r& B/ q# e: D3 ?- {% C{
" ]: X  [% e9 G6 d; n3 x; C    // Assumes that the display part is the top of the assembly6 u8 x- ]7 o$ g; y+ d  C3 t; {

) N2 a$ D8 p8 a9 `/ j    tag_t! K" Y! z, \9 w: p& N
        dispPart = UF_PART_ask_display_part();2 p: ~1 O# E' n0 L$ p
( F( E  S! O/ C4 u- R5 L! n
    if(NULL_TAG == dispPart)
; \* ^! U* h- ^1 Z! r& I    {
+ ~0 y( D# ^8 ]6 J- M        ECHO("Program requires an active displayed part");7 ^: q' u$ D! V' E' D, g1 b
        return;
7 t" y$ U, m- C4 e    }
) j8 M/ G% n6 \  B4 t' F& u, i, Z' v- ]
    tag_t% ?! b7 I) d5 n" a5 u. s
        compTag = NULL_TAG;
# r) M  m' u, `+ Y( \+ E% a8 K2 F/ D( C' G# D& I
    while((compTag = ask_next_of_type(dispPart, UF_component_type, compTag)) != NULL_TAG)
  a* ]1 R. h5 g2 f7 E. N    {
# s, l% f" X- ^' ^        char
; N6 p3 A; x& F' a0 Q; q/ ]1 [/ r6 C            msg[512] = {""},8 ]; S: L; j8 P  m# x1 E
            fSpec[256] = {""};
, c; |2 u6 p" G6 t
; S9 k& ?9 Q" J) w/ [, A* l            tag_t
1 e5 |1 ~& {  L9 d                protoPart = UF_ASSEM_ask_prototype_of_occ(compTag);
+ r$ p# B6 Z' [( Z9 N
2 C) \9 m; r% l8 C; s            UF_CALL(UF_PART_ask_part_name(protoPart, fSpec));
  a' H& d' V$ [7 ^$ Q/ b. E8 j; A8 ]: ^# ]' r
            // uncomment to see all component names:
# E6 E( \3 H9 ?7 {2 Q3 L  R, ]3 |. V            //sprintf(msg, "Component Part: %s\n", fSpec);
% R# r+ `7 w5 Z: _            //ECHO(msg);/ J9 ]7 n. P, q" y& S- p) J
* X2 q2 [3 s0 P& u/ g
            Component *theComponent = (Component *)NXObjectManager::Get(compTag);7 x8 m) J+ |/ g" E* _( p1 u2 z
            if (attribute_exists(*theComponent, RO))
; O* D# C( p9 J# q6 n( F' ?- V0 f            {% b* P/ O. D5 O0 T7 l" Q6 D
                sprintf(msg, "**** Reference-Only Component: %s\n", fSpec);
! Y& R% m7 h5 Z" m* r                ECHO(msg);+ X3 D, s6 u" i$ b1 E4 [
            }
; M( m% |2 m( I3 @    }
1 Y# a& K! M: v. C}[/mw_shl_code]  L* b" @% Y1 P4 b9 f
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了