|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
6 t; L# X5 m; y I5 m( S* d& ?( P5 l
NXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值
8 [* S4 X$ E o
* P5 q V! f; `# ]5 O0 j% e8 C- Q
# h( K. ?3 x( d/ [6 b& `static void do_it(void); Y1 b. \* K7 h8 x- }
{
$ E/ ?8 Z7 N- n* W; p logical is_initialized;
( E+ {9 R3 G+ m" Y8 L2 } int object_count;
9 H. u: Q. k+ ^. }; q+ o) k5 P int type;3 ?3 G# Z M: P& D" T% m
int subtype;7 U' u( r4 q$ r! P7 a# S
tag_t *objects;
* o B) w. S, L0 U! R. u! }+ e9 {
) b3 j7 Y9 C+ w, T* D
. P! Z8 @. J5 q8 V7 ~4 Q( R+ I( K
2 ~2 |% n$ \' }: W1 `7 w$ z! k# R, y- b
char mesg[133];& R& g/ W1 ~6 ]1 w
! p8 t0 Z. \+ n" a5 D$ ?
* s8 @$ u7 v n% Z! X3 s2 | // Get the work part
2 a; @! y; k$ w: b Session *theSession = Session::GetSession();
5 q1 K* P9 a* j' ?' ]6 @* J8 R Part *workPart(theSession->Parts()->Work());
k) F6 y5 s" o& S Part *displayPart(theSession->Parts()->Display());' @; Z6 ^5 k. m1 X
1 z+ g1 ?* E1 Y4 a" @. a. ?- o7 n3 }# h
) @ M" y! ~; w2 L/ }7 D1 e
1 X6 Q9 Z% f% @2 S3 l$ p* \' p if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;
8 m( @; e. V0 t x
( P# K O8 |6 i8 s" M( V& J' r" M5 v B, G! o" F$ E9 h8 E
/* Get selected WORKPIECE object in ONT */3 Q4 J5 P' `8 N& j) W- D' j# B
UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));! b) h" K1 q1 [9 t
9 @. M3 _ L+ ?; }) |0 ~) k2 h4 S! b9 ?% P& v
+ _5 j$ s5 i- t+ r& s
3 X9 `$ O- W; b1 B. x% G9 r: b- t/ y
if (object_count == 1) {
+ E4 L& t! @8 }7 P* n UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));
6 ?. E$ a4 [0 f- c/ B/ v' i8 z$ g S: k% M
; a) g5 _! [. p' D+ s" i. p4 [! l6 s& {* D% A: E9 E3 n
1 M, {5 d2 L. H
if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {
7 c8 I7 W, o$ M T( N) W, @5 k7 G% W/ x# |
/ [: L0 K7 \0 A5 e: K2 ?; U
tag_t ObjectTag = NULL_TAG;. w! l7 y6 q, [+ K' j7 c+ K
2 B, K+ N" m6 g- y# Y9 ~5 f. ?7 u
* e, Y2 R& ^4 p/ ]# a2 w // Get the object from the WORKPIECE tag
$ [* z( f* c8 E9 l4 x CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);$ }* p `$ p7 D/ W/ c+ o/ O
1 M4 ?! X2 Z3 y$ B' w
/ ^+ ?, k+ o: j& @ CAM::MillGeomBuilder *millGeomBuilder1;5 k% K) k: n; }4 Q, F8 y
millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);8 G2 { u' a6 D8 V" @, U' ]& }$ r2 d
7 l5 H! a: M( {: v
. w9 [7 V" B. u1 x- ~
// Get geometry set list
/ N' z8 }2 ^3 P9 Q; i3 J CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();2 D" U3 l; J. _
std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();$ e+ o' x! u- f; E. L( E- o: O
. W9 a% ~- o# u/ d% c1 u
& q" G- X3 M6 `% m* a% n // get geometry set
: W- \" R/ O/ F) L1 j i4 I std::vector<CAM::GeometrySet*>::iterator iter;
( O3 F& ^7 n0 i) \: W for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )! @3 c- ]7 S5 ?3 r) O( @: Y6 `+ m
{
( w- n9 A8 g6 x, \- Y1 A5 A/ v" @ CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);- F$ U! m% D+ _+ L! f& N
ScCollector *scCollector = geomSet->ScCollector();
0 v3 N+ f. s5 x5 k, J( r std::vector<SelectionIntentRule*> rules;
4 Z) I" L$ j! T scCollector->GetRules(rules);
. C6 Q0 W6 H: s, I; K' R
. m |& ^' y0 _8 ]" q- Z' q
& N2 j% ~8 A; k* Z$ e2 W( ? //get selection rule
2 W5 Q2 a: R+ v1 U' s6 w, ^$ v std::vector<SelectionIntentRule*>::iterator ruleIter;
5 Y1 L# Q. B5 N, | for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )
) h! n4 o5 {) Q4 ] {/ o9 X5 L& F) o6 M0 L2 g- W
SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);' z; X7 c+ Q7 s- \- P: `0 j
NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();, x! T/ \0 o5 G" X
//there are different rule types, here just use body, face as sample
6 C/ O. h F# i switch ( ruleType )
; A$ K% Y" w/ _; ^8 z8 R( C {
5 C, ]& _- f) ?' K. r0 |0 Y9 z0 { case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:
+ ~$ k7 A- ~5 U9 i; Z {
- H/ c3 C3 Y2 v `/ b //get bodies
1 P6 {0 Y+ O5 A' |: J NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);
8 x9 |$ X: V9 \: y' J, G0 T3 f std::vector<Body*> bodies;& E6 E3 d. U4 V1 L
bodyRule->GetData(bodies);
) u. p# @3 X& @9 `/ K4 I std::vector<Body*>::iterator bIter;
" K+ H8 T, r. Y4 s* P/ p int index = 1;2 B0 V6 S4 p1 u3 z& L
for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ ), Q$ C% m5 A- ?* k% y7 h2 @
{2 \, N: W$ u' i
Body* body = dynamic_cast<Body*>(*bIter);
* F* U' d) L& ^" t3 F H& \ ObjectTag = body->GetTag();
1 A0 T' {' J6 }# i& F( h8 H: M1 N sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag); 2 p7 j! X3 J. p8 g2 M: i* f( r3 H
WRITE(mesg);
/ W1 ~. v* t& g( c" U% i( G body->Highlight();9 `0 L* b6 \$ }5 R, i. Q( N* `5 P3 r& k
index++;7 s# K$ w8 l+ w
} E) b8 Z3 Z7 B0 P
}7 ?2 l3 v i% z# u2 e( g
break;% ?8 Y. p/ D8 s1 J- p+ D% [
1 O1 L& Q5 h% a
; j: d9 q& W" i* g0 l
case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:
( y# ?# m! s: C$ e' _5 Z {8 l& g3 L& N( D$ e4 t$ g- y, w* g
//get faces % z* t& _9 a6 r, t! e! A0 G
NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);
6 q6 S6 n' s | std::vector<Face*> faces;
7 s' k( W7 M( J" C faceRule->GetData(faces); |+ m% D8 r1 ~& u0 {8 K
std::vector<Face*>::iterator fIter;
/ H; j7 x. r$ c int index = 1;
$ A( R+ s+ ]3 T$ g for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )* p1 B! i4 t/ x/ m" L. `
{
2 ~, h5 ?: G- c' T2 L0 r- e Face* face = dynamic_cast<Face*>(*fIter);! X8 d K& f, B4 W5 Q" X9 R
ObjectTag = face->GetTag();
( ?9 o, U- j3 B1 P7 y6 G sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag); 1 M8 e+ h- ?3 F% x. r0 o8 l
WRITE(mesg);
* S2 V- [8 r4 [' C! v index++;/ v1 [9 C* k/ `8 ?# r/ f8 {8 d. E
}, y) d0 O; @, E% e
}
: H% {% S4 O% t0 [. N& B break;
" b' _! m7 K& \: S! I
/ O) U4 N* u4 C5 S+ _: [
6 D9 ^9 Q- T: ^* Q, l% } default:
( s% p1 [ D3 w% k7 l# j h break; O0 M/ Y3 a& A4 C/ v4 K
}
( g. g; Q, P1 g }& ?) x, h% o# ]$ G4 ?
}& \, y$ L9 x" @
$ }+ |( t' T' B" C
( n |1 }4 i9 q/ H/ k) ?5 g7 x9 j) ?, |( Y, n
/ I( O7 m, b7 o! |1 e9 Q8 C
}8 F8 u5 w; T2 y" P/ ?# c r
2 z2 s- W! {& G1 p$ U millGeomBuilder1->Destroy();
6 ^" a: d8 ~$ I# @/ D0 V7 v$ `3 r& q1 P% m7 \
. T8 n/ ~' e5 ^* z3 T+ N } else { K' T3 `8 m% x* w8 ^+ A* Z
WRITE("type is not UF_machining_geometry_grp_type");* j V! u" E2 i, u9 {
WRITE(" or UF_mill_geom_featr_subtype");- ~. u. s+ [# Q! i5 a' U/ R H D& m
}. }! ]' Q! L- a$ ?: Q& O, B4 W
UF_free(objects);
: `7 T8 X0 U5 n
' q; D2 ~6 K# N5 f3 T$ x7 P3 G/ R* y
} else {
( j$ `3 M5 u+ f* ~! x WRITE("The number of selected objects in ONT must be 1.");# W. e! Y' R# p- [" z7 z! Z3 Z
}* T9 K5 n7 V- g- B, u8 m
4 j7 V# _3 w0 k' P% S5 K5 ]8 Z5 e8 v8 J
) U, o8 D+ m( D& @' Z
}8 w- B8 `" o# L# O
3 I! ~5 F8 e' W. e; P
|
|