|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
; E6 c0 F2 A% `2 c3 H4 zNX二次开放源码分享: 获取装配下所有的实体, T, g8 R4 H" t" Y; X3 h3 P
7 [7 W1 T( i1 q# c# R
3 ~% [+ e/ u; `5 F2 Y! X3 g$ u6 g
& N w$ ]7 \9 G! I( a4 Bpublic class report_all_bodies_in_assembly_level: U1 Q R7 Q( C$ t% u. A |
{
& G( t2 K9 E& ?" N& f4 ^* O public static void Main(string[] args)
. [$ X: M2 K9 A {" [/ e, ~8 s+ ~7 y
Session theSession = Session.GetSession();
! \9 T, F* b9 v5 s: G; q UFSession theUFSession = UFSession.GetUFSession();
- O1 ]2 k1 V4 E4 p ListingWindow theLW = theSession.ListingWindow;6 n2 A2 a d4 @9 S- V4 E, I
" m, e6 N9 A' M( h7 M2 F: G: R- p$ R% K ^( S, `! M' T
Part theDispPart = theSession.Parts.Display;$ K0 w, J+ _& _- `8 ?( ^9 I7 [$ }+ {: X
List<Body> theBodies = new List<Body>();
" \% G! s T7 d0 T( h& h: e; P- D C Tag aTag = Tag.Null;
6 B, _7 W( @$ A int type = 0, subtype = 0;1 _+ H7 K; z: V; i& L' o1 F
5 t2 |' H+ a5 z, E5 B; V7 k% y) u+ h) c' x1 P6 C8 S# ]
theLW.Open();7 V7 W% A: z; A
do w/ P0 K& B4 _! T- B0 R
{
3 O' K* `8 P$ q& z theUFSession.Obj.CycleObjsInPart(theDispPart.Tag, UFConstants.UF_solid_type, ref aTag);9 c9 ~ R& ^& m; P! g5 M
if (aTag == Tag.Null) break;
; J' B8 D4 s* G theUFSession.Obj.AskTypeAndSubtype(aTag, out type, out subtype);
/ C+ r+ Q/ D% v* R( X
# A+ t- s% ], K: t" \! l" n" n
! f5 b* m0 M8 @ if (subtype == UFConstants.UF_solid_body_subtype)$ \* J# k B1 _3 Z# x
{
$ z3 Q/ P- {: c J" d3 V6 |1 _7 h Body obj = (Body)theSession.GetObjectManager().GetTaggedObject(aTag);
3 Y+ U4 I; S& R/ F3 d; B* E if (obj is Body) theBodies.Add(obj);$ r. e/ Q" S0 `: V' @3 v
} ]) x0 z6 \4 Y8 R( E- t
} while (true);
" U: X9 N) \- P6 \# V5 W2 B0 p( H& w" p9 G$ Y! @6 p
/ [! V6 `5 ~4 e# J0 q0 p theLW.WriteLine("Bodies in the list: " + theBodies.Count.ToString());) p1 N; p; H* z8 ` L
foreach( Body theBody in theBodies )* N3 p* a: w5 ~* H5 w
{' w1 Z* E0 V7 ^$ J V, A
if (theBody.IsOccurrence)' a7 }& P8 a4 b, U# a2 N& j
theLW.WriteLine(String.Format("Body: {0}, Layer: {1}, IsOccurrence: {2}, Component: {3}",
$ s6 a& i- _& o! n) \ theBody.ToString(), theBody.Layer, theBody.IsOccurrence, theBody.OwningComponent.DisplayName));
: k4 O! P* _* m) y5 f0 X0 c else
# k3 ^: r( f: s2 ` theLW.WriteLine(String.Format("Body: {0}, Layer: {1}, IsOccurrence: {2}, Part: {3}",% r$ b" u9 W0 d0 ~" P) _% s. e
theBody.ToString(), theBody.Layer, theBody.IsOccurrence, theBody.OwningPart.Leaf));+ `: b5 C$ o$ o+ _: S, O3 x" W! Q: I
}% K8 ]; f$ [4 f
}
$ Q, _' a" n, @4 S Y1 C}, G# F' n( Q# F4 [) Y; `
- F" z1 M6 h# \4 d+ |2 j |
|