|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
( L- Q1 S, O% }. L2 C8 `, d' d
NX二次开放源码分享: 获取装配下所有的实体
( i/ |0 j$ m1 Q
& [* a: Y- A3 z* e8 Q
) O( {+ o% y4 R2 U( T; d7 \: f1 a$ ?6 G0 X( F! G
public class report_all_bodies_in_assembly_level
b; Q5 [1 y! i8 j( l' g9 t! D{
% B& s. k' T5 w7 \- ~3 z7 s public static void Main(string[] args)
8 [, V* p, c7 y+ _+ ~% a {
' o+ `7 i" e- i- X4 B: R- r Session theSession = Session.GetSession();3 h/ l( D# ^/ p$ p% i% Y7 U5 p0 v
UFSession theUFSession = UFSession.GetUFSession();
7 Q! y' E' [" q8 i. i! f! m ListingWindow theLW = theSession.ListingWindow;
: F, H% G# c# B$ v8 g2 p( a
: v% i8 Y Z {$ b
1 z4 O' `* ^3 z) U Part theDispPart = theSession.Parts.Display;8 ~3 N1 @" A* X9 J
List<Body> theBodies = new List<Body>();0 k9 i5 G* B+ O: ^
Tag aTag = Tag.Null;. k( L$ h. w$ ?( ?& g
int type = 0, subtype = 0;
- ]) E( ^9 }* Q; L& b8 ]) c& o( [5 E& F1 d5 E" f
. g# T& ~: n; \4 \7 X; {
theLW.Open();
1 l: V& I8 w" ^ do
7 U6 s9 A8 q9 B6 f c- ] {
- z6 [+ M) I+ S theUFSession.Obj.CycleObjsInPart(theDispPart.Tag, UFConstants.UF_solid_type, ref aTag);8 w. ]) {8 U: W" l9 w* b
if (aTag == Tag.Null) break;$ C3 W8 c9 _+ M/ M
theUFSession.Obj.AskTypeAndSubtype(aTag, out type, out subtype);8 L! l1 }. C u& ?4 o
1 b( M8 V3 e4 A6 t7 W, E
! P( W& V+ C$ O if (subtype == UFConstants.UF_solid_body_subtype). ~3 O0 R4 o$ E, R3 N5 x0 c
{
& t( g; Z1 S z3 `* Q0 E2 X Body obj = (Body)theSession.GetObjectManager().GetTaggedObject(aTag);
; Q2 W+ X" ~6 ^( ?4 ? if (obj is Body) theBodies.Add(obj);$ e8 Q& C1 Y* a- {4 p
}. Z- \- [3 \# J8 R$ Y
} while (true);
. S6 ?% @' i1 |% T9 `# ^" i/ X1 u0 |# j$ p7 e4 p: o
# F' @: M' l: F- |! Z k- u4 f* q
theLW.WriteLine("Bodies in the list: " + theBodies.Count.ToString());/ U* H8 y$ S8 e( |
foreach( Body theBody in theBodies )
; G- {/ @3 U0 ?9 P6 w& h' z# {( k) N {
/ e$ J- \* A5 c2 `6 Q7 W if (theBody.IsOccurrence)
' X+ x; F3 _5 o: i1 {7 ?: e8 b theLW.WriteLine(String.Format("Body: {0}, Layer: {1}, IsOccurrence: {2}, Component: {3}",; y+ S2 Q+ J) i U' |
theBody.ToString(), theBody.Layer, theBody.IsOccurrence, theBody.OwningComponent.DisplayName));
" W9 _4 V* B9 Y' r else. W) w5 z& {9 q/ P, y2 e* j
theLW.WriteLine(String.Format("Body: {0}, Layer: {1}, IsOccurrence: {2}, Part: {3}",
2 [8 V% e; x0 z& J( ]8 ]# M theBody.ToString(), theBody.Layer, theBody.IsOccurrence, theBody.OwningPart.Leaf));& n/ u! K: J% q" u
}# @2 W, \( h( ]4 ~
}
* Y+ F- s, A2 M1 F" Y, |+ Y2 _' E: U}/ G4 a, ?: F9 `6 W1 K: Y
6 A# q: R# b. W0 p% `- d4 q2 H |
|