|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
×
0 c+ {! c; O/ F/ M4 F& dNXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值
8 z; i' W- v! |) l9 U& o1 U/ {/ U: B8 r2 Q2 @# v
# j6 y3 P! D! C9 rstatic void do_it(void)
* E: C6 z5 i7 P5 [5 X1 z{/ C# {0 f" r* H" L: V
logical is_initialized;
* q6 q3 e |$ } int object_count;( d* {& `5 o" l) N
int type;- Y- X4 b; z. M: Z& R' R: D
int subtype;
, g2 @# R( A6 c) Y' A1 J' C tag_t *objects;. d" p' V5 _2 Q% B
, T* ~$ R+ \' N) G1 x
/ C1 t$ N- A, @+ A7 B3 P! n- l% M m0 W w# h5 _: k
! u6 P5 p, F- s7 L$ f; Z
char mesg[133];: L; u. j( {9 I4 P; W
7 R, I8 Q. N; ]0 K
' e' ?! |* L* {+ B' Y // Get the work part+ M% j+ ]2 J* @
Session *theSession = Session::GetSession();
" z6 {% L6 ]9 b$ q4 e Part *workPart(theSession->Parts()->Work());
: G% @$ ?) [. y' N7 R Part *displayPart(theSession->Parts()->Display());
0 |+ E2 c/ a+ b! \, Y, S7 E, [' J6 e
* [1 \, w, R: c5 z& `. J& O, Y
& R+ z. _& @+ k7 [! M1 w
* t0 p1 M& e5 D! h6 o8 D2 }0 Y8 D if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;/ \0 a) B6 S$ }2 F/ {) A1 i4 \
6 p$ R: b% K% W P4 E7 w5 i* l6 b9 R' X0 Y* a }
/* Get selected WORKPIECE object in ONT */9 `' e2 @$ G0 A) p
UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));* u' F1 L( Q; s/ t: l
$ h& Q. {+ c Q
3 U% H8 p" _. L/ \5 }. E+ p$ c% V( @0 c8 a( g
8 i, I( t( I0 U; U$ W' G if (object_count == 1) {1 G; r! b1 w& X X
UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));; c( T4 y9 P# M! j. |
2 B4 t- Q0 G' X D: V
. y% p: T$ K& u( A4 e, ]( c" p9 M0 J
1 G1 Q* z9 i# g if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {3 J" A( \3 g( ]. W$ ?
6 Y/ Q7 o8 X7 E9 `0 [
+ y6 @% \+ C% ]. [7 A% j tag_t ObjectTag = NULL_TAG;
0 k5 x% h! e* G3 M; d% G
( L% J7 r/ x! }( v
- P3 K9 r: N" D! f // Get the object from the WORKPIECE tag4 G1 A9 w; f) F- I* {
CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);) ]1 B" i5 w" B% `8 o5 b0 r8 j
3 b5 X y3 z. t7 R
/ g3 M7 f! K7 \3 H; Z CAM::MillGeomBuilder *millGeomBuilder1;1 T, E2 {$ W9 T; z" k: A
millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);
0 ^+ Z" D. z. ]: ^) n4 E' a! w1 }+ M2 g- [
$ G2 A' q0 o6 T. E, I2 o // Get geometry set list1 r0 P, P, s3 I# V# K$ F
CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();
; D1 g: z' n3 j) a4 Y std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();
! m) h9 n, F; ?% x9 X% Y8 O5 |
9 c( ^+ y' C! Y) k& T g; z! ~; ~5 w" e" I0 v
// get geometry set
5 n8 p' L4 d* v( `9 @' V) ` std::vector<CAM::GeometrySet*>::iterator iter;- P; C0 k& I$ S, t$ J
for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )$ K% s, C" R* n0 M+ }3 o# U
{
( d' `1 h& B4 R0 i CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);
7 w, H' H4 r# r ScCollector *scCollector = geomSet->ScCollector(); 9 N* K% a& o9 a. ^7 M
std::vector<SelectionIntentRule*> rules;
6 S+ ?. W: }# J9 Z, G scCollector->GetRules(rules);% _$ O$ x+ g0 E/ Y
4 N$ o* K* v8 S% W3 h. Z* [% L
8 |8 O, o/ z. X1 A* n- a //get selection rule8 D; h; x" C9 `2 R! i
std::vector<SelectionIntentRule*>::iterator ruleIter;
& Z6 Y) D+ H2 D: _& T" B. F6 v for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )
; |' Q5 r! `8 ^. p# t {
( \! v5 a1 k' d! a& B5 [ SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);( _& N2 G" u8 X6 s0 `& ~7 A
NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();
* L$ Z/ J7 J( I6 i8 n# {* { //there are different rule types, here just use body, face as sample: z) _: F) v) B) E& g# n
switch ( ruleType )
: Z9 f+ k6 }. @- v% { {
6 a0 y- H# i( d1 Q case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:
, x( e- R2 M* K% v8 ~. J {
, ?( ~* l" R4 d //get bodies
+ Y/ Y$ S8 t b4 v' H NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);) z: {: Q% s5 T9 `
std::vector<Body*> bodies;- k& J' u) m6 {
bodyRule->GetData(bodies);
* _" T# ^/ E4 F7 b/ |* d; P std::vector<Body*>::iterator bIter;$ v6 ?, X& P" A: A6 _1 h; x7 i
int index = 1;
' a P6 c- B* n v for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )
* n8 V3 T9 v7 F; @# ` {6 l( e- l! n( m. I9 S) |
Body* body = dynamic_cast<Body*>(*bIter);+ d; r1 s! h4 W. |( F, ?1 D* K9 R
ObjectTag = body->GetTag();2 J3 L8 i0 F: W2 ~* K) m: q
sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag); " c# W# q$ h0 `+ P$ E3 _
WRITE(mesg);
, o" O% {- Y. H: I6 H9 _1 T- |; E1 U body->Highlight();" D ]$ s3 G' a0 \
index++;3 n- W0 P0 t% u. k
} [7 ]9 I; ^, A( C S9 g4 q: R$ {
}5 v" P% B7 T" t
break;$ Y+ `8 z" T% y8 a: f
w8 W! H; B1 ~4 x' b2 l# d3 X0 W
" q% g. ~+ Q# C4 J case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:
' L: ?0 }7 E$ r {
$ H) u( i8 J$ @ v8 [: v //get faces
# x9 ]! [8 X Z; B- k8 O NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);
]' X* B- X+ Z5 C0 T& d; `6 R0 l% g std::vector<Face*> faces;
, o' h# B4 Z( w( j$ y8 M) Z faceRule->GetData(faces);
& o: R% d; ]$ `% s std::vector<Face*>::iterator fIter;
) A2 W* a* ?+ L$ [2 ]+ t int index = 1;
7 v- q. h" O b2 z for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )
4 r" @6 d; d0 ^; J8 `- ?/ P- q9 K& J {7 Y5 ]" M8 ?7 b0 o6 l8 S
Face* face = dynamic_cast<Face*>(*fIter);/ d$ ^7 e6 e: B* x: v, J" m! ]; S
ObjectTag = face->GetTag();
% o* v. u4 {% k$ |% @5 h# m( w" G sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag);
4 i+ N3 U3 w- t) c, t+ I WRITE(mesg);
$ H( J9 z5 M4 u index++;) H N# j& |$ g$ r. Z& h+ V
}
; `/ n, x7 y& a' r }
: ^# L; t( ~ t% i break;
& K6 l N7 \5 k2 A1 E5 U! f; i i, U: Z
- C R3 o8 O- ]+ R! g default:
8 i( n# i0 Z/ v- z, l break;
3 ]6 t1 C6 y% |6 Z$ y% n }
3 v8 h* \: A' I: S2 w" F }& C/ r( u% i& |( i, W! b {
}
. T! F" H8 f8 L0 F1 ~& H, U4 K' Z2 T3 x
$ w+ J0 Q6 m% F3 R7 O' Q
5 D5 h) ^0 V4 X! |! T$ C# ?! t8 b- E0 _+ y
- U% ~9 @, J& j- ?* o: @; @5 T
" s* q [3 J# S4 B
millGeomBuilder1->Destroy();# P, F( Z& V! n0 @ b2 H+ C4 y
; }+ S1 v2 x G2 M, O" J4 { F; } y4 Q! V4 r$ X7 ?! p6 a
} else {/ z/ R9 p' o& X6 C
WRITE("type is not UF_machining_geometry_grp_type");
+ E6 s) G* ^0 @0 `/ K6 K WRITE(" or UF_mill_geom_featr_subtype"); e& e9 w& T3 A3 e/ V7 k9 w( s
}
% k" n$ N, M% e3 j UF_free(objects);
0 v# [0 t0 Q2 q5 f( ?
* f+ C! O7 ?6 l
( v6 \5 Y! y+ V( [4 q( l9 H4 G } else {$ F. Z5 p! I* A7 _9 p
WRITE("The number of selected objects in ONT must be 1.");: l! E. O. Q; S& g/ }# t
}5 v+ [% v9 k: b2 Q, C; s& l
# H$ \" g% s& R7 V6 c0 X! a- p
# A& ]2 `: N$ u: w" H( c0 i& I
}- w0 b0 z7 q, S9 i# y
P, `/ {# ]/ }, r
|
|