PLM之家PLMHome-工业软件践行者

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

[复制链接]

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

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

积分
82162
QQ
发表于 2018-7-27 10:56:17 | 显示全部楼层 |阅读模式

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

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

x
& h# B0 h5 S( m, h1 V5 k$ M2 c% v
NX二次开放源码分享: 获取装配下所有的实体$ s% Q  E2 N# B' O6 l
; q+ G9 W' _2 y. Y- A

; {5 i$ |( y- y1 L: s( H7 D. T7 _% T. B3 ~* }* u$ y
public class report_all_bodies_in_assembly_level
4 z% j8 |+ [0 `! Q& E  j  B/ \{' U% R, c5 z; r! M. X7 w" N
  public static void Main(string[] args)* _9 t4 A  n. h) ?
  {
- {* p5 e4 w# W: k2 S! _' Y    Session theSession = Session.GetSession();" w( s) ?  P7 U
    UFSession theUFSession = UFSession.GetUFSession();! u  ~0 b$ c8 H0 e% l
    ListingWindow theLW = theSession.ListingWindow;
; b; _! f1 w' @2 y" T6 e3 Q
. b! m/ R* D" J% p3 s

1 S, B/ P+ ?- M7 t7 s    Part theDispPart = theSession.Parts.Display;
/ `6 p$ I' e! G; y2 n/ ]9 h( i9 p    List<Body> theBodies = new List<Body>();: k* W2 o# ]' V; l2 ], O1 {( O( {
    Tag aTag = Tag.Null;2 c9 W1 z/ y4 D/ D0 B
    int type = 0, subtype = 0;
- V0 h% v3 P* f, }  a+ [& x
: o" l/ [0 E% ?+ m
6 o4 y; M* H# T( V% p& z
    theLW.Open();
% a% ^- q; ]- {1 G8 L4 P    do
4 _) q. @: y& u7 i' U    {' W' C% S, q( C1 B; e! ?  Q4 X
      theUFSession.Obj.CycleObjsInPart(theDispPart.Tag, UFConstants.UF_solid_type, ref aTag);
" }4 m4 _! x0 m      if (aTag == Tag.Null) break;5 R& a% P: ~+ s% H
      theUFSession.Obj.AskTypeAndSubtype(aTag, out type, out subtype);; `) }9 P2 I- D8 _" [

/ D, L& @" }1 ~2 }" \

0 F  v+ ^. P) u4 T8 m      if (subtype == UFConstants.UF_solid_body_subtype)
1 b! h/ T" Q8 ~! Q: L: h      {
# C. V; t  @& `        Body obj = (Body)theSession.GetObjectManager().GetTaggedObject(aTag);; \. r) L1 j/ c9 v0 C, {
        if (obj is Body) theBodies.Add(obj);
" k$ d0 C. r- D7 J6 w      }( d5 z9 y) S0 z6 g: A2 M
    } while (true);
# D1 s5 P; G  S& j/ \8 l; K# e' U

' A( A4 [: Y  M) R' u    theLW.WriteLine("Bodies in the list: " + theBodies.Count.ToString());/ Q, ?+ u7 M4 |- R% H  r/ i
    foreach( Body theBody in theBodies )% g" f+ v/ E! S
    {
! G; Q5 J) |) Q$ o0 a) X& p0 w      if (theBody.IsOccurrence)
: m+ ]9 c  ?$ ]1 _        theLW.WriteLine(String.Format("Body: {0}, Layer: {1}, IsOccurrence: {2}, Component: {3}",! p5 w& `$ J- s* a! w
          theBody.ToString(), theBody.Layer, theBody.IsOccurrence, theBody.OwningComponent.DisplayName));
9 _& \  N, Z7 q5 ]8 d7 X2 {      else
" a, J5 M# m- C$ s        theLW.WriteLine(String.Format("Body: {0}, Layer: {1}, IsOccurrence: {2}, Part: {3}",
0 x2 o0 ?  D1 m* ^6 c! L: `          theBody.ToString(), theBody.Layer, theBody.IsOccurrence, theBody.OwningPart.Leaf));% T4 R5 ?$ g) m0 G1 s' F0 k: T
    }& K/ l: X, l& l( m
  }2 p+ x0 ^+ b/ R" i8 Y6 {4 ~
}* ~: c& k1 f/ C  \1 i+ _
8 `/ I" v* v4 D2 N" K9 s
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了