|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
7 q" L, [) C- ~+ t# c# W% {
NXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值 Y& m2 q; e6 h, _3 A0 u
! W! q0 y0 |2 l) K( Y7 X
' i W- D2 n' \& jstatic void do_it(void)6 L* }* b" @- m M' o7 j( P# v
{
' ^4 t4 [3 g0 g( x! H0 o4 n" [ logical is_initialized;
1 \, k [3 @! L% s& y( y int object_count;5 B) z9 x6 i0 A5 k5 c0 {
int type;
$ p0 l$ b9 K7 e8 ~7 i+ F int subtype;# o' J3 }: F2 X5 A! Q0 Z
tag_t *objects;% q* J" `2 o; ]# J: w* s4 W- D
/ n" U! {) C& l- B% y& L
5 Q( {% B2 U! E6 x" ]+ f& R! r/ \- a; }
! m2 K% P( d+ `6 k5 R2 } char mesg[133];
5 g" j! Z) K8 J& W4 T4 D. ?$ P( ~( L; ^8 J
: n# }6 r, J% u& B2 x // Get the work part. I/ f5 H' d$ H. M0 ?
Session *theSession = Session::GetSession();- F0 I" L. x# H* ?
Part *workPart(theSession->Parts()->Work());
+ m9 Y1 r/ @; {6 [5 v" ^0 A+ {# k Part *displayPart(theSession->Parts()->Display()); m; q3 n t/ H6 {# k& E, s% p: H
( F! U1 w$ ` V8 c" b# q
; N2 [3 O. [ P* h8 ]) z) H9 x
6 ~1 }1 V& G" v- P3 u
$ c( R/ y! Z9 S2 Z% d4 t6 ~2 K7 T if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;7 A; \- r# u3 B; o X c7 A
1 k* X5 \3 @0 g0 t/ @: O9 p" E# R
/* Get selected WORKPIECE object in ONT */6 I, b/ m7 j7 j
UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));
! T w- ^1 ?* U7 w+ c2 W
* ?+ j: A1 x. Y0 L& W& u. ?# R) e+ t
5 }; H0 R( u4 ?* f/ ^0 w' ~
4 g* p; e; I0 m9 n% N if (object_count == 1) {" c5 Q- p/ K& @. G b6 j
UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));3 J, f U8 }" K( ?
+ d* W/ @3 F% l9 r" L( c4 I y/ K9 C
$ ?; K! i/ E, d4 \
( r# o- n' J* s }6 | if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {7 q" Y1 |! X: D3 S9 j7 R: w
, J6 z9 q- K! K& Y: Y
* y" H z9 x1 P. x( ~. U' b tag_t ObjectTag = NULL_TAG;
0 q3 o7 m2 O3 t7 P7 P- A
" d+ [& v* T' O4 L+ ]
6 M6 N9 K) G# R7 I- i // Get the object from the WORKPIECE tag
, w- p) o9 F3 T. H CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);8 _4 o0 R: b0 b% D: _. @9 d
, A" a6 j9 V0 W0 d" ~ o: N; @! [7 Y( H' `: w: q
CAM::MillGeomBuilder *millGeomBuilder1;% {; Y& x0 ~6 {% y* P0 f# N
millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);
; C' i$ K. z- l" }1 w8 j- _* b7 V
9 m) p7 p* p9 O$ W. T1 \. m/ [' W
// Get geometry set list
: v; j* o$ w x CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();
* }2 i4 X+ `& J% H. c9 o9 t! f std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();! ?; e* W3 p6 g* \0 I
* G/ F( I. U( G2 L- z+ v3 W
; `6 ]: o& j# @ s/ E# }- \
// get geometry set' c7 M8 j# t5 R% Y4 M2 N7 {
std::vector<CAM::GeometrySet*>::iterator iter;
/ U8 G) F( ?( J1 H4 L/ |5 Q, t" L! g for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )
' H7 y) _; S$ X. J$ e {1 s$ n j/ ~0 ]* Q3 V' ?9 m
CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);
3 q6 W$ j. X. F' C ScCollector *scCollector = geomSet->ScCollector(); 9 Z4 K( i/ m( U
std::vector<SelectionIntentRule*> rules; R" H% l$ F& S# d- q2 V
scCollector->GetRules(rules);/ u/ W M, o/ S! @& A" `4 z! X
J# e. F, ^* I7 Z
# A+ M9 y2 ?) [" ~ //get selection rule0 d/ _* N3 x9 D" C
std::vector<SelectionIntentRule*>::iterator ruleIter;
5 r3 g. Y6 w7 H0 g- V% n/ v for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )
! G+ ~; x5 U N* [# @# k2 L {1 h. ]5 z" b1 c3 V
SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);
B x% w3 V7 a2 m3 g* j1 P) {& K* C NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();: }- l3 k& P" q0 _3 b: l, D
//there are different rule types, here just use body, face as sample2 D0 i; Y3 @, U8 f5 S; M; F
switch ( ruleType )
2 _( C: ]7 V' E {# ^1 Y4 h# F5 b+ ^" E
case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:
& n) y: {4 I# P' F) _6 H3 B {
5 w" C6 W- N0 g5 a0 `9 X' x- U# y //get bodies
4 y) P# b4 q; U- B! L; |$ m NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);
8 x) R7 W, v1 ] std::vector<Body*> bodies;
2 b1 A8 K8 F' B/ Y6 a: D& N bodyRule->GetData(bodies);$ F6 [1 ?* P# w8 Y' M, W4 p& r
std::vector<Body*>::iterator bIter;1 @4 ?! u3 w- {' G6 h# x; h
int index = 1;7 H! T7 G6 D* [0 B0 A; s
for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ ), O! l* p* c, ~* F; _8 M3 l$ o
{9 m4 R/ [# N; b) m
Body* body = dynamic_cast<Body*>(*bIter);' O0 s' ]! `& B4 U
ObjectTag = body->GetTag();
5 i# X$ S: A. i. |6 U sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag);
6 X4 P4 d, `" X WRITE(mesg);2 H H& v5 o. Z
body->Highlight();
8 `, C, Z S% @, ?8 O0 x5 \ u+ h6 Z index++;9 _4 U V4 J: q/ z! b: k% x* b/ [$ y1 q1 @
}
8 K" F2 m# S4 H/ I7 Q# f1 M }4 A% R% k* T/ D% |
break;
" i% K, C8 ]! B+ N" l' y- Z. v- x6 o$ H, C" u
3 {% d$ i1 g# E1 M) W
case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:
9 [2 m# s3 @ f' R* Y {
) x8 ~) K) O9 K //get faces ! K! N; D8 z: r! {3 Z
NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);
! H. Z4 I& g9 v6 H$ t5 u3 v& n4 F std::vector<Face*> faces;5 p( S N4 Z) B7 Q& K' v+ w
faceRule->GetData(faces);
/ i) n/ E& w6 d std::vector<Face*>::iterator fIter;: O( k3 z) h+ ~& e/ j
int index = 1;( r4 O+ y" [$ Z' |: ?( R6 I$ G7 R6 j3 e
for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )
, s+ }0 G, S: x( |8 k* _- Z {4 N* H& j/ @: R
Face* face = dynamic_cast<Face*>(*fIter);
$ E3 z4 Q4 s, k- r* q( Y ObjectTag = face->GetTag();
4 o; u5 H) i y: W sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag); ! `5 y3 Y, ?/ m0 H
WRITE(mesg);3 E, V* j7 ~* @9 x! S/ }/ T% O
index++;
7 n/ z: ]- c1 m; r8 u5 Q }
. K- }2 j+ O% ^% U' ^4 v* j }
, {' h$ y( b2 `* e break;
' u% [5 e4 n+ E5 Z) w% q: |- H+ H+ J* H0 A3 }
* I/ \$ L* p7 c5 @) V! E9 _9 @ default:
. d+ v% R8 H/ c8 f break;( [: q9 q) q0 M
}
7 T% H9 H6 y+ t6 _! U& H }
! R+ _% S8 s' C3 [ }+ Z. S6 @) T; [3 k# m$ j
- V; E# J ~$ C' H% C
* G6 o* j: O* Q3 P0 j
5 x/ o6 U2 ?8 a' O
6 j. ]/ }/ C8 O3 s( R% V9 x8 \0 F, z
7 B Z# ^: Y7 u' H8 ~ millGeomBuilder1->Destroy();
( e- X- q' T: p$ A% p0 |& i1 k9 G! ~/ F v9 _/ a
4 x9 [- o& z: q; H% e7 N/ i0 B4 [ } else {
0 A4 W% ~: R# b+ i" p WRITE("type is not UF_machining_geometry_grp_type");
+ O" n# f: d; d- Q9 m; I1 G- Q6 J WRITE(" or UF_mill_geom_featr_subtype");
$ D7 [' v) x9 f+ s" r7 E }
' H) t4 ]4 h3 @* O& k; h. D UF_free(objects);
: |) i+ u& [1 t& w0 c6 \+ o7 L' e- t {- P7 I2 o* i
) I i% z7 I4 I& N" {
} else {4 C: o( r" z2 l( I
WRITE("The number of selected objects in ONT must be 1.");6 J7 ^# }2 N9 w7 @6 I' F, a
}. s u8 V) i% P* A" l- n; k* f0 `
: M2 U4 W9 @5 C% z1 {+ Y l1 a( f+ O, N; ~- c; m/ ~* J+ Y
}( {3 j; h4 R3 ? C# m' k& {) r
( _# L( ^, {1 P* D$ ?( R% t
|
|