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

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

admin 楼主

2018-1-10 17:48:41

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

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

x

, s! l. e$ F8 l- W  v
2 E) F. V% X3 W4 i9 ~- dNX二次开发源码分享: 获取当前Reference Component的通用方法
- F1 X* U8 c) B0 O
9 A7 i6 Q+ o6 Y3 ?
$ y( l" A, e6 F# m! T* _% a1 v4 w6 O3 P

/ }2 _! `) _& C& f! j# {
! }2 H# y1 |0 S[mw_shl_code=c,true]static logical attribute_exists(Component cmpnt, char *title)
' B/ P5 ^8 X, G1 F{9 W9 b3 g% O. s, f8 h

4 L$ t0 k6 @3 _& ?2 D//  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.: `/ o, v9 J( q/ A. `
   
4 Q- H0 P. I* w( u    logical
* C' J9 P3 c& ?  x        hasRefAttr = FALSE;: N6 K6 n" Q4 A

! z& X- |+ L2 b' R: {    hasRefAttr = cmpnt.HasUserAttribute(RO, NXObject::AttributeTypeAny, -1);& {# p# l- D) ~

3 M5 C6 @4 I$ r3 u5 H    if(hasRefAttr == TRUE)8 b$ I% }# r. V0 j# m! `" o
    {
2 h( Q7 {- R0 P3 g5 [% u# z        return TRUE;
) o. A& {4 H  |; N    }
# T/ h- u, y4 ^8 M% m- U- P5 |, ?5 k& D& x6 u3 j
    return FALSE;2 F9 K- H( d1 W( ~. ~% z5 B& y5 [5 E; x

' W+ Y, w( E  X) S, }* |3 {}
; R3 B; @  }7 w: L  S0 e0 @+ J$ K
static tag_t ask_next_of_type(tag_t part, int type, tag_t object)/ N' q& @0 H, U5 m) J6 B
{8 Y. O( X0 C" j. B+ ~) U
    UF_CALL(UF_OBJ_cycle_objs_in_part(part, type, &object));' N1 P. a$ R8 d2 Q0 C8 k6 z1 H
    return (object);0 c9 O1 O! J9 m: B/ v8 i5 J
}2 p& V6 R; h9 ?  c
7 Z, f3 D: y3 R$ d
static void do_it(void)' L3 s4 q$ _3 a) q8 B
{& C: Q5 _+ L' X6 G; v4 V
    // Assumes that the display part is the top of the assembly6 O0 h% \9 |; s) t7 Z
1 \1 z0 M+ v1 }
    tag_t" u/ [( w) X6 E' c
        dispPart = UF_PART_ask_display_part();
5 b6 c8 E# Y3 l, _9 ?# Z& J8 x. Q0 v( W% D# E. [
    if(NULL_TAG == dispPart)
9 e& _$ [' A, F2 U/ E% g* \    {
$ d# {/ r( Q1 P) E        ECHO("Program requires an active displayed part");
& h0 j# B: Z7 D/ H        return;4 D4 D8 z1 m& }$ L" Z
    }2 F7 P- Z) R* [

- T1 q  t0 P, Z* ~/ x& v, `* M    tag_t
$ u& k7 T7 B* [# E6 F; A2 o+ p& S. ~        compTag = NULL_TAG;& N' Z$ ~+ I% E& e0 M& j! H

* ]( b5 @. V& R" z, Z( K% ]    while((compTag = ask_next_of_type(dispPart, UF_component_type, compTag)) != NULL_TAG)
$ R9 V3 [+ A& z* {/ }    {
% Y2 t$ v. _* c4 t. \+ {- w        char
1 \4 T7 M4 n' j5 \            msg[512] = {""},3 M5 c$ y) b1 [0 c8 r
            fSpec[256] = {""};
) a; z- e: \3 E2 {$ J/ {
' d2 e: ~0 y# R( x3 S, J! w4 l            tag_t5 Z0 e& M2 Z2 ?3 h$ |
                protoPart = UF_ASSEM_ask_prototype_of_occ(compTag);% v" _& g' Q0 D/ n
& d* N& d# A  U+ \+ g
            UF_CALL(UF_PART_ask_part_name(protoPart, fSpec));
  `* r7 R" v# X) X: f" w* F& A: I1 \+ \0 n) ]3 j3 _/ B2 G
            // uncomment to see all component names:2 i2 F- a1 N0 o# W* e, Q
            //sprintf(msg, "Component Part: %s\n", fSpec);4 |% E' L3 X5 \8 _
            //ECHO(msg);
6 V! o: n9 f" L+ D$ s2 F) O% |, M# a) P
            Component *theComponent = (Component *)NXObjectManager::Get(compTag);
+ Z8 Q7 X" D$ b  ?5 w, |            if (attribute_exists(*theComponent, RO))5 o5 j9 T/ B! u/ c, X* d8 g$ b
            {& Q  @: m4 M% j4 ~
                sprintf(msg, "**** Reference-Only Component: %s\n", fSpec);
8 R! b2 J! o% d- x* ]1 b                ECHO(msg);* E7 A* x% |' L0 _5 |( a
            }& p  N" b- Y5 \
    }
: `" ?0 ~  m% o9 O' s. Q}[/mw_shl_code]
  k5 Q' ]' @0 b3 C1 i, ^/ @
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了