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

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

[复制链接]

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

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

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

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

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

x
  m+ L% [/ I" K5 N4 `9 t& _
NX二次开放源码分享: 获取装配下所有的实体
4 L1 C6 m( Z6 a' t& j% T. i) @; W4 B; l. ]) V+ M8 L, [) `
7 j! E3 s0 C" h" R

& x0 Q9 u0 J' I! z  Hpublic class report_all_bodies_in_assembly_level0 ]- z' a! ]! q5 b' Q
{
, g3 z6 q/ t5 L4 Q3 _$ i. \- Z3 Y# T  public static void Main(string[] args)
2 ~# u9 j+ I4 D0 m  {
+ M/ p  L- d8 f9 @( {    Session theSession = Session.GetSession();8 v5 v3 ]7 o% e
    UFSession theUFSession = UFSession.GetUFSession();& k, x% k8 r% X8 w5 a9 q# z
    ListingWindow theLW = theSession.ListingWindow;
. H% t, c4 P# w$ z5 ]' b  M9 A# J

: l6 r- x( S7 v8 k    Part theDispPart = theSession.Parts.Display;
+ P' F8 T% p- Y6 a    List<Body> theBodies = new List<Body>();
3 |! M  D/ ?( p( o' S- G' w* D    Tag aTag = Tag.Null;2 z/ v& a" z- a7 C  ^
    int type = 0, subtype = 0;# v) j. X* u' J+ E5 k
! K1 J8 G; U! C0 u. g7 V

3 d$ e1 ~  N1 g1 p7 S& O' \1 e. ?# |8 }    theLW.Open();" V! l4 y( b$ t
    do
. b) h2 d+ F  P4 z    {, c- @# K/ s8 ]% U  U. o; l
      theUFSession.Obj.CycleObjsInPart(theDispPart.Tag, UFConstants.UF_solid_type, ref aTag);
/ m6 b, Z. M7 i  L6 M2 V* L4 @% V      if (aTag == Tag.Null) break;: h6 l; |. H( P9 i4 M$ i
      theUFSession.Obj.AskTypeAndSubtype(aTag, out type, out subtype);
6 j/ g8 y0 i  [, @& x$ O8 ^" ^/ |9 X" ^! d! ~4 b: s$ k

& f9 ^/ D' @* p0 E& b+ q      if (subtype == UFConstants.UF_solid_body_subtype)
6 {7 ~% ^5 B. k6 q      {( m7 L) r8 N1 t8 n" w
        Body obj = (Body)theSession.GetObjectManager().GetTaggedObject(aTag);
) R3 [1 G3 j5 P9 j: y9 l0 b        if (obj is Body) theBodies.Add(obj);
" `/ ]+ h( x% w      }
4 k6 @* v7 ^9 [* `+ M' x    } while (true);
  s4 S# `5 x4 l9 B$ c7 O
* ?( N; y1 w/ F/ D7 P$ R; I
* x  P, D' {3 U( E  N, h$ @  M9 z( X
    theLW.WriteLine("Bodies in the list: " + theBodies.Count.ToString());
" ~( ~6 t7 J$ `6 q& N- A; b3 h! B! \    foreach( Body theBody in theBodies )
& Z8 j, o( t; a4 S; J    {
) [& x! j. i( y6 m" e8 B      if (theBody.IsOccurrence)2 b- R9 f. n- \0 ]! y- X" G8 X9 y
        theLW.WriteLine(String.Format("Body: {0}, Layer: {1}, IsOccurrence: {2}, Component: {3}"," f' i+ x* ]( j7 e
          theBody.ToString(), theBody.Layer, theBody.IsOccurrence, theBody.OwningComponent.DisplayName));
8 e6 u! u+ [' U5 g4 n      else
- d2 h& u1 [( w$ V5 A; e        theLW.WriteLine(String.Format("Body: {0}, Layer: {1}, IsOccurrence: {2}, Part: {3}",6 u+ ]- l6 A; V  q3 X  Y; i: U  z  D
          theBody.ToString(), theBody.Layer, theBody.IsOccurrence, theBody.OwningPart.Leaf));
2 [" p6 d- j, l4 D! p2 s( \7 R    }
8 U: L* T  `: D  }4 p/ O$ u, m" D+ F* K
}6 J4 L" ?- S; Y9 C; Q. P% o0 h

. j, v! i9 b! p% O% J0 ~
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了