|
using System;
3 o0 {2 y" _0 y% Ousing System.Collections;
) A' ~2 N7 |( w9 W9 c3 wusing System.Collections.Generic;
) r" f( @1 `5 L4 l, s6 }7 E
) a, w7 d9 {0 f: B# p( \, Qusing NXOpen; 3 _) T. t7 S+ w/ L
using NXOpen.UF;
% x0 ~1 Y1 h( E" | rusing NXOpen.Utilities; ; R$ W" X5 I ^2 B2 t
using NXOpen.Features;
& j3 s4 _% G, E+ k; kusing NXOpenUI; - B: R. [0 J% B1 T# e
j3 ]) X- {7 c7 q: n
namespace Get_Solid_count ( I* o" A; l0 X9 s/ o
{
2 A. Z6 J) f: \9 Z public class MyClass
! e' n( E- r; U1 n+ |, N K { : t2 a+ ` W6 t/ K
private static Session theSession;
& A7 ^! M4 a' t1 U# R* m$ }. f private static UI theUI; + I+ U* m# @+ D
private static UFSession theUF;
2 w8 _9 ?, U8 s, d- F( Z; {1 m3 d* v private static ListingWindow lw; / }/ V: u, H" ^, F. N+ g: v
private static NXMessageBox MessageBox; " m7 [# b0 h" U: l
I: B$ k% W, W' o9 u. w/ I, L
public static int Main(string[] args) // 入口函数 # _$ W+ T+ r9 G6 u7 ?& W C2 x' q2 J; B
{
- E% D) i' K1 R4 s3 d. ]3 V& V. C T. c3 b: h3 U7 V
theSession = Session.GetSession(); , R8 E* [- k& v' \9 W
theUI = UI.GetUI();
8 R6 U. w7 E5 A; q0 M1 ~& w theUF = UFSession.GetUFSession(); 5 g% _: v% B D/ u5 k
8 ]* w7 w/ q. z; B6 T lw = theSession.ListingWindow;
# U2 A- h. q' R) a- s; D% e
+ M: d3 g* M$ N' m' w* Z; P MessageBox = theUI.NXMessageBox; 4 q" \1 w# F- t; y/ i) }. L
& h/ j: ~7 ?4 g8 l
UFModl ufmodl = theUF.Modl; ' s$ u! N( Q9 T5 @, ~5 n& `# S
UFObj ufo = theUF.Obj; 2 `2 N* f: K( C7 i0 m
UFUi ufui = theUF.Ui;
8 v5 h: w7 S& ]8 H6 a$ F. z* H% Y( s
! [& I5 @1 t8 { int retValue = 0;
( L E' U$ w8 w& F6 C try
' U. o; `. Z! e! P {
- Q7 s H5 o! o$ s: }6 z! H ArrayList BodyTags = new ArrayList(); " u5 V' Q# f7 F9 o+ `' j& w
% w0 r2 `$ h( O. }5 a6 b% ` int numberclipped = 0, 4 d$ z/ }( Y+ W/ b8 I$ K( } U9 Y3 U
numbervisible = 0, k$ [$ Q) _, V1 E
type = 0, - B: w6 ~1 f# p+ a7 c0 x1 c
subtype = 0,
. d5 V/ w+ S, _ i = 0, j = 0, 3 ]* T; j2 A3 j0 E
bodytype = 0; # W. v7 |0 Z* n% _/ S7 K( N# c" u
//====================================================================== , N6 ~' W" Z2 s& v4 b4 }1 B
// 获取文件中实体的数量
8 r0 d+ z" u# p7 R+ i- l* R
. q X% a4 g. z2 j: g9 U6 h NXOpen.Tag[] VisibleObjects; $ f& d& w0 |3 X" K. ^: r
; _: O) I' O/ s$ j' U) x0 C0 M
NXOpen.Tag[] ClippedObjects;
) [# u/ p; l/ Q3 S. `
1 O; Z! N' r: Z9 h. i; v/ g, e // 只能获取显示的实体的数量
% ^9 O. r: G7 u/ W2 h; U$ G/ c( U theUF.View.AskVisibleObjects(NXOpen.Tag.Null, out numbervisible, out VisibleObjects, out numberclipped, out ClippedObjects);
& c Z; _! M3 B5 {/ V, C: p% q& G3 G: E: R
lw.Open();
8 U- B N; m+ h7 I- ]8 ^" @
0 {' @+ a( P" p# _8 Q; E foreach (NXOpen.Tag aTag in VisibleObjects)
+ c5 u+ ~* M5 c! n { ( _/ D6 d! \% r( u
theUF.Obj.AskTypeAndSubtype(aTag, out type, out subtype); 0 }$ }- B; W, r
. b% @; F$ H6 T4 ~ i3 Z6 I Q
if (type == UFConstants.UF_solid_type && subtype == UFConstants.UF_solid_body_subtype) 5 z$ B' F: N& d& ^
{ ' P) y* n- X* K( l* n9 C; c$ p
ufmodl.AskBodyType(aTag, out bodytype); // 使用UF命令进一步判断
# Z& L7 F8 }: {# ?! i, U
\3 z. b8 @# ^6 i! i) g9 _ if(bodytype == UFConstants.UF_MODL_SOLID_BODY)
! r- j1 ~( Y1 R; V; H- Z { }! ?, u/ f9 p& j
i++; * N2 b p O0 D" s- J b
if(j > 215) * y, V( b+ S: z- M
{ ' I* z; X2 p8 F0 b3 w7 w
j = 0; 0 ]# p. i) U2 e
} : { k4 X$ o/ T5 M5 F: x
ufo.SetColor(aTag, ++j); 2 g7 W; z5 j$ A0 E. [; v
ufo.SetTranslucency(aTag, 50);
( ]* L. h$ n6 N& c3 K( |5 o0 l( w& R! ?- D
Body aBody = (Body)NXObjectManager.Get(aTag); 2 e; I& Z* n, ^7 {1 J
" p& W1 G0 y; I$ s7 {: t8 d BodyTags.Add(aBody.Tag); . `) H/ M; s5 D, A3 n
* w: U% H( o9 v& i% B1 V ufo.SetColor(aTag, 150); 2 g1 i7 e1 l8 S3 s M
9 J3 Z# X! ? a
}
+ e% H& X1 S' K9 O1 G }
+ d& D; n) h+ R" ^1 g0 W } 2 u {1 S, p3 L* i1 i3 L5 |
6 J1 M" e9 ?9 N6 c
ufui.DisplayMessage("Found visible bodies: " + BodyTags.Count.ToString(), 1); + H& C' U/ b7 [3 m- `0 A% t2 }# w9 E
2 B9 Y0 `- N1 c3 }1 n" \ //=======================================================================================
0 i) [! V) u4 w/ g: s, _1 u
8 `* p# }4 ?, n" l8 o( J+ W# z Part dispPart = theSession.Parts.Display;
; y$ v! {6 v6 s3 S Tag Ntag = default(Tag);
& m4 u- [" d2 Y) h/ G [* \( ~) Z8 N P2 L2 D$ X
Tag ftag = Ntag; ( c7 z3 ~& b/ _; R0 e
i = 0;
6 h- ]5 v2 b; M% t3 p5 N# y) z j = 0; * C8 I# u/ V* C& B0 w. u+ E4 C
# w2 W) k3 Y9 |. i% p, z" e // 获取文件中包含的实体的数量 4 C* ?/ a9 m; E/ t/ y# ]9 u
do
2 i9 u& _( b, u3 Y+ {/ \" Y% \1 k { 3 r8 L9 H8 z( b* v6 T
ftag = ufo.CycleAll(dispPart.Tag, ftag);
& d# ?+ M- _+ ^
/ \$ L0 K9 d; c1 e/ b2 u i if(ftag != Ntag) ! _1 E8 J7 S" y
{
( _! r7 \. b' H& ? ufo.AskTypeAndSubtype(ftag, out type, out subtype); 7 s0 `; z# D' K& s! ~
+ B E+ u- J- S4 L
if (type == UFConstants.UF_solid_type && subtype == UFConstants.UF_solid_body_subtype) : V3 n; _4 M, M, e, l
{ / \. L9 B( \& Q" q7 y' g
ufmodl.AskBodyType(ftag, out bodytype); // 使用UF命令进一步判断
/ e9 [% F* L* _% M5 H8 G7 j, U. K" E' _+ N% E9 c G
if(bodytype == UFConstants.UF_MODL_SOLID_BODY) ' t% x& l0 j; H, P' K
{
4 s5 a$ }+ |: @4 z5 J0 I i++;
, y! E4 I8 ]' ^/ M, i5 G
) S( N6 P0 r% B/ ]9 {( @, i! G if(j > 215) 6 a) f* M6 P, t$ Y5 W
{
1 t6 L$ m' k- l. C2 C, q& v j = 0;
, @. \: g+ f% K* Y7 S5 ^ u }
! a0 Z& R0 M5 E' \6 w' |. ] ufo.SetColor(ftag, ++j); // 最大的颜色 216 / I2 r |( q+ k/ n! g1 @. I1 B
ufo.SetTranslucency(ftag, 90);
$ F, w2 y: f8 i+ B! s, |3 @ _; j } ! E# ?! Q- c3 O, G1 m
} , l# o5 i+ Q7 T" b6 s. ?
}
& T& b% C; J; B( u+ a$ i1 d' w5 x* H2 P
} ! T6 a# }& N+ U0 ?, A
while(ftag != Ntag); & Q2 ]- ~* I' S( K0 [/ D
# }5 V9 R. H* o3 R) G: Y6 _ ufui.SetPrompt("Hello ,You are welcome to CHIAN!,Please input Length,Width,Hiag"); // 提示行
7 [ q; I4 q$ j! r8 o; ]% D+ j6 u ufui.SetStatus("Input value ing"); // 状态行
, Y- p$ l1 i7 h- B/ q; y4 B6 p1 l
ufui.DisplayMessage(dispPart.FullPath + " have bodies count is : " + i, 1); // uc1601 , T, i2 s S% X( H8 q" ^# t
}
8 `; \1 ^" r' d) y' Q
4 A7 W0 U' h/ N* M+ N7 O catch (NXOpen.NXException ex)
8 N+ P; y2 A+ s) U) k, l {
. X- y1 _" ?0 Z! X+ W UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
) N# P C+ n* q: b } # t8 p1 k; { _! t3 D
return retValue; 1 E @! B W! y/ @+ v7 h
} 6 l9 j! M. |$ d. ?9 {& w7 O
+ I6 d$ L# e7 u t3 s3 {
public static int GetUnloadOption(string arg)
, J8 b8 K S+ S# ?. [ { - X6 t8 z& o( A7 K# H/ C
return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately); 3 Z) @2 _8 j$ a4 f( j, J9 ~% K
}
H5 B( D. E' d3 z4 u' X } % j) n0 a' k; ?* k& G, g) k& r
} ) k# `; j; P/ |1 [% Z$ r: i; T
4 `- R7 W0 _; {# U s3 K# Y1 i9 ]
//可直接调试运行
" w- o) Z" A' Z o2 e//仅供学习交流! ! (smthan@163.com) |
|