PLM之家PLMHome-工业软件与AI结合践行者

[二次开发源码] NX二次开放源码分享: 获取装配下所有的实体

[复制链接]

2018-7-27 10:56:17 2105 0

admin 发表于 2018-7-27 10:56:17 |阅读模式

admin 楼主

2018-7-27 10:56:17

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

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

x
# V: G6 u2 W$ J/ e; ?$ H) L
NX二次开放源码分享: 获取装配下所有的实体
& g2 @0 n! Z7 A+ v: A( Y" S5 I
. z9 v* k& k; Z# \. A3 k3 B& D: M1 c8 k
; V( J! u+ J4 t
public class report_all_bodies_in_assembly_level7 ^$ d) \& m' X1 o
{: c2 [2 z5 U4 ^! S+ ^
  public static void Main(string[] args)
6 h. u3 @, c2 P) I8 U% ], U  {
% \3 i* G6 ~' M) m0 N" B    Session theSession = Session.GetSession();" F+ D# p; v' r" U+ @6 `2 t
    UFSession theUFSession = UFSession.GetUFSession();
& J' R9 n* r5 M8 ^! J' T    ListingWindow theLW = theSession.ListingWindow;% E3 X* t! _0 x

1 c+ \) q/ }. h1 }
, B* P% e# N+ T" U
    Part theDispPart = theSession.Parts.Display;
& _0 ^7 `$ s  l; k    List<Body> theBodies = new List<Body>();4 l' a. ]' N: L! k$ r
    Tag aTag = Tag.Null;
# j* P, _* w  ]    int type = 0, subtype = 0;3 B+ t/ O8 `* V: ^

! o0 s8 R' S- D3 g/ p( J  c0 S
* }; [. v7 ]  E7 B; f
    theLW.Open();  n8 }+ Q& m! ~* t' a4 f
    do
- A. a" J% S' x0 X( K    {% Q. m( ^& F- e* Z' e8 X$ v, h
      theUFSession.Obj.CycleObjsInPart(theDispPart.Tag, UFConstants.UF_solid_type, ref aTag);! w: g" Y/ e# _# f, s# l
      if (aTag == Tag.Null) break;0 @5 T1 W$ ]5 F, w# {5 j
      theUFSession.Obj.AskTypeAndSubtype(aTag, out type, out subtype);
1 h3 z3 r0 }( u: g
& ~( l, x+ V" N8 m! m1 m

6 z( A5 Q. x- B/ C, ~* B& v6 n+ {      if (subtype == UFConstants.UF_solid_body_subtype)+ V, p( f# c. j9 j, h4 Y; d: R
      {
) c# i- C% p1 t# y4 O4 }        Body obj = (Body)theSession.GetObjectManager().GetTaggedObject(aTag);
4 J! V, ^4 Q* @7 V. d  a        if (obj is Body) theBodies.Add(obj);
3 ^' Q5 y6 O. @2 ?$ d' R      }
# |, G* j7 k. i* [. a: q8 l    } while (true);4 X! I9 w  N" {" z" d; H. M* k

! X  Z& i5 C+ A2 f3 R) S# l, O8 L; Q

% g% h% a2 [" j  O. T    theLW.WriteLine("Bodies in the list: " + theBodies.Count.ToString());" q  _2 n' g* v+ |. z
    foreach( Body theBody in theBodies )
4 \; T8 c; {% x4 U1 _" s    {
, w  p2 T# y! Z" t0 T6 s/ y      if (theBody.IsOccurrence)
7 q2 c" Z" c+ j' n8 {        theLW.WriteLine(String.Format("Body: {0}, Layer: {1}, IsOccurrence: {2}, Component: {3}",
. M  D% t7 D5 h0 D: |! A          theBody.ToString(), theBody.Layer, theBody.IsOccurrence, theBody.OwningComponent.DisplayName));
9 E9 x5 l* n7 c1 ^: u' ^! q8 P      else3 s! E& d! H8 [  ?( W) ?) I$ y) v+ }3 W2 I
        theLW.WriteLine(String.Format("Body: {0}, Layer: {1}, IsOccurrence: {2}, Part: {3}",
, Y9 f, i% {2 Y2 k          theBody.ToString(), theBody.Layer, theBody.IsOccurrence, theBody.OwningPart.Leaf));
  h; B5 }$ I, f' h. y    }
- z$ F4 E) x; ?1 h8 N  }
; E' `: y0 _# I; B! I}
/ i: I, R: ~1 T: u0 o# a% Y7 j5 x. P( J, O8 J" S2 D$ f
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了