|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
% W3 D2 E; K2 @$ @' B# [$ L) TNXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值
3 A: s9 o8 C0 @; i9 d4 ~5 |& x# L) h3 i. O2 G i
; o, v# K: r% c& c8 f' y/ u9 E `
static void do_it(void)
5 J6 \+ a# _) m# h; h, S' E{) W% g, C5 e$ _ I# N) A
logical is_initialized;
# L6 l( S0 C( m( L int object_count;- T! x, A# y( Y8 H; V
int type;
& K: f; w f! E/ ~, i) S( { int subtype;
3 r2 t/ h [4 s4 O tag_t *objects;
) f+ j' O9 U. r/ I4 a8 x) n5 }! m+ k" e
. w9 _: v: m+ M. v3 y
7 |) R. P, q1 G( D& T9 h/ M7 F3 U$ w/ g. M/ B
char mesg[133]; v2 _$ E8 }0 U/ j" E
+ v8 n, F/ v6 D H3 {9 u3 H' t3 D1 T
$ R# F+ b% M; o1 Q // Get the work part
% }# C, W& r5 f# } Session *theSession = Session::GetSession();
) t; u. B+ Q% ]% U E) }4 @# O Part *workPart(theSession->Parts()->Work());6 W6 o) l- `6 w" [; F& K; @0 H
Part *displayPart(theSession->Parts()->Display());
& r q* ~* A! F; a4 @9 a, ]
. w, N' r8 j, K' M$ w( o% L8 g A" l4 ?" Q% N7 y- O0 @
$ l% W$ p, u3 z8 q
/ L8 S. w: f/ O; n ?1 p# A if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;6 Z5 h8 Q6 S5 `7 X/ Q; G
2 W1 t% m% m) a9 @# C
1 p5 [- Z$ W7 h: m& G /* Get selected WORKPIECE object in ONT */
9 v7 p9 \' ^* j c; i4 } UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));9 O: P* J# \' n, m4 f6 S% u
x) N) ~7 J" h$ ^+ q0 v3 @/ y" E+ e$ W
8 H J' g6 A) i; J+ o* G* j2 d; u$ W$ x/ L8 d* `7 p6 I
if (object_count == 1) {5 {7 m+ L0 {* F7 c5 n+ ^6 j/ j
UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));
. u: I2 y$ I+ }( Y0 G
/ r+ C! n9 o! D% s& U. o0 d) a, Y* ]5 z# N3 t0 r, o
- R/ D4 r; S' Y. p8 x1 R6 X- c# |* t
if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {
8 h& {) o7 ]( G) g
( W4 s0 Y) O( x8 a8 P6 g$ t3 Y2 i8 j, L6 d; h
tag_t ObjectTag = NULL_TAG;: a- J+ \; q2 f& T* h
, O/ S4 V- N& U8 e8 N& V& U
8 k; G* |0 O" m7 ]* N; D
// Get the object from the WORKPIECE tag
. t# u+ F* `1 W9 U0 f. e CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);2 o9 S- d, q( g- q4 j0 z$ S
9 ~; S% i+ x4 a0 o8 v! x0 w' r; t6 e9 Y
0 W Q( a* K& d' P9 k4 } CAM::MillGeomBuilder *millGeomBuilder1;" @/ [6 W* u; w: q; ~* \$ a$ O$ N
millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);7 E! E1 Z! L& s* p
9 A8 j* E0 e( {/ y4 O5 X3 f% L6 B9 W1 |/ C: X8 o
// Get geometry set list
3 j' D! S8 |) {* f" O* |1 _ CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();! z8 i# \3 m# t! V8 @4 R, `9 K. [0 \
std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();2 e, n9 D: L3 o
+ M1 M @% R' Q0 E$ n' A
0 ]9 X; \# @' x7 a1 f4 Y
// get geometry set
+ B* Q0 s2 @: q0 \2 P std::vector<CAM::GeometrySet*>::iterator iter;4 L# n3 L; K3 }8 v
for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ ). k4 _+ I, Y6 D% L
{
j' B3 A/ @- O+ f CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);
8 \( y( c: r j! } ScCollector *scCollector = geomSet->ScCollector(); * O; T k5 ]2 ?6 w$ X1 N6 l
std::vector<SelectionIntentRule*> rules;
. W' I2 A' k& u scCollector->GetRules(rules);
7 F% x4 X; k; t( |" `0 ~2 _' R5 u$ S& d! N+ f
7 _5 k. C0 z, Q0 ^3 ~) Z
//get selection rule( @7 I& k5 u+ p
std::vector<SelectionIntentRule*>::iterator ruleIter;
, \4 h7 t. S1 M. q, R D% E for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )
% u; `- V3 R* i4 U/ k0 e {
8 l* r1 \. k$ k: @2 a. Z SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);) J5 J8 _% y5 y: w# r
NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();$ I: n7 d" N# \5 n
//there are different rule types, here just use body, face as sample
" p, B# P2 M# q; C. f! P: m switch ( ruleType )" ?( f& H. `" [% R; v1 V6 Y
{
6 D$ c/ N! T( }2 i: W7 b case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:5 Z0 [/ K* n1 ?
{) `2 W) R, d5 H2 E. t; ~5 @, a
//get bodies ; E* P# o" ?0 i
NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);5 g5 b, z. V# o- w
std::vector<Body*> bodies;
$ \) A! w+ ?0 _- l bodyRule->GetData(bodies);
* u: `* |1 r; n1 i6 ?; z- a: [ std::vector<Body*>::iterator bIter;
6 Z. g" H/ |& x. x( h8 _! C int index = 1;* G" l9 j. q+ [6 ~: e
for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )
) @5 B0 o+ T7 c. v* h" ~ {
, P! s3 n4 ^. H" m- t3 _7 |0 { Body* body = dynamic_cast<Body*>(*bIter);
- z. g' W& N' P% b0 R* E8 M ObjectTag = body->GetTag();
, y; l& W3 c8 [2 B# k& E sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag); ' W1 } `8 e6 ~. |
WRITE(mesg);# a8 F( m: v' R) }, i, L
body->Highlight();7 |7 L- m0 X" M) V
index++;
- |; S. ~& e9 } z# Y }
5 ?* P3 @$ t* J1 B0 m+ M }& d2 s: Q% I, V& k* Z. N1 K
break;: |, w6 A7 j( r0 |# A* F
8 N$ ?9 w9 u1 @+ }
! [8 [% P# w' j& A* X2 t case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:
1 M3 t; o1 e, T6 N. [+ ?2 ~1 W {
% R E) g% U4 V/ \ //get faces
/ A1 n7 ~, F6 }$ q/ g$ a+ Z NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);5 Z$ B& y. f$ u% K. o6 f7 z
std::vector<Face*> faces;1 h" s" |; R$ D: r$ Y
faceRule->GetData(faces);
8 R8 _3 Z9 J2 X std::vector<Face*>::iterator fIter;- `. i" i% ?1 ^5 ]* `9 J3 w4 g
int index = 1;6 y- \% q$ _! s* N K7 v" O( X
for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )
' n" F$ e7 W" o+ b e {
( |: _/ u$ b8 y7 K2 i Face* face = dynamic_cast<Face*>(*fIter); Y: ~! u0 U: p
ObjectTag = face->GetTag();
7 ^. }4 w/ M% y8 ^1 S3 H7 }4 X sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag); - t$ {* q) O/ I! E: O. o
WRITE(mesg);: \. |& J9 ~# ~1 O2 \
index++;7 a, r. S: ?3 e" d( i) p# d) I
}2 k8 b. j* f* z, P7 O
}
% T% e" V, x, \/ X/ T9 x break;
; S& k; U* c% K- B
, M' B4 z$ O/ U
% _% B7 d; c( b6 d default:( W. Q4 \ a! p; c6 @
break;# F' y7 q9 w0 b9 }+ F& `" W Q: w8 z
}
5 Q) h+ ~ {0 w! _8 { }( a+ \ }
0 k+ r- y" V# N& I4 P7 Z2 E+ n }
2 N, D' s, _1 R5 G
) H' F7 j8 n. K! u& ?, ^# x
8 K( L8 a: B$ _7 b' z3 y. \' ]
5 `% m/ z, h- X/ P4 L
! I Y& h' P5 {# G& g+ u3 Y w9 I, L, w9 X" L+ s: s
. W2 r9 Q- w/ t, Y* {0 q2 a
millGeomBuilder1->Destroy();+ V, B7 D$ C& U+ i) ]
" g$ t7 i1 X( x- G& t; O2 |+ \
' o# R2 D: ~' o } else {5 L; D! C; v6 ~- I B5 c
WRITE("type is not UF_machining_geometry_grp_type");, `! n* K) ^" F9 i
WRITE(" or UF_mill_geom_featr_subtype");, s! {4 j: ?2 K6 s5 L
}3 F" b# K. j/ B% ^
UF_free(objects);
; S- N. ] |* g5 b7 m/ P' ?2 _
9 n0 i& S* M% N7 o+ Q1 C' p X3 t
} else {
' c0 a) U6 _) R3 x8 N WRITE("The number of selected objects in ONT must be 1.");
! H' \1 w3 a- ^ a& ^ }
) u! D' G6 G( T% _/ L4 a) l% m4 x( i, }# V7 @6 R+ L
! d7 F1 p) h0 n4 m# U2 X4 j! n* P# _}/ `* _6 S2 G3 n$ N: P
m# `& L+ h& X# l- \
|
|