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 1895 0

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

admin 楼主

2018-1-10 17:48:41

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

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

x

/ T7 r( V* U8 t+ R  j* f/ s
; F  G+ ]% B- S! N5 I; ]4 yNX二次开发源码分享: 获取当前Reference Component的通用方法
, R7 }2 [2 L" X9 x1 D( N0 S+ n, O  @  T

: U0 R& @0 z' ^2 C% W
3 O4 U! c  Q- E& n
! u* V: I" B8 v, ?' `: {$ a- n, R, @' K6 C' ^
[mw_shl_code=c,true]static logical attribute_exists(Component cmpnt, char *title)6 L3 U5 |( Z2 U9 w! J
{
) K" _# a. ?+ D1 A# `0 P" l
  n+ D# O: @# U4 C2 w1 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.
' E5 |! w! r$ h; n5 C    4 U  t( s# k+ S+ F, w$ b
    logical) [4 ]2 d* ~6 N& Z" I( S. E
        hasRefAttr = FALSE;
1 i$ P' U* O7 t7 O- r0 M8 D7 H* q
+ E1 t$ }) x/ K6 F8 @    hasRefAttr = cmpnt.HasUserAttribute(RO, NXObject::AttributeTypeAny, -1);# |; R$ L0 D" B+ |8 y

' s' z: p. B  O$ }) V/ v    if(hasRefAttr == TRUE)
/ J0 {/ k) G4 T( a( _4 y8 Q    {
+ h( b8 V! u; r$ \# A+ P5 s        return TRUE;
9 s4 o0 l9 e: d2 M2 P    }
4 m7 i+ s6 D0 T4 p5 Y
- Y2 ^4 R+ [. I' u8 N- n, C    return FALSE;! e5 y! M" a+ y  A( d8 @, j
; C1 e  w: W' K- L# Q1 `
}
2 W7 S% o4 P: P6 Z1 x. n! C- c0 c# @# `
static tag_t ask_next_of_type(tag_t part, int type, tag_t object)
9 `+ Y3 r5 M+ Y+ Z$ @{
/ L/ E0 }  e6 O* g. H- F    UF_CALL(UF_OBJ_cycle_objs_in_part(part, type, &object));8 w1 R! C" P% u: ?! v% I+ C
    return (object);
& G. V* f' i' I}
' q9 R7 Q: |) v7 M( F, f& g7 `3 T& k1 r' v/ |' z
static void do_it(void)
, o) ?6 G1 C. p# U{- O3 W' S# P, Z5 K! _: n
    // Assumes that the display part is the top of the assembly2 L+ `0 a+ ~. h& N/ `* z. P
4 X6 Y( J; }* i! h% {1 z9 ?( ]. }
    tag_t
* y8 |- S0 `1 e& w$ o: ~9 W        dispPart = UF_PART_ask_display_part();0 r2 |: @% z* j/ C
  Y3 k2 m% q3 Y
    if(NULL_TAG == dispPart)
3 ?1 `. P) |% ]9 M- f) w5 S    {
6 t2 A# L3 {; r+ x$ f        ECHO("Program requires an active displayed part");. \# k" E& c9 h, }, _7 `1 H3 @& {
        return;  ^' }6 w! f. M7 [
    }
7 R" I/ }0 n9 G& O, K  Q4 `
" Q( d+ T+ I% z0 A  V' Q    tag_t! [! u  r& T! r- Q. q
        compTag = NULL_TAG;! F0 c- m7 u( ^- J) x  u6 e
, }$ ~7 ]& @; |! o
    while((compTag = ask_next_of_type(dispPart, UF_component_type, compTag)) != NULL_TAG)
9 t. Y& _+ q) Q: b& i+ W" I6 v7 F    {
  D& `4 ]3 e0 \  h( \        char
1 D- j' q0 j3 e            msg[512] = {""},
+ I6 W! _0 a9 U& u6 h/ I            fSpec[256] = {""};9 w4 [' Z. v) t: W. J. B1 P

  o' I/ l" ~: C  v3 p4 W            tag_t
2 T# P5 s" M, l0 l1 b                protoPart = UF_ASSEM_ask_prototype_of_occ(compTag);$ [6 P* k+ i2 l1 I

' `1 q5 W; Z& e1 v- U6 e2 U            UF_CALL(UF_PART_ask_part_name(protoPart, fSpec));: t( t4 I' Z  y6 ?/ d
6 I% _8 V5 x8 i, l+ ]( r, F+ ^
            // uncomment to see all component names:5 h: L5 A+ d# |' s7 f. J, ^
            //sprintf(msg, "Component Part: %s\n", fSpec);3 x9 O- Z2 e7 X, }$ `# H4 Q, U
            //ECHO(msg);  A. \8 q/ M+ u- O8 o- k
: s4 V# T6 Y' k( n* y! D
            Component *theComponent = (Component *)NXObjectManager::Get(compTag);  b( P+ E% W& z; m; z8 W- S
            if (attribute_exists(*theComponent, RO))
$ V7 \7 O2 S. E) I& L! x/ T            {
: `0 j. w0 T/ V/ j$ j5 Y3 a% }1 u                sprintf(msg, "**** Reference-Only Component: %s\n", fSpec);
7 _* _* F! @5 ^5 k) A3 g% A                ECHO(msg);
6 D2 e$ V8 k# K9 Q' C/ n. U            }' r3 l5 a( \. e8 K( y9 d+ J
    }
1 g3 q/ D# B4 ?}[/mw_shl_code]0 |8 [" Y* b. W& Y/ g! S
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了