|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
/ Y9 F1 G; |' ~! ]7 h4 m5 xNXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值
0 z% M# O5 @3 b) ]+ S4 m9 O
; D, q K3 ~3 [) B# s# U3 f+ G3 C# v% |6 k# I
static void do_it(void)
: W& z1 A1 O# _# ^( [; ?1 p{
4 U6 f$ w5 u* s, L logical is_initialized;& X: B5 V8 ]1 i) I
int object_count;
0 W& A; \2 K3 |* F k' \ B. V/ {+ e6 d int type;
( W) U* u6 Y: ^' U' Y int subtype;
+ O0 q, K/ S/ U- k, g3 F; ~# J tag_t *objects;
& h; y2 E8 Z! q7 t9 n3 K
& {* s, v2 O# {4 F$ X( ]! m8 E& \8 k% }! b* Y
6 _' I3 _' L( h7 b
/ K4 `1 ^/ c. r& B/ L7 |' _
char mesg[133];' }8 ~1 U+ q; ~& ^0 U( m, {6 ]( }
8 c/ _9 L4 Y3 L, O: t% N3 w. L$ h
/ d. Y$ n- z% x0 T // Get the work part
% T7 j3 @7 ^1 ~; ~ Session *theSession = Session::GetSession();
6 }, T3 Z) f5 W* m Part *workPart(theSession->Parts()->Work());2 ~* [" y, T9 i( B+ x0 c8 _ t3 b
Part *displayPart(theSession->Parts()->Display());
- ]6 r- f: Q5 _6 _7 c6 j# N( Y7 ^# c" N8 _" ?/ O) T4 S) R! N
3 D0 q6 f4 J. g, H- M6 z* ^
$ |9 F$ q. t) A2 V1 D9 @/ J
: B' \& T7 s7 ]5 O; C if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;
% e$ s' |8 y$ s8 h0 r* y, N3 I
: l* u/ I% I1 [! E9 t
% F7 Y& B% U4 b) v, I6 U# p /* Get selected WORKPIECE object in ONT */' i% q5 P5 K7 \, m# z6 W1 K
UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));
8 @5 j; f5 ]/ ]
& g; Z% C; Z4 q7 F/ G3 k$ N- J- [. j h
/ Y& C7 Y; d3 V+ c
4 O) W Y2 Y u; R/ y" ^ if (object_count == 1) {% N) W c. Z0 {/ V( o! ?
UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));
B) s3 ^9 r" }4 u+ g# m1 ]
9 X2 d# @: i$ s2 ]
: M ~0 _, a& [+ Z
* {" M) G, t/ m; i) B+ S m. Z2 K2 @4 {
if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {( b, H. n! x* N$ s5 P/ b' {
0 A# u+ e$ q; S+ P g
, `5 V' L6 s( H9 l) P& l8 e1 H9 ^ tag_t ObjectTag = NULL_TAG;
, N! y- |2 x# g7 \, T7 l! R' ]1 T
3 h+ ]. y" r( j7 W // Get the object from the WORKPIECE tag n7 G6 V. C$ q# _. u( ?
CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);
, F% [) b6 E0 S/ U5 y5 o% c: w) z9 E5 F; P9 Y$ d) q
9 n3 w2 Y) _8 f
CAM::MillGeomBuilder *millGeomBuilder1;
1 s" k+ L9 I5 B7 r millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);
" A9 @8 l( z7 e5 Y/ A4 ]& m: @# @9 l, V* V+ g6 l
# S0 Q1 I$ i7 l" H# z0 L // Get geometry set list t6 L- [& m( D7 z9 N+ B
CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();
& K) |; F _( w8 t0 g( _ std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();2 Y6 u* i! @( a; [$ h$ q
$ s. y* j7 I% S1 K0 j1 N9 J4 q4 ]# P# T& `) D" @( C6 V8 ~- D
// get geometry set
/ E) a1 C' F. d: d/ {# Q3 w' h. U2 f std::vector<CAM::GeometrySet*>::iterator iter;
* v* l4 ?# \" C& f; \ for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )( F6 v5 K1 M* x- K; r" c8 h
{
9 o0 N" d1 O- Y. q7 P0 i0 M$ g CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);
" S: I% |+ B3 }- G ScCollector *scCollector = geomSet->ScCollector();
: H; j& y& g9 `" E: H7 Z+ H# F3 A: _2 ` std::vector<SelectionIntentRule*> rules;7 y) H* ]. D, m
scCollector->GetRules(rules);8 ]9 e$ B! S$ h; f$ |% a
* i: a& s( I1 {3 L- A
7 U: n- s7 t5 V //get selection rule
0 q- C( _: g, ~; }7 [: I7 { std::vector<SelectionIntentRule*>::iterator ruleIter;6 ?6 ^, Y( }8 d) Z- c1 E
for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ ) Z* E+ r- H# S5 W7 H) a& \
{. b' G8 _& @7 O. P
SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);7 e; L3 Z0 t( Z0 f% k+ F. [3 M
NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();1 C6 S! \+ Y( L+ ~+ b V
//there are different rule types, here just use body, face as sample. [! g6 f( o8 g! U6 \, P. ]
switch ( ruleType )
/ D7 D( M" L9 c3 i* L5 {6 [: f. h {2 [2 x9 g5 [: Z' [
case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:% q# G3 C" ^$ g( H' w
{5 I- ]0 O# {1 n
//get bodies $ @4 z2 h7 v/ }$ S2 K: ^8 K/ T1 X
NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);
5 O9 Y8 a/ V/ L3 n5 h: o. Q std::vector<Body*> bodies;4 h5 y( b6 E9 i+ e, G
bodyRule->GetData(bodies);
q( C, E0 ?- C' k std::vector<Body*>::iterator bIter;
: ~ H/ B7 h4 A% C. O; { int index = 1;
$ P, ^( u8 t% s, a; g for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )
4 z, b5 k9 V) l; P7 y, H {& y' s5 {! R2 R& o
Body* body = dynamic_cast<Body*>(*bIter);
* w- X7 ^" X% d7 a0 L$ ?. a ObjectTag = body->GetTag();9 B# Y0 z" y7 U2 p
sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag); 1 L" z/ h) A- q3 X l. w2 ~- l; x7 E
WRITE(mesg);
% c, _) Z# m; _; w* d9 g9 Z body->Highlight();2 y6 f$ e7 m' }9 M" p; D M# }7 Z
index++;, _4 l# u9 r; X3 Q
}6 @$ H4 |9 A% C0 y2 K" [
}0 b! t, p4 g% {) z" f6 I
break; I5 z" [; N9 c8 ~( z [% p' I
& D! r2 j T4 f0 @) s2 Q1 o+ ~/ Q0 N; W! Y8 u
case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:
* O0 s0 `' J* z2 r6 p {) U6 I/ z0 W% a6 X
//get faces - r5 t2 L& T; J8 {0 L
NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);5 ^8 N4 {! v* U) L7 U: E
std::vector<Face*> faces;
: T9 L8 t# l0 o. R# @& _+ Y+ ~' k faceRule->GetData(faces);
V& s% r7 E* n std::vector<Face*>::iterator fIter;+ x4 |( D5 q8 l" l8 o7 Q
int index = 1;6 i# q; p$ i3 C6 N- g" Q. v6 a
for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )) I! w8 E0 q- M8 B9 v$ U e
{ ]" c1 ^+ g d
Face* face = dynamic_cast<Face*>(*fIter);7 G# f" E9 B! h
ObjectTag = face->GetTag();
& v9 G5 A$ E6 \% E9 B sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag); ' k7 f' e, D& i* _$ a
WRITE(mesg);
" W0 O# N: w' g! I: I2 E- J& b9 X index++;+ T, B/ E- r6 ~0 w- {5 M% a/ ]0 z
}
) m/ a( U2 u6 W0 G W# J }
% o" X7 z$ X" k5 z break;: T" f9 ^( X* N% o
( P, P3 n+ w( x0 Q8 l* o$ _6 a
* b! O5 p( r% X4 R default:8 ]3 l* B' y4 k$ }
break;
( V% ?, }. `1 Y0 m }# Q4 w A: R3 X& v$ h5 o4 s
}$ s Q1 \$ b/ ^5 G4 Y( V
}# Z) I: G3 K f: \+ M8 g9 c
6 D1 W/ ], V1 R( A
) s; A: C8 S: S8 n7 D5 e; a7 }' X' h4 i3 h4 q4 M% U: V
/ w5 ~% g4 a4 v$ s7 M, Q/ b# j+ L8 O) `+ q, [
* E0 S7 H. r8 z, B! v4 s
millGeomBuilder1->Destroy();% y3 I. e! k0 G7 J
5 W6 G! e5 h G) a! E3 G/ Q& ~* d$ g5 k9 G+ L
} else {
1 R) T) d2 P7 ^! g WRITE("type is not UF_machining_geometry_grp_type");& W# N$ o' i U
WRITE(" or UF_mill_geom_featr_subtype");; @/ \- J% v) q9 P6 ^% Z
}. ]# N: c' C) Y% c8 v" k, H! x1 B. ~
UF_free(objects);# ~, z! X9 }0 h7 f% [
. R! L }. t. c7 f) L8 P# P+ M4 e; S3 _! A( E' v
} else {
( J7 k: P' L+ x+ G8 z& J; L( ~( E WRITE("The number of selected objects in ONT must be 1.");
% V( Z9 v% o; ~4 Y }
# \1 N* Q W S1 N. g4 T' ^4 @& C' z7 M
}- t- q! v( [
}2 `6 m- m, Z! `3 t
( [2 t, `6 x, T" I
|
|