|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
2 E+ {2 R3 X& J; ?# [
NXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值
& A( N5 }4 S) d" w5 E7 {6 f0 X" P# c4 N7 F
1 l" x1 C# P& ~3 U; ]4 W, W
static void do_it(void)
3 @( _9 W5 ~( @, g: b+ e+ v{ s0 }6 z$ B2 c+ m" _
logical is_initialized;) O& j% @# n5 K8 E* B* R5 I
int object_count;
6 J1 H0 C3 \1 M3 d$ O int type;
2 q" X$ P* I6 m0 M1 W int subtype;6 r6 n0 A' H% F; I M
tag_t *objects;+ h8 |2 J! H$ u! }/ t. c* f
. E% J5 O1 Q( r8 h' y7 c# e) ^6 f0 D& J
5 n @+ _" x# D+ d' F+ ]- ^8 ~: x' f
, ?, n; b8 L+ \6 P \ O char mesg[133];
' d$ f2 o @& S' {" ?+ S# v+ t R% u3 x- _
, q* |+ j7 _( `4 a // Get the work part
9 U' r' g8 I2 d: S: \% y Session *theSession = Session::GetSession();: h/ P- Z* O9 }9 m* p; A6 _& {) i
Part *workPart(theSession->Parts()->Work());2 y( C D, B5 k/ w/ @
Part *displayPart(theSession->Parts()->Display());9 T( e4 f/ Y$ T8 w
6 j2 ?/ t; [, J- @5 e# D
+ q1 y" a8 y& K& t3 P
6 U- _/ @2 g- t
+ D' U0 x' M3 a5 j- j% K if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;' N( {5 f/ U% W) w. p# F7 x
5 }5 [* D: X- x5 f4 }, C4 ~
! I# _3 L" s, k; b( F2 u
/* Get selected WORKPIECE object in ONT */6 U; ^! S9 Z! f6 v
UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));
0 m5 s1 b# P! G; ^/ J, f0 r$ d/ `, K$ g( Z7 ?: d, U
9 _# y' t$ U4 i: h2 K: l, i7 j7 x, T) l' ~+ B! e! n
( d% q% ^) S# ^; |8 W2 E( ~1 `
if (object_count == 1) {
$ s$ i% F% `2 c t* [7 U% {4 Z UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));
; W) s0 C* z3 U: ]! l- A5 ]# K" b5 `! ` O y' s" ?
$ j3 l# d ^" q5 E0 k* N% {, Y5 D0 v; s/ H
6 ~5 w3 z% f, Q8 y9 s3 _2 ^7 _! X
if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {$ [5 o+ j& }1 {0 X
% L0 O# W+ r R" M9 g* e* e7 [2 i- T- A: a
tag_t ObjectTag = NULL_TAG;( i; w% X' t: V# L0 H# u
/ S6 \0 J5 S7 x' P( T' {* s( H: u1 z! N1 k& m3 z0 o
// Get the object from the WORKPIECE tag9 C4 G# t% S7 O
CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);
\; c6 z6 [' e1 V: p
( V" T( ?; P- \. H0 U4 p# w: |3 `( p$ _) c
CAM::MillGeomBuilder *millGeomBuilder1;
, R8 y/ O7 a3 V H7 _* | millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);& X9 D0 J4 B% H. y# V6 C, v
) T( B" j- `) s4 f- D/ J
2 s j! G- r% P' |: y // Get geometry set list
) M+ w+ S! i# ~# F5 b CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();( b# J Q; N7 r# g# O
std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();
: x! o8 V7 O: Y j- X) X, n3 H/ t
5 w) b, K5 x2 F& d# [- b, Y
9 y' b, B- l8 @9 S! R // get geometry set
; |: L) C& R9 w# }+ I& o* X std::vector<CAM::GeometrySet*>::iterator iter;% ]- l1 K/ x6 ^; W) |
for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )# F6 B0 b- u' j3 m* w
{$ Z4 }' H/ l9 @2 |; Z l
CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);/ [& [) u, e) K3 n
ScCollector *scCollector = geomSet->ScCollector(); . t6 p" `: _+ Z+ y, v0 ?# {
std::vector<SelectionIntentRule*> rules;
" r* }. |5 R1 e scCollector->GetRules(rules);0 n& m+ ^) Q1 C% ?+ u$ c* }
$ _: |4 z( e L6 H9 Y* f
$ I, R% E1 I$ b, F
//get selection rule; |6 [9 |( S2 f; P1 N3 t
std::vector<SelectionIntentRule*>::iterator ruleIter;
4 Z# t. f' J# N; y ~3 X for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )# p) k* m+ G! ~+ r0 p
{
' e/ P, m F& B7 N SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);8 J$ V, v+ ~- H' i. o' k* ^$ d7 e
NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();. D0 k Q5 [0 N% i! g6 A6 H
//there are different rule types, here just use body, face as sample; @+ P& R' j( G: d0 x
switch ( ruleType )
/ b1 o# e' S2 J5 l+ U: k' a* h) V {2 P" s g1 X6 C7 Z4 W' m: e
case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:
7 a: j# d+ F2 Z {
9 a3 g- @: O1 a( c9 h F3 u7 t //get bodies
4 p: W8 p' c6 e: W+ Q) g# v NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);
' [7 }6 M# o$ t4 h8 D6 v; u std::vector<Body*> bodies;6 Y% z3 A+ {: m8 D u' b
bodyRule->GetData(bodies);* q4 v7 V- y( c0 w m ]$ J; |$ s/ A1 F( M
std::vector<Body*>::iterator bIter;
1 i" o3 a2 q! q, Y2 _ int index = 1;6 B9 g. p1 w6 ?. ?5 G
for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )3 D6 }4 I: S8 }/ Q& Y0 o( f8 I
{. A# g* j- Y; M8 v8 ~8 H
Body* body = dynamic_cast<Body*>(*bIter);( Q2 J7 m. e6 ?) T; y/ L+ h7 c; d$ o
ObjectTag = body->GetTag();. k0 U/ j3 L' M* |5 T! r+ f! A
sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag); 0 |6 F" t; j& P" s% K4 @- M
WRITE(mesg); ?; b6 J" n6 c. _, a
body->Highlight();
2 i8 m* [; I" `) ]/ Y* w index++;
2 d; r5 B- G6 ^0 k- }8 D }/ ~, H4 k2 \2 e
}! f) P4 o( D2 ]6 K% y" v. _3 d
break;2 ~4 P3 ?1 W7 `6 J0 {; ?( Q5 @
h4 @# ~- I8 U: B1 z
: L2 v o% T9 Z4 v5 b6 Z case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:& p1 x8 e6 G9 s: A
{
. x1 D# H ]* r8 S //get faces
( y* w' |. V! A5 @3 n" I/ V8 t NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);% n' v+ Y, w' x
std::vector<Face*> faces;
; a1 m8 Q1 i6 }- |/ ] faceRule->GetData(faces);
1 \# n: W- z: G+ @" `% ^ std::vector<Face*>::iterator fIter;1 X3 ]5 K5 g1 h; i
int index = 1;
7 M: h3 l. \/ X$ O+ \# e9 H for (fIter=faces.begin(); fIter!=faces.end(); fIter++ ): A! s, A& E9 T1 L
{
( ^ R, h" J0 H: B% k) \; r( o Face* face = dynamic_cast<Face*>(*fIter);
C. M- _& q7 }. ` r ObjectTag = face->GetTag();
4 m2 e0 f. i+ [, Q' Y! h sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag); " N& E* `$ m5 z% p: e& t, H
WRITE(mesg);
) ]9 r$ J A1 n& c( E! m& B index++;& H' E H- t! P3 {: e0 d5 v
}
0 ]/ K9 k& [* @1 x$ ^ s, e! @; Y3 s }3 |" r- p: K) S; p
break;6 t: K [; }1 r6 T1 A9 ?) S
) ~1 ?0 q" a5 t9 k3 X5 C& b
0 t6 m! @: u6 W+ _+ h- s
default:5 u* w9 l% D T% S
break;
% i7 T& A) l9 }: K) } }$ u. ]; ^ }! \$ i* h& o/ V. M$ U
}# F" h4 u6 C2 d. E
}
0 e3 w9 B5 m/ B# G$ L
1 K$ m7 f, |% t" i( j8 q! G& Y7 g) @5 H2 Z% U* O6 ?6 U
' v2 Z1 f: ?1 C- t. Y, t2 j
$ e/ j" L0 @5 R! V* b. K
. M. H& G7 O! L! c E2 j! C( L; G; ]
7 r0 m. r3 @) ^ f. V; A millGeomBuilder1->Destroy();
1 X$ ~. q' f# k0 B, y# t7 j- m9 D6 k. W3 q
1 D6 I5 u6 _ B# H5 d6 n. H2 g
} else {, F: `0 Z8 e7 y7 a0 O% X3 V
WRITE("type is not UF_machining_geometry_grp_type");: N% A( e' q( B5 L& W. Z5 e
WRITE(" or UF_mill_geom_featr_subtype");1 Q7 |6 S4 [+ x
}
8 j( w/ Z6 ^% Y4 K( Y& h UF_free(objects);
9 }+ W$ U, ]% X T' W# L4 @
1 u- |% |- z) A8 n2 B" P ]# h% }! L6 {+ w
} else {+ W" W* t q2 U6 B
WRITE("The number of selected objects in ONT must be 1.");' G, _6 ^ P8 P6 X2 ` j' b
}
+ S6 m' d% Q" M$ O( v2 v" B9 u0 d, b8 I* x" O \6 t5 J
6 F, m4 [4 z. `6 D- t- b. P; G}
1 K7 q* I/ q8 ~6 F; `9 k
9 S9 Y# [4 E0 G2 L' x, h: @ |
|