|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
. o- r/ @* W( T) K3 x7 l7 |NXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值
; P, J* ?# l" p& z2 K+ e }' z$ n9 v6 F3 g5 p) U1 m
6 k! h& N, \, C$ X# N5 p. I% ustatic void do_it(void)
5 z: O, B! d p4 U5 x{
; F( }4 J# } |# c0 a' h: | logical is_initialized;
\( \$ k3 \0 R int object_count;
0 Z* y' b% m4 H4 W) D* x int type;% ?3 r( N$ g, `3 B. X# A
int subtype;
+ W( `$ x+ N' o: Z tag_t *objects;
; G. A3 M. P, o; [0 M% Q6 f0 r& D! n5 {. _; o' I
R, S& Z' s* V0 l. y) E% b
+ \1 j7 w- o5 u- E3 i6 e' U( l0 j- X7 d6 F3 E% V, V+ u% Q1 [
char mesg[133];! c) {2 C; T3 }7 T
+ ]9 S! K0 Y( H% P3 r$ g
& t d! `, d/ A1 w& r9 y // Get the work part& ?& y8 I+ E+ J
Session *theSession = Session::GetSession();+ n. ?, C5 Q E
Part *workPart(theSession->Parts()->Work());' C! n, e6 {4 X0 n
Part *displayPart(theSession->Parts()->Display());
: o7 S$ N' E, y+ D5 H+ p( F
+ q$ m( a7 o, p& ?
6 Z* K$ }+ c- E0 x8 s
2 D+ f+ k9 Q+ z
5 B" V) r+ Y" M( z Q# J7 s if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;: j# T" U. t# |! b
8 z+ _/ G# O$ d; p1 K2 u
3 h0 L# K7 Y! b7 r, R /* Get selected WORKPIECE object in ONT */
% l% T- V0 o+ x$ d3 A UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));
! ?) t$ Z4 A2 {0 m! O2 z! r: g
' {- D1 c* }& q' {% _* S n1 ]% R" O0 N- G5 h8 n+ A
- C# g4 _' `* q$ Q
5 B, c& w- p" n- C if (object_count == 1) {" l' o+ `3 A0 q3 W; Q9 u) k. Z
UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));
. V' R7 p( {. V' {, T7 y4 F# E. W2 I# Z
& W4 J. \3 O5 f+ o5 D+ D8 O6 m+ `) t0 z/ {0 Y/ ?! T2 F+ j: g7 K8 Y2 G
- _; Z' h) N0 s9 E5 W: K% T5 Y
if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {1 x6 n% }3 x: }" @3 t+ i% l
; q2 l% R, x( i$ f8 Y8 w/ S+ l, [& z1 B
tag_t ObjectTag = NULL_TAG;" h! Q7 f% R: m" x9 F0 l3 ]& t
6 j' I1 {6 R7 E5 D1 Y0 g% R
" o0 T$ Z+ q5 F' m8 p" K& c7 } // Get the object from the WORKPIECE tag; n0 ]$ s/ N. P" [ N' D9 L
CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);0 y3 q% T7 ?+ ]# T
0 g' Z& @- g \) \% u9 a* k
( U1 ^) h B, j) S CAM::MillGeomBuilder *millGeomBuilder1;
9 c4 _2 K& n; S. p0 o: Q4 l* t millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);. a( n; A! r2 S, p, Z2 X2 V
o: t/ g: M9 B h+ `) b3 N( g$ t% J$ E& n
// Get geometry set list: e: q7 e- j$ o$ N, h2 y
CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();) @3 g# O, G; k' ?9 U6 b4 n, B- |
std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();+ c" X! i' p* n% z( Z
3 J! U8 j' C+ w V
. `; y/ b( B0 [ // get geometry set
9 T8 `2 N% D' O std::vector<CAM::GeometrySet*>::iterator iter;/ K) q( i4 d* B9 B b6 b4 R1 m
for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )2 w* x+ b; F9 A; r: K
{
3 d. Q* S$ _6 j5 W" j CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);
5 Z: l. l2 c. a4 m ScCollector *scCollector = geomSet->ScCollector();
3 S( w7 O/ I; l- f% A std::vector<SelectionIntentRule*> rules;3 N! R/ e' u" Q; k6 f) Q5 G
scCollector->GetRules(rules);
2 Z4 W; [: w: _6 B X" m9 N$ n+ Z! ?, I! G2 e: O
) } U- d, F, I3 r' C" n //get selection rule1 ~; F& o# Z6 U* i
std::vector<SelectionIntentRule*>::iterator ruleIter;
2 Z3 v0 t A- T5 ^ for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )% c$ |" {* H8 T+ m# r
{4 x: \" b J: @# n6 J3 D
SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);
" \* C# L5 C& J- \5 ~; C NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();% ]8 \( F y2 p+ b/ T' P
//there are different rule types, here just use body, face as sample
& k% M9 w* f3 f& S& ?7 v switch ( ruleType ): K7 _* y/ C6 h) \( W
{
: {6 |- H* P/ [1 J& U* ~, ` case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:
( Y5 {7 m9 b u% a* p; { {' i0 b3 q$ s5 p( o3 Z {
//get bodies
, P; G0 w2 k0 z" \; F9 P7 \1 q NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);5 G: q& O2 v( D1 @
std::vector<Body*> bodies;
$ ]; `& m) m- | bodyRule->GetData(bodies);9 {0 J6 D/ e% |# R, I
std::vector<Body*>::iterator bIter;( r9 k( E. I$ G( a% P, u
int index = 1;
4 ~- x; C) e4 D4 k9 A for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )' b! }. r( h: a5 Z, `% U
{7 i p; Y! V: Q6 k# ]% N, F
Body* body = dynamic_cast<Body*>(*bIter);8 G8 j0 j5 M/ [5 y0 p
ObjectTag = body->GetTag();
* J; ^: P0 ]+ ~$ j4 I. E sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag);
; R0 s$ h$ f/ R. b# w/ I WRITE(mesg);6 u S, `4 p" _$ X" C3 O4 X4 N
body->Highlight();& ?5 m' l" ?2 L) E) [; h! K- B
index++;$ |* @8 A# ]9 N& X) w, U9 `
}
% ~4 j( g# x& [4 v. ?& j( s }; Y9 ]( ?/ f& j
break;
5 q+ _% M7 C2 a% a0 ~- h- q; R* x' W# m4 H, ~
/ y4 B. g/ o u) m) k9 }% T. q case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:
. f# V# R4 }5 \( Q0 B* e; p8 o {! z* v& v; }) Y
//get faces
% a: Q+ m3 w, s3 Q( T' y NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);" \; O o) }1 c, y0 l" O/ l6 [
std::vector<Face*> faces;
- w( F! ^, E w: Z7 _3 Z faceRule->GetData(faces);' G8 R. ~! b" s% n8 f S G
std::vector<Face*>::iterator fIter;
. F7 S; ?- o0 n7 Z/ p8 n int index = 1;
, x( K- T3 G# E& J: w0 N) z for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )
4 x2 Y6 ?8 S5 w/ V+ \ {1 _! o3 V. r. j! Y" R' m
Face* face = dynamic_cast<Face*>(*fIter);
: R( i T8 e) [9 ]5 A0 s- L0 p9 R* ~6 U0 H ObjectTag = face->GetTag();
2 }) W; H. T- _2 w$ G; f; U [ {6 ^ sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag);
9 V7 \7 v% X; J! y! A7 C WRITE(mesg);
2 m) D `. D/ \8 }* N0 j# G1 N index++; ^0 D( Z* a4 i2 F' w
}& X3 E' P/ I% U4 Z
}/ ]9 P7 g8 K; U, {( f! C& Q
break;
+ P1 C" Z- g+ H% i9 A' z! K1 T5 I. I% y# F
5 @9 w/ t5 D2 u) O default:
8 B1 W5 y8 y" w* b1 `% ]. V break;/ O' U( E7 U- [$ V3 C5 Q2 r
}
/ W( x. j t, z3 d! y1 V' F }# `3 S, e3 i& v
}
) P7 [: l! ~% J, P2 ^; E" c. r* N9 S9 c$ h, C$ e
1 g; b g8 p( h$ u+ ^& T7 ^" J, K+ \9 b" _4 |! z- p! n6 t6 @0 A
" o0 y4 S$ D: ]2 b+ W8 y& V% l: T" d4 N% R
- Q5 l, u% ]6 A7 X) Y' u
millGeomBuilder1->Destroy();
, u, [7 w; [. v, o4 J* v0 \' k5 {' q1 k
# w8 @# p6 R! x' |1 K$ \ } else {
# m( R2 f2 D( u7 C. K7 M! C6 @ WRITE("type is not UF_machining_geometry_grp_type");
. `, b; x, T( H: |. { WRITE(" or UF_mill_geom_featr_subtype");0 n0 ~0 y, {3 c* y1 e7 |( b6 C) d
}
! a8 c1 o Y+ s$ f$ v) V$ m UF_free(objects);: k$ `3 v4 } j9 A6 q4 p e
2 r( N3 o1 e* A, D
- A! U7 Q; I5 I1 f( T) g
} else {
- N$ p8 J6 @7 R! @ WRITE("The number of selected objects in ONT must be 1.");: C- L! [9 a& Y, f! V8 O
}! P3 \% b% Z, C
$ Q; e* X, X7 j" y4 {$ j. D5 D- j4 r0 s: M8 W6 _* P1 ] Z+ `3 ^# w
}
z7 {+ D7 {) o9 c
+ {, V' }7 F( x$ ^3 B |
|