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

[二次开发源码] NX二次开发源码分享: 如何判断当前零件的类型,很聪明...

[复制链接]

2018-7-27 11:00:30 2153 0

admin 发表于 2018-7-27 11:00:30 |阅读模式

admin 楼主

2018-7-27 11:00:30

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

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

x
$ q( a/ [1 R  K4 ~

. l9 a0 M" s' V' M2 pNX二次开发源码分享: 如何判断当前零件的类型,很聪明...
; Z6 j3 w. d, d/ @# _9 F
: K3 i2 q: i/ I+ e" r. m" T
# m  f* I8 P- W$ f
大体思路如下!!8 U; a: l- A6 ]7 @: E8 U4 X

: e& D7 k* ]! y; X% Y& p3 q/ y- m2 W/ M
2 v$ p- K  O/ a1 S+ j+ o  R5 g3 ?/ W   enum PartTypes {Empty=0, Model=1, Drawing=2, MasterDrawing=3, Assembly=4, Undefined=5, MasterModelDrawing=6, Invalid=7};! G" h" A- d, H2 |
  ' N( E  B8 Q4 i1 G- Z: s: V
  void DoIt(string[] args)
4 i! U5 N* ~+ x' A3 K8 m    {; _( v1 [+ I$ K3 S
        Part displayPart = theSession.Parts.Display;# ]* |  ]6 ?2 F/ ?: D4 R! t" s
        if (displayPart != null)
6 z6 P& N) {* V+ |+ ]        {1 X0 e4 p8 i  [8 U6 L) Z
            GetPartType(displayPart);
# M; ^' ^5 O3 v3 m3 _            return;$ C1 x& {. i6 ^* M$ ~
        }9 b  r0 t  _2 ^7 t
6 _2 g$ ^, A% t0 M. M
0 {3 L- y1 e; Z; t# V
        for (int ii = 0; ii < args.Length; ii++)
1 z! ~+ B0 c  ]% w( v        {) n5 a! R9 r# E( _4 G
            Echo("Processing: " + args[ii]);
* n% P6 L% ]) `( a) Y. ^8 ^/ Y            try 9 a5 q# k" j4 O: u9 E
            {  a2 a2 k1 W0 ?1 E8 V0 G0 e
                PartLoadStatus loadStatus;' i1 r0 r" j9 p2 n% n  [. \7 G2 k- ?
                displayPart = (Part) theSession.Parts.OpenBaseDisplay(args[ii], out loadStatus);; v, {+ j. Y6 k# V  N, ?: C) n
                reportPartLoadStatus(loadStatus);
1 ~9 m( N  r" u  j$ Y
* w3 _: H2 Q) r- e: N
* H1 x9 f& k: I2 a4 O
                GetPartType(displayPart);
+ `  f  L' @5 Y1 J! o- L* `3 A& ?: `* @3 X
, @3 \* W, }" K3 I; B
                displayPart.Close(BasePart.CloseWholeTree.True, BasePart.CloseModified.CloseModified, null);2 s. F' i8 P7 g/ y  c
            }/ [% E6 A7 j; w' S8 V  K2 o. }% T
            caTCh (NXException ex)# Q+ C  N7 p, R# q* u' {; F+ v: ?
            {% f/ d5 {# ^6 l' W9 |' B
                Echo("   " + ex.Message);  N% A* C( M( v1 g5 p" i: _0 y$ W* \
            }
6 {. {2 l4 z' Y1 y& v5 q% z7 `2 T/ |        }
% y( k; y" H+ Y) c$ Y% h, r9 v    }
! D, c  p. ^  H9 [4 a0 B& D
. l$ c4 M: ]$ |0 l5 P, q& ^' r) @! {

9 T3 p6 B9 A; i/ l    void GetPartType(Part thePart)" `, f' k$ d! z+ L
    {% Y" v+ w, p2 ?, T' U( n; d
        int nPartType = 0;: T4 g; {, j7 o, e8 W. G
7 B! D7 U" v3 M8 I& X6 U3 d" R# o8 q

( }' T" ]; J- F8 d: o8 @; q3 o        if (thePart.Bodies.ToArray().Length > 0) nPartType += 1;: P& b4 X: Z1 ]
        if (thePart.DrawingSheets.ToArray().Length > 0) nPartType += 2;6 @3 \# X7 {7 M3 @; T  `% p+ b
        if (thePart.ComponentAssembly.RootComponent != null) nPartType += 4;  T9 n4 z+ {  W2 I" ?9 g1 Z

. \$ H* M7 m' j7 a/ }! c) W' z/ ?
: o& V  E6 T* @0 P4 P: H2 s
        Echo( String.Format("Part Type = {0}", (PartTypes)nPartType) );
' n6 v/ ]) ~: `    }. x& V4 r2 q0 s' O7 k, b0 @

! @5 G2 W( H" |5 y; `+ P3 @
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了