|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
- c- N( b/ b+ @6 J+ d4 f7 }NXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值
' F, b/ M, L% i- f+ p( Q
3 u# i) n- C, x. s: f1 [$ j. A
$ I$ k, \. O5 u; O9 {9 c* istatic void do_it(void)
3 d% S( d H% y9 g; q- r{) R5 u/ Z! J; c' \! {
logical is_initialized;8 {( C4 E* n9 h% @7 L
int object_count;
- O0 _" T) P! W int type;5 [7 A3 s/ M$ V+ i
int subtype;% F3 y, j$ g" m
tag_t *objects;1 O4 s3 }3 E$ x( M" J4 a9 e$ |
% S/ x/ T9 e$ d; C R3 p, [! y7 |# O$ H6 ]5 s" M2 D# D) t7 j5 q% Z
+ L& s# R3 ^2 ?% d
2 a9 }: z7 s; x( K$ ^ char mesg[133];
' r4 Y1 b& ~( f" e/ Q& t z$ T$ X% o7 ]
' L8 `$ W0 _# [% \
// Get the work part
5 s6 i" h/ j2 ]6 y7 E Session *theSession = Session::GetSession();
6 c# y) \9 ?5 L( R4 b$ \ Part *workPart(theSession->Parts()->Work());; X K- ^7 l1 _6 n
Part *displayPart(theSession->Parts()->Display());2 o7 S7 ]# ?& g8 s6 r' W
1 {+ w3 |+ W8 T( D0 z- s
`8 b, R! k( G1 b9 i0 o, _( h
' d: C. _" l" ^4 J' l1 `5 }; B8 t* q1 D
if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;) w/ O( [5 ?; v& t f! R: g
! b' |, ~( r- g9 G( L7 t l5 F! z3 J( c1 S
/* Get selected WORKPIECE object in ONT */9 h$ p; @! Q i- j- N' K1 g
UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));! q8 `, u/ C; z
! E! W' Z1 {) d8 ~: U
# O! C4 z T( y. F& B7 }6 r" r6 k* B" J- ^- @ J' T
) t0 f3 V* M4 w: q- n
if (object_count == 1) {
% X' Q: S3 G+ a- U' X9 r( n$ f8 Y UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));0 P0 G E: o) K# M
" Y9 D+ d, z/ r1 u
; N! z: a& f/ A
7 L3 n; ~; U1 B- U/ s
E6 d1 c/ p' N* o& h" u if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {/ N% d! x: J5 h. V
2 L7 ~ d: f- e
% s+ U+ p, d7 f: ], R1 v" a
tag_t ObjectTag = NULL_TAG;2 n1 D+ n( d! @+ R6 p( W
, ], H" \1 J$ k: ~* v6 H1 B8 N9 z
" S) j8 S! ^6 N0 D2 p: g/ U // Get the object from the WORKPIECE tag. J8 g7 x( z% g0 g6 q
CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);) B: M" [! S: ~) \! U0 \0 l
2 i% n# W! a6 Z! [; F3 C
3 d- g) M2 r. B
CAM::MillGeomBuilder *millGeomBuilder1;
* b, D2 o2 @$ r millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);
" L) y4 F( q) c8 J/ ~6 A# g) ~- |' }: W
( m$ C4 ]3 f6 z% F9 |" g' W // Get geometry set list* F+ { n0 R* ]4 Y" w2 q
CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();8 C% G+ M$ m$ M% `5 ^- p
std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();
: w! v8 f' [. t* Z; H
1 h/ T H& g" `) t' y$ d
; b+ ^, _, u9 F b // get geometry set! _6 I" y; P0 V* u. U4 ]+ A& [7 C
std::vector<CAM::GeometrySet*>::iterator iter;' `; C$ h% `$ @+ R& s
for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )
& N; k2 d4 G( O {
5 }/ Q$ v" K! @; X' v$ P+ Z0 m CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);, t* Q8 P1 V3 f$ F
ScCollector *scCollector = geomSet->ScCollector();
& ?! e9 m6 t) _2 m std::vector<SelectionIntentRule*> rules;3 H8 B2 v; l9 P9 E$ H9 `
scCollector->GetRules(rules);% ^" G0 ?) u6 i2 \5 P7 {2 }
) P( ~+ u$ r' a$ J6 o2 w
: t8 z# Z* ]6 Z; t //get selection rule |% _1 ?3 r: i: B
std::vector<SelectionIntentRule*>::iterator ruleIter;
6 c7 c; j0 ` v for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )
2 z3 m( m# b2 t. `) f1 n8 Q {! V6 K+ {' B( ]# N4 m% Z5 T" K
SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);/ p0 @, a6 D4 t7 h
NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();- j4 C, R- K* x! n( w
//there are different rule types, here just use body, face as sample3 o! \6 k" a3 Z
switch ( ruleType ), m5 m+ ?! ~4 h# v" M( }
{# A+ B, m) S2 T: G5 H
case NXOpen::SelectionIntentRule::RuleTypeBodyDumb: T; v; Z" B! Q0 r$ I
{( O5 q2 g7 W" g/ S
//get bodies
7 S- ~ \; y E, b NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);
2 ]( Z+ [* p) v" H4 j7 o0 \' Q std::vector<Body*> bodies;, P, I4 e( `: K8 l( q( f4 i
bodyRule->GetData(bodies);+ J0 R I+ ^5 `
std::vector<Body*>::iterator bIter;
. ]3 N) O6 _' @1 N: k int index = 1;
& q9 m/ y# D8 [+ g for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )0 G0 q. k+ F9 ^$ Z% [
{! Y0 I# T1 W, K( A( o& {% d0 Y
Body* body = dynamic_cast<Body*>(*bIter);
4 `- c" r5 d: P) U ObjectTag = body->GetTag();
y0 u% u) e' ?& Y sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag); ) Y8 L$ b5 |$ R/ R# ?9 @
WRITE(mesg);
6 [! p' o- v5 ~# m% `' U% D body->Highlight();
A6 s" q# E+ a ?; u3 X4 V, W" _ index++;
s/ l6 s- \$ P7 i }2 A$ i$ d( T; b6 ~+ h
}
, C& P9 D+ e8 Y* j4 K. p break;
- v8 a/ o' d6 l# @, y0 D& K( l- ^3 d3 W( V q! F9 c
S( v' I c) W; ? case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:
0 r& f: a$ |: v7 O# d6 S {& N$ i/ Q8 G- Z9 U1 y6 j5 v
//get faces ' `: {+ `/ y' M% p( P/ e
NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);# m9 s* p6 z/ H/ u( {* p" Q
std::vector<Face*> faces;$ T/ R8 P! X; G/ f( Y
faceRule->GetData(faces);
. i+ G# Y/ A2 Z- y1 X std::vector<Face*>::iterator fIter;( d% H& S6 s' ?: h" C# A9 y
int index = 1;
0 I; ~0 E8 j" c6 `$ g. Q' W& S for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )
( Q% Z% J1 \; S; }, {# p' R) u {, T! K8 S. ]& g) Z! k
Face* face = dynamic_cast<Face*>(*fIter);
* ~+ H& k% N& R# y5 d ObjectTag = face->GetTag();) q( X1 j& N7 M" U& M' c" y% H& [
sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag); 4 h8 E( d \) U
WRITE(mesg);2 h8 ~8 v( ?* D; O
index++;* q b7 D2 b( G' V6 E" Z
}1 s- \3 H6 H) E! U+ Q
} @" K' C9 x/ t* R
break;. e9 b) p) K$ P
" O, j+ `" t% ^
' N, d( ]. [- j7 ^# n6 P( |
default:7 W0 C+ K0 O' m* {3 m- j
break;
0 R! W" t# M8 S j' R4 H5 N1 R }4 W. l$ N& S: c
}4 S: x, r1 I" o: u* G, X2 I0 Z9 q
}
1 e% x! W: Q$ C! s0 O; t/ t
' s. m+ g7 F5 H3 x" p
, d& x5 y; g( T9 M: T E
* S! B3 k; d# r( ]* f" f" n9 A8 o# p& s0 e% a( L; `
$ A v" p6 ]$ W5 X; y) n8 ` S) P% B' Q b( s2 t8 S% h9 |
millGeomBuilder1->Destroy();
) r3 r9 C& \; S
: W* t1 M |' I! r0 q, \; c7 \7 h( m, c u2 y; i9 D `, @
} else {7 n+ Y" V2 Y+ x/ m) l+ O- Z; y
WRITE("type is not UF_machining_geometry_grp_type");% ]. |4 r: ^% k4 _1 M# M: q0 u+ S
WRITE(" or UF_mill_geom_featr_subtype");
+ h9 ^" ~3 l9 w( X/ a } u; i; m) a. J& \0 m6 H1 y. Z
UF_free(objects);
! ~3 g8 T j( s1 W- }1 r% S+ {
) q- {& \8 ?1 h! ?& X$ P5 n; }# ^5 S1 I4 Y* w8 R2 R: d
} else {4 s# B+ b9 a- Y$ [- f4 E2 S# y
WRITE("The number of selected objects in ONT must be 1.");
* x, b# M- g1 S: z6 W }
" a. `/ f5 p+ N# x2 o/ ^7 y" W" h0 O( M% p
5 m+ U+ Q, ]: T. o! ?}5 K7 }7 F& A# T
" c# d/ R: O- ^ |
|