|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
% W, m# b$ n0 c1 k6 V0 \. ~( @3 GNXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值0 `3 |& s% Y, F3 {' k
1 t- B' W* U- O. x6 D
! @; R9 W9 }, I7 G9 P- U! sstatic void do_it(void)1 |, n$ F) j" L5 u& \* D% p
{" e# D- ]7 N% \$ P
logical is_initialized;
3 W, [* y( t% [& f- r [9 {, C( i int object_count;9 O$ z3 Q9 \' \3 H: C- G$ _
int type;; J- S0 I& a, \! ~' C& A* O0 ?
int subtype;0 F5 J# |7 A% O4 z/ M+ V
tag_t *objects;1 a% Z% H. K- x
* f' z! A4 ^5 i e4 u) v$ \1 O! Y1 |0 ^
8 h% O: A0 F; @( m
# S, d. r: L/ p2 {, r- Y char mesg[133];, r# T, w, @1 |5 B& n# `& i2 T
0 X& [7 g- ?# J. u
4 A' B# B- n4 ] n2 B // Get the work part
2 S* l9 @5 Y Y( { Session *theSession = Session::GetSession();7 ]3 P* Z0 K( s( j
Part *workPart(theSession->Parts()->Work());
9 n5 p7 @. H- L Part *displayPart(theSession->Parts()->Display());# @- ^- r3 o5 Q8 E' ~! j
+ {# I$ s O& |5 ~
: R( Q" p" _7 H: _* k7 @' R2 f% H( k" ^ U$ N- r7 T2 p
& O5 M+ t4 k4 n) C O& n/ G if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;
% @2 b9 v/ A+ C# Y) o+ O% l/ t5 Q4 }5 o! w: F5 R% i8 ? I
4 `( ^8 \8 N4 M /* Get selected WORKPIECE object in ONT */% a& n) e) h+ \( |: q
UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));
/ L7 S; C g) b; g. V5 I+ i+ p: {% h+ e" A& Y# `( [: L
2 o K- j* {: J9 r
5 _ g' r$ `! V) M
$ v o3 s& B$ g. r2 a1 m, b. d if (object_count == 1) {
9 T Z, ~* u0 X; }9 ~7 N UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));: b; l" f% u' Y. C/ q( o
, }; H" K" R3 d9 ^6 R; Y& D
4 ^( l0 x+ Y4 L* ]: b9 P$ ^
% z$ H* D2 _; n% I% D }& p: Z9 h# ~8 R4 K: m" h2 C
if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {2 L0 W% |: v7 b
; e; D' B% C* |6 W$ Z! O2 G
* h! ^& v: X. f9 i( u- l) a/ g tag_t ObjectTag = NULL_TAG;( \- Z* p: C4 b5 Q9 K1 m, p
- c* a% W% P+ |, ?
9 O. J' I. q$ X3 S9 `$ o // Get the object from the WORKPIECE tag
0 l; J0 {2 }. r CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);8 F( C7 w" W( D0 u$ T# m0 z, k! V% V
( `1 N4 ]# A5 _; W, H
' p- ?8 U. Y, n" A CAM::MillGeomBuilder *millGeomBuilder1;! @) F8 m$ X' d- E& n+ g
millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);
; n, X4 B! A, t% T( m ]/ s9 o+ [
# a7 [( `' m4 p7 n0 b# U+ J- ~% H+ S! b& ~# R
// Get geometry set list5 S; ^7 {: {! ?/ X. v2 D
CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();
, V/ x3 m- R) i- v std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();- _/ e1 `5 a' M# d2 p
- @1 O( x- O* r( C, G+ j3 @. h9 C; k- o% G( w& J
// get geometry set
5 ^7 b. {, _% P4 p std::vector<CAM::GeometrySet*>::iterator iter;9 [2 t% z4 m/ N1 S' E" ]5 T0 ^
for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )
. M4 h0 z4 `! [" A1 h. s) {7 q {
: L% r# Y; a+ J% y4 z; C: X* b& z CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);
# {9 N: `0 m' @! _+ k. d) R6 |( |$ r ScCollector *scCollector = geomSet->ScCollector(); 4 ]0 [- b- I' _/ K! @
std::vector<SelectionIntentRule*> rules;
* o/ }( h/ i; Y# K/ Y scCollector->GetRules(rules);# c' j5 o- {' c, P
' R3 D0 r L, Q
( d8 ]* |8 S5 y+ E
//get selection rule; g" T2 A$ m {6 \7 I9 \
std::vector<SelectionIntentRule*>::iterator ruleIter;
% [3 {# Z( B" R for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )
Y( q9 B, q& v0 `3 | {
6 e8 N% E) E# [( v* w SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);
4 _5 u+ A% o8 ^1 d NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();7 n- |/ H4 f3 z% k, y6 J
//there are different rule types, here just use body, face as sample, l3 n8 L0 m4 \& q( h
switch ( ruleType )2 ]& H; @" u3 z; R" ?. O
{8 u5 a- D3 d' B7 i
case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:7 r% x1 D. [1 \4 I1 B1 z
{
5 ~+ m3 t1 K7 ]$ `0 I" P //get bodies
6 ~( y- N6 _" v NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);
* ~: Z% C7 f% R std::vector<Body*> bodies;
+ B0 S6 P# P: O! w$ ~% W bodyRule->GetData(bodies);
) ]0 _& Z( p1 K# F0 {% J" B! ~ std::vector<Body*>::iterator bIter;
0 N2 i/ ]& P0 @# x4 w: ? int index = 1;8 T7 w3 z& _% I; a% o+ y
for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )
, A1 S/ n( S! O* x4 g( B( {& K {& z% |; U# b! s# f
Body* body = dynamic_cast<Body*>(*bIter);
$ |( s2 g4 B" m! G q7 ?' I2 ^ ObjectTag = body->GetTag();
. r l1 q: e# r7 G sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag); / ]6 H; ^7 y9 u# c' B5 C$ U
WRITE(mesg);! V- g e' C& H1 p& }
body->Highlight();. w! |% a7 q L/ {% i$ B
index++;; V" Z5 K, F: c8 _
}
9 ~1 W. c' a1 F }2 A) x! T( Q, ?( y% S& K9 `
break;
) x1 e4 E0 D* |- @
& o: g2 y" E9 ]0 c0 v" Y
& Y" w& e' q; ?2 d+ Z O case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:
8 I+ l3 r1 H7 T( m {$ O# G5 v+ { v% E/ {. ^
//get faces : M7 d+ f; O5 _2 S7 S
NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);6 W$ @ X: \# h7 X! f
std::vector<Face*> faces;, ^. f$ l, J: E6 y- x# i$ ?0 d2 U
faceRule->GetData(faces);; j: t, u5 j$ @. y& \0 K
std::vector<Face*>::iterator fIter;
) Y1 ~" q2 N: ]8 X2 m9 ] int index = 1;1 g0 r$ A- A0 |* _' X& P4 N
for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )
5 O+ u: u, [, R, m2 Q1 T { O L7 X7 \ ~' z" T% B& e9 w
Face* face = dynamic_cast<Face*>(*fIter);
) D! s1 y" k; F6 ], }8 t6 z" s& c ObjectTag = face->GetTag();- ^5 e5 {0 b( a3 G1 l N3 d
sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag);
9 y# H9 Z$ o, n+ ~* |- @' O WRITE(mesg);
) W9 q/ p x& P+ ?1 `) A& W index++;
" j& O+ V1 _/ p$ i: j- Z }& Y4 x) Q; v% R F F
}
" Y5 T5 \, x- | break;
X) e K1 m- X/ h
! h4 O- N9 `7 ^! v! A0 j
5 e6 O9 Y {3 L1 `8 K default:- t* g+ t- E: k9 v; ?
break;8 W9 }0 [8 i, x7 E8 ] H
}
1 i- Q) l! T: ? }+ u2 b( l; B, r0 u- Q( m5 ?8 i
}8 ^* a+ P0 W, w' [
% ^; @5 j( i% X0 C' M& y7 Q; |+ D5 I
% h; @7 b5 t8 j/ ], I" }( ` u) v" A3 Z0 l
) y F) `) U: I% s
& |/ N) G8 p7 X7 C" |' n# E# U1 R! ^9 u" s0 I: a
millGeomBuilder1->Destroy();' \) V: M' m+ `* Q4 {+ @3 y9 x/ F
; A% b, ?/ [3 @8 g
- o" b7 ^% j Z9 ]
} else {7 U. w3 L3 P+ s% {
WRITE("type is not UF_machining_geometry_grp_type");
3 p8 }+ j; S- v" U WRITE(" or UF_mill_geom_featr_subtype");* u- D' ^- _/ _6 d
}
/ ^! s( K9 n* q4 s, R. ?9 T UF_free(objects);
6 H2 m( _. @6 `% E6 _, W$ c* z9 m% o) o; }( D! f* Q" g/ i
7 a9 A/ ~. I" p/ ~4 }2 v) w5 w } else {
/ {8 T& Q% T4 s; \3 W+ G+ p* { W% T WRITE("The number of selected objects in ONT must be 1.");, D3 p0 ~5 ^' ]& `' x
}- }9 k- N& s: ?6 ^- p
- U( B0 L9 j' z
# `& x* I0 S8 B' w" C: J}2 T) R+ g2 S0 g ^4 J, u( [1 R
; T, ]( r9 }6 I' u' A) w4 z4 w2 Y |
|