|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
, ?" z, P- M, M" Y* O$ p* [NXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值
3 W) m6 J# K2 M& \1 d- J
6 A+ H2 d' m; w* \- T% F# h; {7 m5 f3 d, N. w" E- O
static void do_it(void)
5 v2 [* o: B" n' \0 w; p" l{
/ i! @( f# [4 i logical is_initialized;
% j1 O% t5 a2 S1 } d. u int object_count;
! m9 Z8 J6 ^0 M8 E& z int type;% ~6 [3 n7 h F3 N0 _
int subtype;
! f. g1 n, Y5 }1 z. e4 w. I4 U; L tag_t *objects;
: C) V4 x% {! P* s
1 a/ d T0 A" P, T" A! q w8 w, h' `$ f, y# |% X7 O. s
% B3 M( q! g, V9 M+ l. |, V
+ H8 R. H* G, g
char mesg[133];( Q9 k# M3 s5 G" |: `
5 [3 J2 y* A+ _4 ?; n9 v
7 Y8 q6 D; M6 H( J2 {( K
// Get the work part9 J( M3 w2 p$ `& Z- G
Session *theSession = Session::GetSession();1 a7 J$ K5 v1 ^* u- `) V' J' g! R
Part *workPart(theSession->Parts()->Work());
! A% n O; K! h Part *displayPart(theSession->Parts()->Display());/ M- I; v6 u& `/ T$ |4 d+ C/ `
# Q3 M$ A1 i3 F- M
h: D: h$ X7 ~9 e' x) V# U- c# R: A" D. C9 h6 f6 @ j) \7 v( o( q
) ?3 g8 S1 T8 @
if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;; v# v& O* ^5 w% R: w! R3 V; }
0 [9 _. P( u J, M7 o! ^/ M3 S \& z' T
/* Get selected WORKPIECE object in ONT */8 M" z2 {9 x u4 O" C
UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));
7 U: v# K# }/ T
Q9 O+ J2 A( a1 g% G# G, H0 f( V2 @/ b/ `. q; c. m* Z6 V7 H: v
7 O! b) B# z* p0 J' L6 F
2 p$ R' x/ C; v1 m+ H6 m. W% D) T if (object_count == 1) {
: `- n6 ^$ l/ U; ] UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));
* X+ J' u) Q v. V; h6 g; C1 S/ o2 Q
0 j% x- X8 L. A0 c, B# D, p
( d! e7 h% y8 Q$ }/ |9 p9 i" R
" ~6 @8 n Y& n: e if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {
. \, u; h$ b/ B. D o0 C9 B% F$ y! g# [' K
* W6 { d3 @7 p. S" p- w
tag_t ObjectTag = NULL_TAG;) p! R& ^" X" D8 p$ N
; y$ \1 ]/ B7 S# N5 j
+ n% A" _1 u$ W# P) f
// Get the object from the WORKPIECE tag
7 x# x4 d5 {& k CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);
; U- J& {. }/ s8 T& y
# ^( i0 ~: r M. @2 ?: p* [2 ^( q6 n) j4 \
CAM::MillGeomBuilder *millGeomBuilder1;' L( y( o4 K5 ?6 R1 w5 \7 g* T
millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);
5 I+ l6 Y3 a5 l0 b2 X& K$ Q, V3 I& U& C$ ?
% L. V/ ]' {7 \% m& u! R
// Get geometry set list
0 u/ D5 T. s9 p1 r t CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();3 t( R# G5 m2 d* |! X' E
std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();
( A: [ `% }8 ?7 Y7 N- m0 P! s; U0 b* O; j
" {* }% H' Z+ y) _5 C, f @; c" D
// get geometry set
4 C) Z g0 ^4 ~0 L ]% h+ k std::vector<CAM::GeometrySet*>::iterator iter;
3 L% a3 k8 C, H9 M for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )8 Q+ z9 L7 s( V6 V8 J% f
{
+ b0 d3 T7 `7 r4 r/ t4 ~ O0 T$ J5 S CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);
9 t- w3 s @% ~- I ScCollector *scCollector = geomSet->ScCollector(); 7 G7 o$ ]# m5 h) g6 |5 q
std::vector<SelectionIntentRule*> rules;
6 v4 Y0 J0 o* a2 d/ w scCollector->GetRules(rules);
& h r" N: t) u# L0 s' x z: M: q* b" u4 j# I \" Z& S6 s% m" M
. ?( c0 a3 c- |7 j8 A6 W2 o) ` //get selection rule
$ x8 Z- P3 v* p( n! O* ~ y std::vector<SelectionIntentRule*>::iterator ruleIter;
1 o x; t1 r+ p2 a& L1 M for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )- J n- i3 |+ y+ o
{
4 N/ b: i$ ]) W7 p6 ? SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);( _! Y/ C% x' `, J8 c: Z9 W
NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();
: N2 Q) S9 R: A2 u6 G2 Q- H- l //there are different rule types, here just use body, face as sample
- i5 o, g- @, F5 W% F switch ( ruleType )
# @: [9 [' h6 W) \% L/ N7 M$ Y E {1 `0 B6 |$ S) Y2 e! k3 I, M
case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:. B9 ^( T: c3 Z9 C, D" v; U4 c
{
0 F8 ^4 o. m* W3 k/ y //get bodies
# ~: r% \4 S) Y2 c1 A- s9 s NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);
( G( E, f; |9 w9 O. f5 F3 l std::vector<Body*> bodies;
* r3 @' e% k" \0 l: f2 r, r; ^ bodyRule->GetData(bodies);
0 T# c) q% S4 w; \' {9 ` M: f( O std::vector<Body*>::iterator bIter;4 D. ]2 x3 U1 B' X* `5 X [
int index = 1;
# q+ h4 A9 v) ?3 B2 \, ~ for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )
$ g& Y' \1 M C9 k6 W1 b {; _- l) m5 `2 m$ [, j
Body* body = dynamic_cast<Body*>(*bIter);
# Y) a$ Z4 i2 M n ObjectTag = body->GetTag();8 V) r; p" K2 H! G2 T' f
sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag);
I0 H8 M! [1 R! u! g- r; H WRITE(mesg);/ i! X4 g3 p ~9 S4 R( q
body->Highlight();4 Q: M! w" @9 Y P% m
index++;
0 n4 x9 d% l+ @8 U' k j% @4 g1 j }
4 n+ O1 c5 B) K }. G' |- B) r% ?5 y
break;/ x, y7 T; d, H' U
: H4 \+ g& ~0 j1 q, b- |0 K( I
, Y7 h5 @' A& j _+ v6 g9 m& M
case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:! L# `( X! j- h7 N; p
{
. Z# k0 ~8 N p. p //get faces - H* F! v( W' b% d6 I& B
NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);
( m: V! a: q3 L$ `5 G8 Q0 B std::vector<Face*> faces;
/ n' ^2 o5 W2 b. n; F4 x faceRule->GetData(faces);" @/ s( |4 Y. k2 m+ b) i7 Q4 s
std::vector<Face*>::iterator fIter;% ^4 c+ A, n! ^& b
int index = 1;; f' K* R4 c! c- p( `
for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )
p$ M5 ?4 o$ H3 p# V7 ` {
& I* x* u) L+ q8 N& I: v8 O' R2 b) a Face* face = dynamic_cast<Face*>(*fIter);# Y+ }0 T: h5 w1 I
ObjectTag = face->GetTag();
9 z: d5 I. F8 \$ w; Y sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag);
7 E# s$ e( B: T6 f+ C3 t0 T1 n WRITE(mesg);, ^5 \2 d) u5 B: E$ B7 l
index++;2 _* x4 S u# |9 z/ x# K+ ^, [
}5 g. p4 A: y: c8 U+ [, |2 n! i) M# h
}" u8 S, q- g1 c3 K- a5 I1 c1 D5 H
break;0 Q( _) |0 |# `1 u
9 }$ H+ \' @3 j% l- p0 U' w
0 U4 |9 V3 u/ Y0 E C5 R
default:
1 } \$ i/ v- Q: q; H' g+ l8 U break;
5 J- n; _ L$ ?: w; h6 G }
; Z- u" \) g1 U7 u# h }/ S8 ^8 {) V9 Z- i
}
; `0 t" R" v `/ ^7 I. Q+ y* D
' h% v% ]: @( m; a5 L- L+ c" _2 h
5 W5 X8 i/ A3 {; M
# T/ v: Z) R) ]( r) [
8 o# ]/ d6 i) S1 d; I: Z" f millGeomBuilder1->Destroy();
! @+ H- p7 n0 j: q }. [; k1 c; P' D/ R& i* k
( z. s. L) ]& n+ D# P
} else {' Q' o1 C2 r2 s, _2 b1 g& ] R
WRITE("type is not UF_machining_geometry_grp_type");' o% [7 T2 g# G5 M. ~8 d4 ^
WRITE(" or UF_mill_geom_featr_subtype");! N+ s/ y3 @1 q; R- a6 a
}
" L; [) I5 H# j, G' \, Z+ o3 h UF_free(objects);8 l Y' |$ l1 \( S. L% X7 P6 E3 |
1 n# C! j" R* N7 l5 @7 s- M- o: B$ a% U/ `" c% _4 S' e0 c( y
} else {0 K3 b' C. V' H! z
WRITE("The number of selected objects in ONT must be 1.");
$ M$ l8 }, X- [6 K5 N0 u }! X: d n" B# |7 R
1 \' }3 U! p' n9 t
, O* C' K; `; s' V$ l3 b}
& O @, U# K8 X1 f
+ f! z5 b8 h' d4 M- E+ q: N' ]; I |
|