|
using System; # C! V8 k. t: E! X9 M; t
using System.Collections; ' j [; P/ g6 H' _; n o, F
using System.Collections.Generic;
0 v: k& q3 K }7 X0 ~- i: x' k2 d7 h" P( q8 q8 K# x, H g8 e2 B
using NXOpen;
$ m. s; i4 X9 X; ~using NXOpen.UF;
, Q' Z9 G8 H# P2 _using NXOpen.Utilities;
+ L$ k2 p, y# I3 C# H) y/ Y& qusing NXOpen.Features;
- r* D7 v" s' i* b' o$ vusing NXOpenUI; 4 K6 y3 l. L0 O- {) |2 K
8 P' u/ V8 O0 r2 _; Y- C. ~namespace Get_Solid_count
2 X2 o0 _ V* E{
* G3 Y# I* A- {, {* C/ J# Y public class MyClass
$ ?# F9 `0 P4 g8 J0 o {
n7 c" A$ Q& b private static Session theSession;
, ?2 Z s/ ~/ _, X! q9 d private static UI theUI; 8 M9 O2 a5 H3 G. p8 Y& @4 i- R& k
private static UFSession theUF; # i* k1 a4 T3 Z- k) T Z
private static ListingWindow lw;
* e$ Z% \( W) u" b4 s5 ? K* b private static NXMessageBox MessageBox;
, }4 m- v/ ^: p
% P! [, G( I' H s, L9 V0 | public static int Main(string[] args) // 入口函数
- [6 F! D0 n7 H {
; ~/ J5 l: a5 T2 k; [/ u; G" r- J! h+ `% K+ P" M' { P" o
theSession = Session.GetSession();
) T: d. w' a# t# L theUI = UI.GetUI();
* j* V" W- h0 O ` theUF = UFSession.GetUFSession(); ; C; v U4 _9 v/ {5 p3 X7 |# |
3 |3 ]- z1 E+ s9 ?6 h. P& ]
lw = theSession.ListingWindow; # I6 T$ a. u% V. I* }) L! f
' t& @! [& ?/ C1 ]' q. T
MessageBox = theUI.NXMessageBox;
+ t9 _4 k" m! V9 [6 i6 l+ H% |& N- K) W' Z
UFModl ufmodl = theUF.Modl; 0 r$ M6 _ _$ |# K, b5 g
UFObj ufo = theUF.Obj;
, c% q1 V! L% B. H: M3 q$ \& v* J UFUi ufui = theUF.Ui;
8 H' Y$ V( p+ {9 H b
. @3 S O) p4 V3 ~6 _! ^9 W# t7 | int retValue = 0; : t- V- o5 i, |' {. [+ I2 n; f
try @3 F( A! W: h
{
+ v- o0 ~+ `" [' A ArrayList BodyTags = new ArrayList(); ' G6 r. P5 e3 m. Z- e- X; F8 F. n
3 _2 `# a. D' g% v, a; d1 \' l int numberclipped = 0, / B* \( G9 D. D7 @- W6 F
numbervisible = 0,
5 A3 q( t- [$ n' F1 v type = 0, / H& t% i8 H" c
subtype = 0, , R1 Y ]7 Y. k' s, U
i = 0, j = 0, 7 f! k1 Q n1 D
bodytype = 0;
& \' U* I( n( o- K0 U //====================================================================== 6 C. S! b8 y$ [5 e, l
// 获取文件中实体的数量
- h. f: N+ Q" t6 \+ t$ j+ z& w* ^9 U' r- X, c
NXOpen.Tag[] VisibleObjects; & w0 F, E5 I/ _, q( F) V
" r7 m; W- q1 S
NXOpen.Tag[] ClippedObjects;
) ]6 O7 l1 }) G8 h u
# z1 ?: x0 l3 l$ C // 只能获取显示的实体的数量
# j5 J7 H! \" m6 {" X* X/ ^: m theUF.View.AskVisibleObjects(NXOpen.Tag.Null, out numbervisible, out VisibleObjects, out numberclipped, out ClippedObjects); q8 v6 e; G/ H' {! ?6 w: P: R5 [
$ q( _3 Q: H7 e0 K
lw.Open();
7 i* P: s2 w, _' a# {% u
- S5 o+ S0 Z4 @1 ~ foreach (NXOpen.Tag aTag in VisibleObjects) % |7 Y) r, [3 s0 I ~
{
[; J; g, ~6 v) y4 Y theUF.Obj.AskTypeAndSubtype(aTag, out type, out subtype); : U0 L: q- [5 Q: p
: R& \0 N7 Q. Z0 F
if (type == UFConstants.UF_solid_type && subtype == UFConstants.UF_solid_body_subtype) ! O8 {% X9 g6 U) i
{ 5 V! U) a" H% z* ^$ H. s9 G
ufmodl.AskBodyType(aTag, out bodytype); // 使用UF命令进一步判断
) {( a3 Z7 @* l$ Y3 @- C2 k
- v+ |- K K, N+ ^9 @0 h if(bodytype == UFConstants.UF_MODL_SOLID_BODY) : o, W1 a- J! r1 v& U* {
{
- e6 Y( d0 T9 n# ~( F i++;
Z8 _7 {5 E. i6 |$ x1 H if(j > 215)
0 S* q8 e- b8 }; i- w4 h { & x. Z, ^, M5 C' l5 |" f
j = 0; ( e* H8 q% h+ f% G
}
2 _/ h6 W- t4 s7 j6 w8 H ufo.SetColor(aTag, ++j);
% ]4 c6 g6 G2 y ufo.SetTranslucency(aTag, 50);
2 C; {+ m# h0 ]) q: [" _2 I5 K, ~- L$ L
Body aBody = (Body)NXObjectManager.Get(aTag);
; W( u" V1 v2 l' x+ c8 m, Y' I$ y7 d* |/ p; W5 {* b
BodyTags.Add(aBody.Tag);
: |8 G8 {+ l( A+ R$ ` X" s# [
c* u( T+ ^& z6 }, g9 H ufo.SetColor(aTag, 150);
. ?7 }6 i& t6 x A* J/ w4 R
7 i% w: }: n% N% O$ a7 ?* X } " x) E# ?5 b- m9 S2 Q3 W( f6 K6 }. s
} / ]9 T7 R' z' A9 x6 }
} ! v( ^! T% _8 G8 g Z
' C2 O/ y; X8 H, A ufui.DisplayMessage("Found visible bodies: " + BodyTags.Count.ToString(), 1); / c; p1 d3 s( C8 v/ S# `5 c
! |! D' m" C u% {8 {( C/ W
//=======================================================================================
, r3 S: r; A( m- L5 I5 E! L) G# Z! P- z; S6 s" @4 X. q- P1 m
Part dispPart = theSession.Parts.Display;
. a- b( X$ n0 d# x' i5 B' h" P Tag Ntag = default(Tag); 2 f3 P" Y6 X. ^3 _$ ~
' f0 t6 r j3 F5 j _! L: J Tag ftag = Ntag; ! B& O$ a3 Q0 d; A' z" T' Y
i = 0; & I U$ P+ ^+ {5 U' U( ^
j = 0; 0 T4 U* T, }$ ?& ^+ |4 {- Q; Q
$ n# y# }2 y3 e$ J `( m2 i
// 获取文件中包含的实体的数量 . _5 E. A7 g$ s9 X8 y; Q5 f( A1 d
do & j2 r4 }; f' }' ?
{
: l) `2 u& v# }6 g ftag = ufo.CycleAll(dispPart.Tag, ftag); 5 U6 g4 L4 P( [ y* y$ e4 d0 ]
5 D' U+ w1 J, _! A( I1 {) q if(ftag != Ntag) 7 F, ]# z9 o: Z: N! K: A6 Q
{ ! y0 v8 M( ^# Y: V
ufo.AskTypeAndSubtype(ftag, out type, out subtype); ) G: s" Z8 X1 Q0 B3 {+ x }" `
2 [& Y' K( t' C4 \ f0 I! Y# _ if (type == UFConstants.UF_solid_type && subtype == UFConstants.UF_solid_body_subtype) S3 l4 s- X0 W* | f
{ : @; g4 X7 f2 I
ufmodl.AskBodyType(ftag, out bodytype); // 使用UF命令进一步判断 ! h+ M( P2 d- Y8 e5 K9 `1 {9 z" f+ h
0 `. y, l( N* C+ s4 E6 A) Q
if(bodytype == UFConstants.UF_MODL_SOLID_BODY) ! W% x& L) j4 | Q0 |
{ ) } B* u$ w0 }( `2 L/ R
i++; ( @3 n' J$ |2 r2 t3 ]9 J
: J5 Y6 Z7 r% L0 V
if(j > 215)
3 F ^& R3 V& A2 _. v7 v { 3 h6 J: r* k$ C6 t# A
j = 0;
) s3 @- j( E; V. Q; a1 i8 R } ! V% {' U0 Z) [6 F# t
ufo.SetColor(ftag, ++j); // 最大的颜色 216 ! [( z \$ \8 i; E; ~% D. r; n+ l
ufo.SetTranslucency(ftag, 90); , n! b6 @! L4 L9 y
}
1 O6 Y$ H. C7 O8 Q" G }
* D% v6 {5 z; e; b) P, f9 e- @ } 8 y& s/ L4 D. A% f4 G- M5 X% ^
% N4 N7 e8 }* r1 G- {
} 8 U, n: {# T2 v1 t X% S9 E
while(ftag != Ntag);
( Q' [) H% I9 E6 ]* O) s' v4 N! F2 T" u4 B' B* R% B! K, d* ~
ufui.SetPrompt("Hello ,You are welcome to CHIAN!,Please input Length,Width,Hiag"); // 提示行
3 t$ s9 I, q6 ]. P: f ufui.SetStatus("Input value ing"); // 状态行 # d- Y# F# F+ w) S) U8 `5 m
) A, a- x8 M6 q0 m
ufui.DisplayMessage(dispPart.FullPath + " have bodies count is : " + i, 1); // uc1601 1 _2 ?: V9 G& U, h W; U
} - w( F( n7 V e( _2 h
( D7 s; z/ R7 Q1 r: g1 J- X catch (NXOpen.NXException ex) - L) q+ n1 l# |
{ 6 E/ d, W2 F+ `0 G
UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message); / D+ i! Q e' d+ R
}
/ t0 t& R; W7 H return retValue;
6 O# s* X! s7 d+ |7 t }
9 ?0 E, s' A( A9 T0 j: l4 Z" z r2 h6 Y- w* k6 c, H
public static int GetUnloadOption(string arg) ) v6 y) k1 t4 A2 Q) E
{
" p7 F& `- ]- S& n2 Y return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately); 4 [$ E- ^, e$ g! N' F3 N/ H
} 8 d& Q- T I5 N3 f
} + M& P3 P; ?# Y
}
1 C6 y, A+ G9 M0 q7 T6 S7 t3 P+ e/ `2 j/ E7 P0 F: M
//可直接调试运行+ L2 H4 d7 y- k! H' L1 S8 L- G
//仅供学习交流! ! (smthan@163.com) |
|