|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
, p! w$ L( _: O7 c2 @3 JNXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值
/ U. B M' i: X% r2 r( O: s$ s
& ]& Y8 a' V% L. K/ P. c1 Lstatic void do_it(void)$ l3 \, N8 @: W4 r$ m
{
) C; f X% c' |5 } logical is_initialized;* x# W7 T* T# O4 ~: G5 ]7 e2 N( u
int object_count;# M7 r: i: a" R& ^
int type;
3 n. @& j9 u, q int subtype;+ Q% _2 p; I: q, N7 _
tag_t *objects;
6 O9 o4 q" f( k* T* ?
& S# O" |( r5 I- Z# v) a/ n$ A
$ P4 q) t d# T2 O8 `
5 x$ ]: a" I9 `& u% ]* Q2 j+ g" U% ]1 V3 ]+ o. T& Z
char mesg[133];
& Q0 p( ?2 {" ?% u2 q0 L I9 i6 V7 S1 v6 g$ d' D/ }: |+ x: {5 M8 W
* d5 r/ E# ^7 H( { // Get the work part$ Q* ^/ F! Q9 X/ C
Session *theSession = Session::GetSession();: w V) W1 W. m J, `
Part *workPart(theSession->Parts()->Work());
V% b5 X; _+ P3 H8 K Part *displayPart(theSession->Parts()->Display());' n( a8 _$ S3 ?* f, A! p! K6 R [& r
2 q4 s. e( }5 _0 ?% l5 m# o( R+ }
0 b1 H1 T) l5 h$ x
) v9 r' h6 ^- j/ I/ O5 u
$ ?- X+ b. C) o+ K if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;# Z$ ?; A, q6 ^7 Q' m4 X$ L
2 ~0 ~+ `; i; c$ G3 r/ F0 h5 n9 q5 {
/* Get selected WORKPIECE object in ONT */
% ?& t* B& K& d# N `" P& m4 H UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));' m5 j. y- q6 I2 y! s- Q
; k7 P J8 j- _, a0 w' ?
6 R% A7 t; w/ y# c* c
+ o4 y a: A' B, x' S
# L; u/ p. R2 p( c6 |
if (object_count == 1) {& F9 m! A5 ^" [. {6 J- S; P
UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));
! E4 ]1 G) S& U; R; y- B, m
: N4 L8 j2 Q# s9 [' p9 _4 L: n1 @/ K$ G
l1 j2 ^2 Y f& e! J$ L
8 F; I% t. H" d9 j: ? if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {9 e# v. J7 f# b w9 |- c: i
% a/ ~+ e; o" t( C
2 h0 x6 V6 B1 V) W
tag_t ObjectTag = NULL_TAG;
& }# E9 C# r/ X) x' _! A% x; N8 s7 Z3 J2 Q# R
5 E4 j) j! f& a2 ?+ L
// Get the object from the WORKPIECE tag
0 d% F, t& o7 }0 _' O CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);# {' ~/ O6 f( e( i: S
9 S- \7 Z* M. o0 Z2 X7 D" R
( a& t$ R. r" q& D" v CAM::MillGeomBuilder *millGeomBuilder1;$ l4 g' p* e }' Y+ q) U+ L* f8 }
millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);
% B9 b) |1 m" L
' o; k1 }5 e% O" {0 o2 V0 N( m2 c2 Z5 q$ v9 j
// Get geometry set list
- _1 m2 M- P. b# x CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();2 {3 Z2 K( ]; ~% d
std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();
1 ?% u) n8 [. K2 A
/ @; F) r" x. {5 A1 a" ^. e) _
3 i' X3 N5 {5 x1 k0 m% m // get geometry set3 d+ J) N# g, k( t1 s& F
std::vector<CAM::GeometrySet*>::iterator iter;
$ O; }* A+ p( X- Z, M for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )6 f0 f9 D( u/ o( m8 {$ r" o" D! ~
{
- [. S7 d" r# Z) e; C/ W F CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);
& U. M1 d ? o1 |0 o2 }& } ScCollector *scCollector = geomSet->ScCollector();
) n$ ~& W6 J9 U7 Y% l) I std::vector<SelectionIntentRule*> rules;
) x4 \7 J$ J7 d scCollector->GetRules(rules);
- l5 |0 W4 ?* s8 X1 Z. ^- `$ E- x0 q" [2 N! O& @/ K
1 F. r- k9 W( K1 A) @ v+ B
//get selection rule/ K; K Z; x c, W: s' G4 h
std::vector<SelectionIntentRule*>::iterator ruleIter;: t! C* R& @% m
for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )
, Z$ o' P" p5 n7 u% ~ {
9 ]) K. _" p/ P3 i4 Y- a! F# x/ h SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);5 u8 v7 T" p0 O& ~
NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();
1 [. Y6 U) [5 u6 D0 o" e6 X' F //there are different rule types, here just use body, face as sample
9 f& H& ^, M8 Q# y4 h$ e `4 Z j switch ( ruleType )' W9 A0 ]0 B9 Y) v
{
- w" R% I1 t' f1 |- [0 g7 D! _ case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:) \+ k, `/ \/ y1 q' |1 E: Z
{& p" H0 E. t3 M# J
//get bodies
1 p/ f! O" C" E! ]1 \; R NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);
* R ]' x" T( {- g std::vector<Body*> bodies;
: p/ ~$ j% H( j0 F! ]0 k& Q& G: W bodyRule->GetData(bodies);3 [% G" x _6 D
std::vector<Body*>::iterator bIter;" s( R1 N- r) } B0 N8 T* l/ G5 Q
int index = 1;
/ e$ c/ R0 j1 S: q! v0 F+ k for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )
% R6 j, c# p% [- o& p% t {
& g1 r9 _ h* j# n Body* body = dynamic_cast<Body*>(*bIter);" G) A; |0 I I! e7 p
ObjectTag = body->GetTag();& \, [4 u. K9 I) z0 T( g
sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag); - u* M% ^* T, E, j
WRITE(mesg);
. \6 U5 Z! l2 P body->Highlight();
% P9 S# w1 Y1 N4 ] J4 g4 H index++;
; D. m$ b% x1 G }
% ^# i) k% M+ Q( z! u' l, ` } }# @& G2 L$ d0 C; t
break;
$ }/ M+ n3 K* F# [
" R& Y1 h8 {- e& ~. y1 @! b) X, a5 N6 ~$ z% B* [0 j/ S0 m g- V& [
case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:/ j( d7 v5 ~7 S$ o) O
{" Z6 z4 { R o
//get faces . l: v! I- a5 |, {5 U, q( w; b
NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);
' u$ Y& g$ D% K+ W4 F& s ^5 E std::vector<Face*> faces;: L( v8 y0 q* F- J- t) a! W
faceRule->GetData(faces);
. ? L' S7 m) ]$ Q/ n, j std::vector<Face*>::iterator fIter;+ w4 _- V) _6 }- Q; N n
int index = 1;
9 i5 M; u" G: y7 ?8 h for (fIter=faces.begin(); fIter!=faces.end(); fIter++ ). L* M* t# ?3 p' e
{
) x6 S1 t$ S& V" Y7 [: i; F Face* face = dynamic_cast<Face*>(*fIter);
L1 r3 g6 d7 ~5 N ObjectTag = face->GetTag();
3 g5 g1 w% I k+ E) C9 f sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag); ! U/ g" i+ N8 d1 m; Y) O" L
WRITE(mesg);" Q% X& I3 j$ @( r
index++;
- z$ h/ y: F+ M, j4 D: J }
! a. E" I( R3 b+ i) F% D }
- x0 d( I9 ~/ a) C break;
8 V/ }& T# |7 i# I. x! G* h1 k4 K1 R4 X
) A! L) ^. c: P* ^
default:
/ ]# S; C/ z. Z0 F* X U, n break;2 \; x4 l5 ?9 J, V ?
}' S, B+ G4 Q8 X$ f- o1 B
}4 h8 X- T7 y5 c% {' C, R
}- V+ z* k/ Y: Q4 H6 ]0 N/ v' }
* F& j6 Q# g; O' b; |- n$ m1 w* J2 s, ~
, A) {7 S4 p" r m9 S# C" V
% b) q( m" x5 Z) a/ x
& u* V7 A/ g* t$ r- G# l, k
! m+ C5 a! l, }8 f" Z2 X# m millGeomBuilder1->Destroy();
; w2 r9 I. q5 O0 c1 A
, ~ J6 L7 {+ ?
) ]# L/ t& |( ~0 y; Q' F) E } else {5 ~+ V; ?$ q6 W: D; F3 |
WRITE("type is not UF_machining_geometry_grp_type");1 c) ^* p# o: G9 \7 j d
WRITE(" or UF_mill_geom_featr_subtype");
8 y' ~9 _4 N9 y, Z. a+ G+ D! I }. s( g9 P! b6 }1 J/ {
UF_free(objects);
! S) E: ~- f6 W6 k w7 B C
, c( f3 L, g9 z6 {/ \
: F7 n c5 ^) {. z } else {
: g7 _' X) T: c' \& N WRITE("The number of selected objects in ONT must be 1.");
x' |5 {! K& t) u. z3 ~ }
`) b4 D& o E" P( ^+ \6 N1 I J# q6 T
+ r1 T$ z- K& k}
3 s4 }& J+ d9 {& h2 I
: k/ C% ^4 G0 I8 A) d1 `1 |: N |
|