|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
$ m; W9 E4 o+ x8 I5 U* I& h0 N: Q8 aNXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值
4 C- Z$ K# }7 O9 ?) [9 y) m I! l: L9 R& o6 j5 z7 f) q
$ v1 j- \: P y- z4 y8 u
static void do_it(void)% a6 B5 ?7 [$ Z
{9 s: L. G8 H! M0 @8 X
logical is_initialized;) M* D' C( d+ p9 c# a
int object_count;# X ~' t9 Z1 Y
int type;
, }# a0 O/ `( a( L2 H. J0 I$ I int subtype;
! d& o: ^7 g/ L+ R, K' N tag_t *objects;5 c4 {6 I1 @4 U# f% ^% t1 T9 ]
0 D1 q7 q0 ]8 F& d
2 M' R1 ^0 b; D! f8 l
$ c% {" Q, ]) ` a
- |7 u7 s# {; _3 p3 g char mesg[133];
/ K0 j% M0 U; x: a) T8 n/ ]5 Y
' G5 Y/ ]# h1 Q1 D
2 I. n& C7 m* i# F# m: c // Get the work part
! g4 R2 c* `& k; { Session *theSession = Session::GetSession();4 D! i5 l/ L4 b7 | B
Part *workPart(theSession->Parts()->Work());
8 d X7 ^$ N @4 w! L Part *displayPart(theSession->Parts()->Display());) h$ q* W9 V% |4 [$ F y v; M
( t) V! R5 F- g0 Z$ ?1 k
' h! k0 [: u1 i* W
' n* {: Z5 R+ E6 T4 ^
) X9 w" B, P6 y& M$ W5 S/ [3 f if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;
/ ^- T0 P( O( I6 ^/ m8 q% ~3 W+ z
" [6 z: H d0 w! w' _* w7 U+ E2 @9 y1 ?- |: f: \. ]! E7 T+ M# J" _ G
/* Get selected WORKPIECE object in ONT */
8 `, a) k& |- o* L( S3 n, ?( U UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));
$ l( o2 a" s) b# V9 u" r: i( l/ \9 D' M, x5 F# w) g
/ L: C' t0 C, x Z g
! H1 i7 \/ e' E* b
! _0 t# R! l+ T4 |
if (object_count == 1) {
$ E" w, U3 d7 c( r' E' @7 }, I( Y UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));* _* g: D9 i2 e3 e( _
/ S; u; ^6 G# \- y+ k P, O( a; v5 E" T# n9 Q3 V
; u: k/ |- R4 j" [, D* l
. H/ ?* e4 e4 C$ k7 T6 I if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {
- G: _7 Z* |& X1 y
& y% X3 C. G2 R0 I2 W% Y& N/ H T% Q o( s/ f) D
tag_t ObjectTag = NULL_TAG;- ^" `4 }1 \& x3 B" p$ E
H- Q+ O$ R2 l* M3 h
: d# J- Z# h3 ^; R // Get the object from the WORKPIECE tag
8 }' I q L$ p/ J CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);( ?; x9 n; m5 |& ^
$ r) e3 n* D6 o: ?* V1 A
5 C* _' l9 B( A4 p7 A& X0 a( A' m' `5 @ CAM::MillGeomBuilder *millGeomBuilder1;5 {! \4 Q0 e8 D
millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);, D' C; s: @9 A$ e' q6 U' u
0 P/ z8 N7 S$ [2 d2 F
# d' U6 G6 C0 r& g3 v
// Get geometry set list
0 b& e- F/ V8 L7 Q5 N* R CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();
" A5 x S8 S$ I2 L, z( o std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();
- F7 G3 C8 p" m0 ?$ n2 i4 W1 @- H( P6 I2 z$ r' f# s% L: i
, ]# T/ w0 _# k I3 O
// get geometry set
( @$ g. b& B% g5 [ std::vector<CAM::GeometrySet*>::iterator iter;0 s" D1 F6 X6 j1 q9 o z, }6 U0 u3 J& f
for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )
0 G' t$ S# s# J( R {
- ~2 D ^0 W8 E2 l* n* B4 F5 v+ X CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);
8 P: L5 [; \4 o- N* i* `/ r5 D& g- _( H ScCollector *scCollector = geomSet->ScCollector();
* Q8 z2 D& l: U7 J( r- r- H std::vector<SelectionIntentRule*> rules;
% s- h0 P$ M& ?% V scCollector->GetRules(rules);
' {6 z; `# U0 @% o# x
2 U5 u( b3 h! @5 Q B7 O$ [, q( }' b) a$ \ k
//get selection rule) U4 E2 D, t: e& {* t
std::vector<SelectionIntentRule*>::iterator ruleIter;& `" ~2 [) P4 | t, R
for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )
! p) W' d5 R) _ \' i' l0 ? {
2 X0 D+ }. r8 R9 F% f SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);. j8 C( l& i) V o; e% n
NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();
# N3 g4 g+ a9 R/ W6 k //there are different rule types, here just use body, face as sample- U% {1 p) S" e0 f/ b$ i5 _# {
switch ( ruleType )
6 Q+ y* Q5 d( z3 v' g {
2 f1 K( e# p5 M) M6 Z& e4 F4 M case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:
H @9 Y I; {3 a {9 N* y" P, W3 M8 V8 y
//get bodies . Q7 a- z- v$ }) l( b
NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);# {; W' P" X- E" S' I3 v% Y
std::vector<Body*> bodies;* W% z6 O. z% P0 o1 x$ y
bodyRule->GetData(bodies);
3 W' u: ]6 [& T5 L+ V3 j std::vector<Body*>::iterator bIter;, l1 U8 }5 d( j. L
int index = 1;9 Z) ?: n2 d$ W
for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )# v% d7 }4 d ], M
{
8 D# Y4 K7 v7 k Body* body = dynamic_cast<Body*>(*bIter);+ ^3 o; J! A/ T
ObjectTag = body->GetTag();
% O, Q$ I) M2 {( {/ N sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag);
7 _7 e/ |( c0 |. b WRITE(mesg);
3 t a9 w$ T% S- H9 P body->Highlight();
* \# W( e$ w' ~9 I$ ^& | index++;2 j1 v M- |, Z& T: m: t1 V
}/ b' u" T t/ @/ I! p
}
3 B8 h. R+ v) x% h( P5 c' v break;* Z) P! z7 }5 y# T
# j u" V3 p2 t( j a
* S; `* J+ u& w# w
case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:/ X0 n: @. U/ v' N# a( q
{
( r- G/ v1 E1 r; z# V+ k //get faces * ?' s; y) K4 S" t7 H1 S, K
NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);
# }/ ]/ s7 {" U5 ]$ a std::vector<Face*> faces;
+ `/ m; w# G, V* w) z" q0 N faceRule->GetData(faces);) V# P+ u- N! W, q6 x% K" ^5 s. X
std::vector<Face*>::iterator fIter;
% I' h. B6 i2 `$ R$ u( W! |0 [6 z int index = 1;* l( s$ J8 D3 Z$ c
for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )3 _& l4 q$ D V8 m
{$ z4 N: A5 G0 M& d, }3 ^2 L
Face* face = dynamic_cast<Face*>(*fIter);
7 W/ u, P1 J, @4 I1 Y: v1 m6 j ObjectTag = face->GetTag();
! g7 K) j/ c6 ^ ^1 h! W sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag);
. u5 }$ W @" v' V) I WRITE(mesg);
: z) M4 [2 R4 k index++;
( N+ L7 T z/ m5 J; g$ } }1 Z1 G: r+ e+ r0 I
}
+ E" Y' D% `$ w6 K7 |9 I break;
7 O# s# h$ |3 P9 ?$ a& j0 K/ v6 ^5 B' [- Y7 G$ i3 ^0 h; U/ `
% ?+ e! s# J( k9 K* [ default:
7 K4 w. Q; o& ^& {; { break;! h5 B! ]- v7 X1 |
}4 m- W$ d, g! M' S, G& c: p
}5 ~9 z X- A. A& _
}& M" P% j( r; l; h+ z) \; K
# w+ Y) t6 g |
, e& G; h& H. W1 ?: r3 X# m7 Z4 f" u' Q1 e K9 v" B: t
" V; _# X4 Y4 M4 Y
8 F# G3 S8 S. h1 n$ |
! Q9 z& K. c" k9 W5 _, Q. i) v6 T millGeomBuilder1->Destroy();
+ [9 h- k. Y) r* n1 W# C1 r* b+ N; D) c- P% M1 q1 k6 `
0 A7 N+ @2 D( D, V: J. l7 o
} else {7 P% q8 {$ [* b5 i$ Q2 |
WRITE("type is not UF_machining_geometry_grp_type");
) ] V2 K9 n/ w9 d WRITE(" or UF_mill_geom_featr_subtype");* j5 ~4 ?+ Q* u
}
: @1 a. Z: N0 N, B" ^# \ UF_free(objects);; g O9 ~0 s" ~# K8 C2 o
7 R5 l3 F; L5 @) u( V* `6 T
8 t% J! Z( H# F0 W( u) J; V } else {0 d6 Q$ t$ W9 D, N& {
WRITE("The number of selected objects in ONT must be 1.");
. t K$ f3 \5 ~. Q }
1 [$ u1 w& _- I
! r; O p, `. Q7 ]& {- j+ U2 W4 }+ D }- H! ~* {0 l& ]
}2 O* o7 _- p& K/ o9 G+ i/ d
4 V9 s) z6 }& q$ p0 u# s |
|