|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
2 I3 ?8 Z# }, v4 v9 Q3 n& eNXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值
3 O) Z" u2 |7 h7 s$ e
' }" x# `1 D1 O! }; P
' l2 n. m1 Z8 }+ m+ Q: } Sstatic void do_it(void)
+ f& A2 t; A: R0 ]. L0 h{8 u5 H: B4 D! P- W
logical is_initialized;
+ C, i7 E! n# v int object_count;
- |9 v/ ] G# a u) o; H$ ?* a int type;
6 L' M- G) s0 K9 o" D0 n/ `8 V int subtype;/ t5 m8 o* U6 J
tag_t *objects;
3 ?1 \) ^4 N- k+ h* V! K3 c
3 j, k3 x+ x; h0 s( H
8 ?: _# v; D# [( H1 \" h/ D% u' y( ?; C
9 Y7 b* j! g. t6 V6 g) D7 h" U char mesg[133];3 A/ M: e) q2 K8 a( ~: J
) i8 I3 { _# A: M& E J
% y" F+ i, U/ {$ g4 M! R
// Get the work part9 f* }; @/ ~4 m
Session *theSession = Session::GetSession();, o T: i' o" T( \
Part *workPart(theSession->Parts()->Work());
; K* p/ Y. V. L Part *displayPart(theSession->Parts()->Display());6 q4 a7 x3 S- i0 Q
" G6 E& d! T9 z. L+ |
/ P8 m! ^+ e/ d8 @5 r% f' ^8 ?$ T2 W4 g) `
" m, [+ ]" ^7 K; H( y; C7 T+ ?& D) m
if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;
7 u2 T O3 J* h) I# s' v4 v* P5 i- q- v! ~- K4 ^7 E
2 w) G9 }7 L4 t
/* Get selected WORKPIECE object in ONT */9 J) O0 _1 g4 ^( ^1 l( G
UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));
6 A+ e# G2 c: D2 k6 r& L" H8 T' @3 N3 A2 J$ ~
& w5 @0 X1 H1 `, v
- S h3 a% U& W, |+ n+ W
, p9 ?. U9 M. e$ h% a if (object_count == 1) {; B' A. O3 o7 x9 z+ @
UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));: Z- U) ~7 g6 t0 t' W: V* L
+ D. p& x. p5 e: H: l. Z" V
1 N4 Q9 y3 w8 `, @& W
% _! U9 C9 h1 X8 a" C0 {6 S1 {* T
if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {
& H9 b4 x' X8 q6 A; A
( U h% y- j" G! i
2 [' t5 y1 d5 e tag_t ObjectTag = NULL_TAG;5 L/ X: U, ?; ?0 e3 _5 J |5 B
! N/ M4 x5 U! _' b. S% g% F
. A1 r0 `: _3 y) ~ // Get the object from the WORKPIECE tag
% D$ Q8 ?9 h! g1 K CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);
; W/ J6 `* @+ R% }& L* t7 F
# I; B2 s( F9 J: o$ l. ]4 I# z- \4 B% H. R6 k" [& t: K& z) h
CAM::MillGeomBuilder *millGeomBuilder1;
5 c5 z( r' {' Y4 G! n millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);
1 z! l6 A, h# j$ Y
; d, ~0 a) x. l1 T
7 G/ t- @; l$ @% a( e+ @4 c // Get geometry set list8 Y" Z% o; M9 K! K; L
CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();& N- E5 M5 W/ x. q7 i8 d* q! X
std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();
$ y& o/ v* D8 R; b! G6 O) {0 ], k7 U0 k* I
4 Q0 {. q1 p2 c8 \! q$ [7 c // get geometry set
0 ~ [9 q9 k1 m: Y- T4 @ std::vector<CAM::GeometrySet*>::iterator iter;
- V% A( v$ G: j& }+ @ for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )
. [( p: w1 g+ a4 S) L/ B4 z {
- _% k: s: A' [ CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);# o5 i' H4 \ Y, {
ScCollector *scCollector = geomSet->ScCollector(); . [& v. T% J, c% o
std::vector<SelectionIntentRule*> rules;& m& R2 c6 K: Q! q) {
scCollector->GetRules(rules); S! R+ M5 L+ [+ B5 B5 Y9 `
: I2 x' g- m! t+ D4 m
1 @: b4 s W- c' m, [ //get selection rule, T. ?$ A5 u$ k, W6 N- s* M
std::vector<SelectionIntentRule*>::iterator ruleIter;
* @' P4 t( c" @% L for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )" n, u" N' @: R/ I7 K2 s, m
{; X7 Y% J2 V! r, R
SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);
$ D1 f0 ~: J! v3 X NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();6 Q% }6 @) a' [: \, @# I/ u! B& f% ]
//there are different rule types, here just use body, face as sample
7 T l9 p0 y& q& S& F; E switch ( ruleType )
2 x+ a; j! U) r! Z# x0 R+ w5 h {% n( [( J4 F" I7 z" R; N
case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:( x$ y/ e9 M* f) b* L5 P
{
( P: R9 Y _5 L1 _# T2 h! k8 M //get bodies
$ |! j6 R$ Z0 c NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);4 O# V* }- c) j, K" J& z
std::vector<Body*> bodies;: O% C3 W1 G: ^+ r( X
bodyRule->GetData(bodies);+ i: Y3 c, ?' {3 f. T8 g; n
std::vector<Body*>::iterator bIter;
" r1 A4 C" X J2 B* J* g% g; \ int index = 1;
) A! n0 U! M5 P# V for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ ), Q" t O5 y0 Z$ H# N( L a
{4 x- n7 p& T) I- ~5 K0 \
Body* body = dynamic_cast<Body*>(*bIter);
, [) B( ]5 s6 F; G1 V) X$ b ObjectTag = body->GetTag();0 r+ V" Y9 C9 p" w
sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag);
# a, x5 S: o9 o3 r4 l c WRITE(mesg);+ _2 e! _2 p; k, i B( m, y+ j
body->Highlight();' j( j) g( s+ t/ @% \
index++;
0 H% o; B* b' @6 ^" h }/ N5 q' }$ V; D! h9 X( j# `
}' u( |$ }' l, V8 Q8 H
break;
% S, p3 G, V9 }! Z% N: m8 L/ q! D# Q) k% u* R9 o: i
% D, `* o0 S0 V5 ]- k! {& @
case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:- w0 j! Q; F% u
{
! b, C* ?( N( s( T; t //get faces
4 x& Y& _. @4 C NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);
( `% f* }, \2 h# f! [ std::vector<Face*> faces;
5 v2 i' q t: H# Q, \ faceRule->GetData(faces);
3 Z# y, V# I7 V0 E$ r- h std::vector<Face*>::iterator fIter;
/ C4 @- m- v' t }2 @ int index = 1;
1 Y+ L( t3 w2 A3 D$ z- { for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )) F; ]3 x, ], ^" M: u3 B1 U
{" i0 _, u' y' E! H; v' Q# _' N4 `- y
Face* face = dynamic_cast<Face*>(*fIter);" d+ Q/ w5 P- O
ObjectTag = face->GetTag();: }( c5 k, p9 ?) }: B4 H% w
sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag); . j$ i( w: ?2 ?; I, B
WRITE(mesg);
6 Z& e% W g' D index++;- n9 U* g! D/ B
}# ^, C' }0 s) d+ X$ q
}
3 p' f6 ]1 `4 }; S+ s break;2 Y5 l+ o, K, w: M) [* H6 P
! i, x- _7 S8 v% d. h1 a
+ j& R9 v) r: [
default:0 h5 I( W- t5 W* R% ?2 c3 X( j' @
break;
) q$ ^3 u ^( o4 f }
! A, C6 G+ V; a7 X* H% G }
, L8 @, |: s3 j6 Y }
4 E& p/ b. H+ J) Q# z4 M
5 D- b z+ @( n2 s; n u4 F0 |* `4 w+ [- ^! `' e
# p# P8 h% G( ^7 X5 J8 h! ^8 f
4 n+ x4 |2 \; |$ C$ [ [: k! M% I9 ^8 _
( y2 }! W4 r7 s; B0 R* u4 w8 M7 l# |& ?/ ^8 _0 Z
millGeomBuilder1->Destroy();, t5 @. O3 k4 k1 x" [
5 q$ t3 }) I3 f4 v9 q3 u& Z( a, Q/ @3 w
} else {
* H- @; z9 @' f( d$ @ WRITE("type is not UF_machining_geometry_grp_type");
' p" \# z3 Z: U6 C! [2 } WRITE(" or UF_mill_geom_featr_subtype");
& N# e( q5 y4 O; F6 H- x }8 c7 N8 ^: O5 n
UF_free(objects);/ M9 E; `" j o% I
: `' _* E$ A; d$ y- d4 w
7 D( ~# d' C4 j* n2 F } else {: |7 Z( p0 ~% A5 f" s4 v$ Y+ [
WRITE("The number of selected objects in ONT must be 1.");. J/ J: v+ U' ?, a. J4 V
}
+ ]( p- F2 D9 K! P. m" \; }0 n- T, c! u# ?4 h; Z; g
; y5 F% q. g3 S( ~# B: k. y+ T}
) h- E3 M5 v" K& o& _
/ z- A, C& t v# q! Y# B |
|