|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
" P- v! I- s/ |0 _+ B% U* N# nNX二次开放源码分享: 获取装配下所有的实体
5 I. Z$ s$ q9 `6 p7 K* L+ T% r" v# s2 O6 K7 N
1 `- f% P5 R/ C$ Y6 V4 P ~/ k1 t) q" |/ I9 k: Z( k
public class report_all_bodies_in_assembly_level, L5 o" N6 M. Q) p) H/ U. Y
{% ]9 K3 ]/ y4 W& x" f. ]2 ^
public static void Main(string[] args)( t& p" [/ n" ?( C4 u
{ N" A4 Z6 f( V- `5 _& J: j" Z( `8 P& K
Session theSession = Session.GetSession();9 |' S& V3 h- h2 i
UFSession theUFSession = UFSession.GetUFSession();
& }* A( |5 E/ G" t" o ListingWindow theLW = theSession.ListingWindow;- q5 k4 g7 O6 @. C
2 J, J5 t, N; A0 r! Z" i9 a- g, x, t
Part theDispPart = theSession.Parts.Display;$ ~' T4 H4 i$ r& i2 c
List<Body> theBodies = new List<Body>();. X, T: k# Q& o; }
Tag aTag = Tag.Null;5 n; ^* }) ^) L; p$ R) R$ p
int type = 0, subtype = 0;
6 @2 `1 u9 H% [1 J9 t/ g$ ]: ^# f2 c6 U/ Y
2 d% {/ b. X8 W0 O% p& R; `/ y theLW.Open(); v# A) V( |& ?: \- X: X4 Z
do( ~" r, m+ {/ C; E% E! e8 G
{
' b) B! q/ ~* _ H5 A+ x; Q theUFSession.Obj.CycleObjsInPart(theDispPart.Tag, UFConstants.UF_solid_type, ref aTag);6 x; S7 } ^4 O/ x
if (aTag == Tag.Null) break; w6 s; O5 v. c# P9 X7 Z
theUFSession.Obj.AskTypeAndSubtype(aTag, out type, out subtype);
: s) r* d3 g' @4 s6 ^, o8 E3 d( S( _" `8 S
4 ]: D* `% N9 E4 r( ~$ D5 p* l
if (subtype == UFConstants.UF_solid_body_subtype)% l9 Q, P! ] X2 A7 J
{2 E2 M9 g1 @8 M$ i. {+ |
Body obj = (Body)theSession.GetObjectManager().GetTaggedObject(aTag);
# @# F2 C9 v5 `; V; ?, R1 P if (obj is Body) theBodies.Add(obj); d, p8 x2 `: ~
}/ [1 ~7 g7 g9 L: B5 ~( i
} while (true);. }, y& j& l* L7 S1 J+ y; j2 D6 e$ i/ I
% W( e* O; o( ^, T4 X- n
6 O5 e. p2 }$ X3 ?4 o; f; K theLW.WriteLine("Bodies in the list: " + theBodies.Count.ToString());
& ?; f& D. W) D6 x- B$ ^5 _; a foreach( Body theBody in theBodies )+ E' J; ]8 R! g9 K
{! b( y0 q+ t. ^& y% \+ j
if (theBody.IsOccurrence)
% m/ Y+ d. F; |. w/ B8 x theLW.WriteLine(String.Format("Body: {0}, Layer: {1}, IsOccurrence: {2}, Component: {3}",
( d0 D% V2 ]5 _ theBody.ToString(), theBody.Layer, theBody.IsOccurrence, theBody.OwningComponent.DisplayName));
1 x3 ^* U5 S% `) ] else3 D* M* B9 }3 G0 Q. p) y7 r
theLW.WriteLine(String.Format("Body: {0}, Layer: {1}, IsOccurrence: {2}, Part: {3}",
) I) w5 {! m$ t0 N: |8 @/ K theBody.ToString(), theBody.Layer, theBody.IsOccurrence, theBody.OwningPart.Leaf));
& v; n8 x+ W: J9 w }+ ?0 U6 T8 |2 ~! u3 y) N2 L
}
5 L8 p+ a4 D; H; O! s( b}$ L$ P$ I8 p$ n0 z& ]6 m
' G3 i- u7 _5 M, F _
|
|