|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
$ k$ ~5 s1 h% R/ JNXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值
) S; O# @& y3 x4 m7 D9 ?" W
- l" A' d4 a4 M* W' R6 I# g
; I' z/ ?5 [& D. }9 s6 G7 Kstatic void do_it(void)
9 M% Z1 j9 s% g; K; i{
) b9 H% n" c' A logical is_initialized;& d4 t6 U$ `$ O! l
int object_count;5 o/ Y0 q; B1 @
int type;% x% A$ t8 [& \" X" p: X% }
int subtype;6 ^ M# Z. A3 V( G
tag_t *objects;* i3 |; d# V5 s* m
/ k6 G9 T3 a; f
4 l- ?9 F) o3 P& R( j2 N* `9 N6 B
7 u: O/ ~: }3 v% ^
6 O3 {% V# w; @% F7 w/ L) s/ R char mesg[133];
% k- S1 U. D* f8 h1 |& p* D& {* P9 p& z
9 X; X6 y7 s% I9 n) P
// Get the work part
# [( _% a' K4 @7 P; q7 G1 f Session *theSession = Session::GetSession();* o8 D% H1 }) V3 [
Part *workPart(theSession->Parts()->Work());- u+ e; \8 D* P1 S& o+ c1 R6 ]# p' M
Part *displayPart(theSession->Parts()->Display());
: X- h: |+ p6 |8 C" Y" J% J6 ?+ T! D/ B6 f8 b7 m, Q& S6 z
0 a- P f- E! ` O% `) y- h
/ u7 i/ Q8 q( U% S
5 o& A) b1 M' N* F" L if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;
, J6 l( q; m+ ?! d4 F9 `
: m: `* d9 \& {# S. m# T
0 {2 U; K* z; X' M7 i0 B /* Get selected WORKPIECE object in ONT */4 W2 h* b8 l" d+ o
UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects )); D$ }, G& S0 r5 K" y5 j" t! E
B" x T. \; S) b& W# s: K
. u7 m8 N7 H' c, {0 V7 W6 l2 p D% J) R8 `6 D# A
j. R2 O& _* y4 p& [ if (object_count == 1) {
: t* o* j; k& l& ]1 g UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));0 c! E' R4 x/ o# q3 {4 O6 m
. l* Y9 s4 S, v' K$ l7 p
9 @0 m) f$ X/ W: y& g: T0 D! ]
3 g1 [, @6 E# i+ P
& r3 x d& u& t; `
if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {/ e, C2 `: h- h
3 e/ \0 y: [/ N1 T1 d9 E Q" S9 h) \* W
tag_t ObjectTag = NULL_TAG;- f. S9 ]) D5 S0 {0 n) ]0 l
+ X' Y( D: N# B" r2 v& I: m
. Q) @: w) _. ~
// Get the object from the WORKPIECE tag
$ |, ]* T$ K1 H' {; a CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);
) H2 `- k+ U2 a* T3 L! t$ N$ ~- x b f/ K7 t
# P5 J8 U( ~$ O v; b# w1 t5 V
CAM::MillGeomBuilder *millGeomBuilder1; k7 {9 u- n; i3 A
millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);2 J& G2 u+ A6 T z5 T5 l0 g$ ^
6 V6 @2 F0 @& H& e) L1 a
% l7 k/ w- I0 V6 |: g
// Get geometry set list/ l# H( ?5 l" Z: r* c& o
CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();5 Y) S' x7 J+ h2 S" p
std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();8 i' n6 D; X3 Y. {, f' p
! [1 o6 `) o: l# N: L
& M* J2 [% A# V F5 g$ d7 Q
// get geometry set
! y+ i& M" D9 u: c/ W std::vector<CAM::GeometrySet*>::iterator iter;
5 T3 p& b+ k2 G" [ for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )4 m+ m; d, ~' c% ?0 p- {* E
{
" ~* e2 d+ I, `" b: T1 ?) x' j5 I CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);& I+ y" r9 D: n# A. h
ScCollector *scCollector = geomSet->ScCollector();
5 u! Z! c/ v2 P4 X; z std::vector<SelectionIntentRule*> rules;
* N$ p# C2 x4 j/ t9 ?- v2 T scCollector->GetRules(rules);
1 g& h) Q+ K- j2 Q6 w! w6 n0 O1 h. b; S4 G7 A; K, [
% z% A8 C0 f8 c, @7 l9 O //get selection rule
4 t; c& f* U: e# D& S' B: F* Z std::vector<SelectionIntentRule*>::iterator ruleIter;
7 {4 U+ F. s5 u8 i( V% F# G6 _ for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )
8 \) \" l+ h* h# D. m {% v3 F! g+ _- u% m, w* A9 G2 [4 T- `- i
SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);( R1 N+ ^: g1 p5 h. X
NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();4 T' Z' h, h; |" a$ s% N7 Y
//there are different rule types, here just use body, face as sample
. Q* _0 a/ c7 w* h) d; a: D switch ( ruleType )
7 i0 Y6 K9 u7 ?5 ~! [" G$ f& l( g; l5 A {
: K* `4 \9 p; J case NXOpen::SelectionIntentRule::RuleTypeBodyDumb: O, P; p# q: ^. ^) q! ~
{( f0 k5 f5 e9 N7 Y2 O
//get bodies 0 a/ Y. S' q$ {
NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);
+ X* P: o0 |2 ]2 S/ a, a std::vector<Body*> bodies;
4 Z, H- X3 K! k" x bodyRule->GetData(bodies);
: T k" G& e9 G std::vector<Body*>::iterator bIter;
3 ^ k- I; k+ T4 r/ j int index = 1;
' U$ Z" K+ L! s% Z) L o/ X for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )
8 E X! E: E9 g! i0 q5 ~+ ]& P& z {
7 Y) a) H( ^+ {: y9 ^* G% t Body* body = dynamic_cast<Body*>(*bIter);3 G/ _3 Q' _ V# o1 D1 ^3 W
ObjectTag = body->GetTag();
; M$ A/ x' P1 ^7 x% q1 n& z sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag); ~3 G3 H: E: `3 k+ Z2 Y
WRITE(mesg);, x5 l8 \; U* g4 V2 {5 p
body->Highlight();
8 v1 B0 T" W; P% ~, V index++;+ d# h- q/ p% y+ y) p+ P
}
1 \. S1 D. i: X; [% ^% R }
$ M3 f/ C& d+ Z' ~ break;
) n) M; c3 i9 R4 w( w9 r/ u* E K& G! W
5 V, `, B5 x! |) _* v case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:
( ?- V( ?, v! y% G; _+ H {. t6 e: F1 L# ]+ `
//get faces
( s3 L1 o- J8 o' X NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);
# Y$ P/ N. V5 \9 x1 a3 q std::vector<Face*> faces;7 L9 x/ s0 n) w# i0 g0 q9 B
faceRule->GetData(faces);
0 Z& [$ S% T [( M$ m, J6 m std::vector<Face*>::iterator fIter;
- j3 d, l- n' ~& F3 ] int index = 1;
) y7 C d* {# J- a2 _0 i for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )
- ~3 \+ { O. s! O, V8 S6 R& K {8 {' [+ N0 E7 e! t W
Face* face = dynamic_cast<Face*>(*fIter);
% P# }3 R: V9 }, X$ |1 V ObjectTag = face->GetTag();
( i( P" a6 E4 R5 E* X sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag); " N- w/ c3 d' k. i! I1 ^
WRITE(mesg);3 Z- i9 d0 k: j( p# K0 S
index++;3 x c8 T7 R& U& D- t' z% Y- ]: y
}
$ j& t ]0 t% o4 K1 e; X* | }
: W3 Z: N" ?9 v; E; }/ e break;+ ?. V( V d% r2 f* Y/ |6 H
0 [9 D, M5 }9 {; S8 _' C: t1 }
8 s7 @$ |% M0 ?# ]& f1 B3 P H default:7 C! B3 x9 t# E6 Y" [
break;
8 s5 m+ W" ~& G- j$ b }; Z( W; G2 O% v/ H
}1 I$ f3 w+ G$ v" @
}4 ?+ b: t) Z1 \. n3 @
. [: p9 `0 S( K7 C& U' D* H
1 K2 E* N) k9 W6 f
& t; W) u5 v: L* R) o& M
+ l& L' ?- t* U2 c* \1 r' u" q; k7 W! p
! P3 n. B o; H
millGeomBuilder1->Destroy();
5 O) Y' j, D# V- D0 p/ s- v0 h8 e' K5 {$ `, q
3 \. w! D. O* q% Y4 f/ p& ~( N
} else {
8 U, h( T# g9 J! o/ g WRITE("type is not UF_machining_geometry_grp_type");
3 J k: c( R' e8 { WRITE(" or UF_mill_geom_featr_subtype");2 U3 q6 G5 R/ {" i( h
}0 Z- x O- ~; o9 F3 _
UF_free(objects);6 ?$ V A8 y) B# }
; C( O/ {* w! O; q: a9 B1 N
* ~- j g# c2 g3 c
} else {2 a4 y' i. e9 ~( M) R4 _
WRITE("The number of selected objects in ONT must be 1.");% l: I- {4 X% I+ V a4 p
}
+ X) c2 [+ g. F" Q K8 }5 ~0 o& f& V+ O1 ^( w# v/ j! [) R
Q8 h8 ?) b4 {8 [ `3 i2 u}, w; U( O: C" l5 O# y
3 {( J' A/ X$ e, s' F
|
|