|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
; [# G; I. c2 p. j4 R
NX二次开放源码分享: 获取装配下所有的实体' [ I- H/ D: v/ J4 q: W" F, Q
* N* l( x- V& ?' @% S
, [' C* d# I. Y+ K, T8 R8 i
) V" _9 {6 } Q+ F0 y1 @- i& O) ~public class report_all_bodies_in_assembly_level# l0 [+ N i- q9 t( r3 I% r# I
{! Q' x F" k [: `0 B7 K7 j+ s6 L# H
public static void Main(string[] args)6 D* \" m- M6 U( H b, d* T( |1 v& \2 {
{
! @6 \. d) D9 \* g Session theSession = Session.GetSession();
1 t8 O0 t$ D5 G8 T& d- ^+ m: s UFSession theUFSession = UFSession.GetUFSession();5 c% r( n, I' `+ x, F9 r
ListingWindow theLW = theSession.ListingWindow;: ?' E+ N" t+ l6 a! O5 f4 H; q
% ?6 |1 K3 [/ A3 T' Y9 q8 t' }& g" d; X2 I0 M
Part theDispPart = theSession.Parts.Display;$ R: \4 J4 G+ S
List<Body> theBodies = new List<Body>();
% C H( |& d: _) S3 D0 ^4 B/ Q/ X- x Tag aTag = Tag.Null;
& }2 e( P0 O$ K H* j+ @ int type = 0, subtype = 0;, Y' J# \9 ?) s* ^; X
4 a. |* H2 |* v1 n0 C% p9 o" b9 G
5 B( k, m! n4 b: {* Y; T$ E theLW.Open();6 H( ?6 V' A# ]8 M% d: K
do0 a; c' X! |" D/ O6 a1 v+ P
{: B9 ?, O5 N9 f5 B: z# I
theUFSession.Obj.CycleObjsInPart(theDispPart.Tag, UFConstants.UF_solid_type, ref aTag);- ^# ]/ v5 u- E" Q3 i7 [
if (aTag == Tag.Null) break;
# W! }& E0 ~9 F. d/ c8 K# B; \2 y& \$ X theUFSession.Obj.AskTypeAndSubtype(aTag, out type, out subtype);
, g4 M3 [$ L9 S2 K6 z1 J( k( {
U& B" n: N4 a0 h8 C" o0 s
0 A, F: v- i, T1 ]1 F$ T& v if (subtype == UFConstants.UF_solid_body_subtype)
' n4 x3 y" h t( j {
$ a& W" d9 r" B. F3 H5 X, C Body obj = (Body)theSession.GetObjectManager().GetTaggedObject(aTag);6 g. M2 }- Q2 p; L# ~% f( U8 f" e
if (obj is Body) theBodies.Add(obj);7 ^8 U( k$ `4 n* W) ]4 a' [9 C
} D8 {7 o# k# K
} while (true);
0 Y7 u2 E7 W- V' t: o% J) _1 y! D! Z1 y0 M
9 B+ \( f& U" f% ~ theLW.WriteLine("Bodies in the list: " + theBodies.Count.ToString());
2 Q/ ~% N5 Q. R! L3 y! H4 e foreach( Body theBody in theBodies )
$ k0 @8 N: e# [" p- t {
2 {4 p# S$ I# N2 D if (theBody.IsOccurrence)& x& z" g. d5 B& w+ C
theLW.WriteLine(String.Format("Body: {0}, Layer: {1}, IsOccurrence: {2}, Component: {3}",1 Q; x4 L2 ?" y' a
theBody.ToString(), theBody.Layer, theBody.IsOccurrence, theBody.OwningComponent.DisplayName));% K& h% E" l$ E2 v# ]0 ^
else
, @2 Q# w% d! Q. V) B$ J; R" {4 G9 D0 A theLW.WriteLine(String.Format("Body: {0}, Layer: {1}, IsOccurrence: {2}, Part: {3}",6 J4 L5 s/ e+ O; T
theBody.ToString(), theBody.Layer, theBody.IsOccurrence, theBody.OwningPart.Leaf));
$ X) T0 y) p5 s9 u! ^" J }
) s5 ^6 z, A) g6 o* _8 u9 S5 s, u }; W. m, F% k9 L8 [3 @3 h$ x1 c
}) ? M6 D; J$ {! |9 O3 X9 B: h7 b& z, W
( m b' x* g l% b* C9 x |
|