|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
# Z$ n9 G& a$ L$ ?% {
NXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值
2 I) Y$ i3 Z/ T6 b e2 O
+ {2 R% s, H7 g& p$ [ l3 Q$ I+ I# i4 J; d
static void do_it(void)5 ?! {' q2 }' U5 c
{
5 c s! u) p5 ^+ V% r& J' w logical is_initialized;& p- F$ `) v6 X1 j/ u% s, Z
int object_count;+ g' w: @8 i, \$ ~1 m& J" @$ j
int type;0 q9 E, B ]# X/ t# x
int subtype;; F& V8 a8 T/ g# B$ B
tag_t *objects;
3 a* c. D2 |# N/ g2 ^$ D2 S! e
9 p1 m m: w# G! D" V1 S3 {8 K4 l% [8 e3 s: ~# M6 K
# d% x% q' I7 u( A
' y$ g) i: A) J9 P5 Q# d. u* }% x
char mesg[133];
3 O: l& |4 p, W6 z; e# I8 r2 Y: e/ T8 |3 G
6 {$ y. c$ u9 m. y" s5 n // Get the work part
2 U! z% c4 n/ M- z Session *theSession = Session::GetSession();
) G |: s$ m% n+ ] Part *workPart(theSession->Parts()->Work());
1 F! ?. R% s0 q8 L Part *displayPart(theSession->Parts()->Display());
! T1 s: a% K+ x* H: I& ?1 M9 n3 A- ]
0 f, S; k2 l' j9 ?
0 {# X; y/ T& B+ W% I5 `' r" J0 Z2 c0 u5 C& `; y* s# |
* A0 Z8 `* a; A2 i
if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;1 L8 k) P6 @; a* Z; m/ w: p0 K0 y
* c/ ?- F+ `/ @8 _3 ?% Z/ k, Q
$ K( A6 y! T$ A0 x /* Get selected WORKPIECE object in ONT */+ w3 ?6 T" E* {" e! L4 I- ]* ~* g) L4 h
UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));
, p+ m8 A4 Z k7 K) }& j
( e1 k& `, E' ?# e- w1 `
3 f. [5 l7 S& r4 e) ?$ m" P, b2 A9 A. h
& A; u; f* Z7 E2 W* Y; {. }. l if (object_count == 1) {$ u( Y1 b1 e+ f1 `
UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));
' d. Q5 n1 l1 m: B: q/ D0 s
2 b2 H; b4 F9 N# F k# R [9 U7 W( E# o2 F# W
! w$ N# U6 W: e9 ~4 x. ^! P1 w+ t! F2 n
if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {
! h1 b& X/ A% F' U s9 W6 U8 X8 x# L( g0 F3 h
9 H; s8 ~9 B- s6 V' c
tag_t ObjectTag = NULL_TAG;, g8 G9 P- \; E* K9 O
9 E0 j) ]" x, U( \7 v
3 S( |- t7 E+ {7 R* }% V5 B7 n
// Get the object from the WORKPIECE tag
5 j, i7 @& R0 s0 B$ {0 y; ?( { CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);
" ?4 H4 _: C+ V2 V! P5 _( v' X9 Z% J) `
2 f( ]- F; ?2 u2 P, i$ F+ h CAM::MillGeomBuilder *millGeomBuilder1;/ b/ v2 g2 p+ z C X
millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);- k# h& K/ `; k7 P; j2 u' t7 ^
- s% Y* _6 D% P' |
& ~2 O' G; P; k q6 d
// Get geometry set list3 r1 m+ d6 Y% u- o A3 c6 r
CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();
- \: M( K8 P) O& N( \ std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();! Y5 c% i) B# `5 F% F4 F9 N: T
. d l% v+ q2 h( b0 a+ U, N6 u
6 k. B3 i& K2 N% T* T5 J! Y // get geometry set
# z" f6 C# J N+ u7 Y! z std::vector<CAM::GeometrySet*>::iterator iter;
d( d4 ?# U/ s9 i; G for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )
9 x/ I. l4 t: ~; K8 h, c( [' n( Y {
e) q& b+ i9 Q, L+ t CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);4 X# [, l- M* G/ k( M. F
ScCollector *scCollector = geomSet->ScCollector(); 4 R, s6 U/ n4 \1 c* p" a& K+ g
std::vector<SelectionIntentRule*> rules;, V7 L2 e8 l% q- e) s0 i% `) K
scCollector->GetRules(rules);: @6 X x0 c v& U+ b/ c
, O9 l! Z( ~- H7 ~ Y2 Z) @
: x0 T% r* j; R; ?
//get selection rule. X8 s/ B# ~8 m% m# e
std::vector<SelectionIntentRule*>::iterator ruleIter;
1 z# H d" s# r+ h( Q for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )# \8 `0 E9 K* Y% k$ p
{
0 Y. u7 F8 @5 C6 z4 x SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);8 w s" R: s! V6 ^6 U
NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();; ~1 Y+ a8 i6 m4 J+ Y! C: Q
//there are different rule types, here just use body, face as sample8 f9 o/ J6 q* ]/ {
switch ( ruleType )0 ^& V& V& w [" ~4 A, W& p
{4 z \( C; Z% g3 R# j# j
case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:" d% a4 m2 q: x: {* S5 {( ?
{
( L. k; }5 W+ [) r //get bodies 3 O4 W* Z$ W7 Z5 \. ]; ]
NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);: E1 b+ K: y. ~" f1 {
std::vector<Body*> bodies;# m& K4 J( P$ V
bodyRule->GetData(bodies);! Z' G' z" I1 v7 B
std::vector<Body*>::iterator bIter;
5 k3 U& j L- F/ k9 O int index = 1;
8 q" `+ @/ ]' V2 v; @. G for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )( t( L! y5 S: I0 T- @, A$ Q
{4 v8 A& e! h1 b* X( n, u, i
Body* body = dynamic_cast<Body*>(*bIter);
. p% |3 Q! K) z/ `6 f ObjectTag = body->GetTag();
0 e- _3 z1 i0 H sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag);
" Z/ O1 `3 S+ N1 g+ F2 u+ F WRITE(mesg);
6 @3 M3 U2 C' x6 U! { body->Highlight();
0 N7 q% b$ N0 J index++;
) f1 F4 M6 m/ {" q7 G) R- v" a+ b5 [ }
. b" M5 K! I2 l D+ I5 @ } `) e2 G4 s* k0 i6 l. V
break;
" y$ j0 F5 M' b; W3 b! m2 k; S* R/ j) r0 q8 y; P: s
: H& r+ ]8 q3 y, a case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:
* X# {( f9 O* d; @5 L {7 c9 h) P$ f. F7 Y4 G+ w4 ]" ?
//get faces w* C, z7 S t6 g& I
NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);
/ M8 N6 O6 @- H# P1 S% Z3 M std::vector<Face*> faces;4 O% z' e! E0 Q8 H
faceRule->GetData(faces);
! y3 u1 ~2 b+ { std::vector<Face*>::iterator fIter;/ {7 n& H$ E0 n4 G9 Z) F1 M0 a5 c
int index = 1;, U, X# |) d3 W& d: c9 D
for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )
- X) \7 N/ h: H* v( m {; P0 m7 f7 T# A1 M
Face* face = dynamic_cast<Face*>(*fIter);" B- ^: C1 L8 e/ H' H
ObjectTag = face->GetTag();5 f* p( J' a4 v* |
sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag); ' G$ F( U, c2 A$ |2 \: \2 C1 ~9 e E
WRITE(mesg);
6 B' g- r5 Z. m( }4 u/ W index++;
1 r ?4 R' ^6 ]5 V) J2 b }
3 C' I0 I! c9 K$ x* d ` }6 u2 b! O$ ?; B3 a3 K% _1 w& y: l8 {
break;& G5 @+ J7 _9 P5 K" O: v2 y+ @2 k
6 A/ I- T+ W( Q2 [9 o1 E! G
; ^6 K/ ~& `2 P8 ~7 @ default:
3 D$ s0 t5 V( ^3 W* ` break;1 X6 {) w: n" p: V
}6 Q: t0 F9 _8 }9 [
}
: j! X" s! I7 u( ^9 B& E8 @5 o }
4 \$ v1 z* j: x$ b' O! a6 H. E( ?: i. D3 ?; \
0 H& B) k9 }; _1 }4 V) b8 i6 e' {9 L0 c
d3 A% {; R9 l' O9 \ O) V9 Y$ Q
$ T/ S8 Y. e" l r
% h. q, p: |7 n6 @ millGeomBuilder1->Destroy();& W; ^ G' U/ ^4 W+ l$ D* l
' h! ~. }. m/ M3 I, Q
\; P# C; h9 F6 F& ^ } else {
9 y& f1 X8 A3 b! }( e WRITE("type is not UF_machining_geometry_grp_type");# i, i9 i! p5 b7 C
WRITE(" or UF_mill_geom_featr_subtype");# c8 ^( g6 \5 d5 G( f# o9 B( s
}
/ u: G& x. ]. `* |1 H' J4 w5 s UF_free(objects);
! F0 H, N- V2 L- V# R* l8 }2 t
; P5 G5 P2 T6 d. b: D9 b& R. Q5 P. ^0 Y. b* ^3 B: p+ z! L
} else {: i1 Y/ u) I( f, @+ c7 y
WRITE("The number of selected objects in ONT must be 1.");
; y8 B5 U! Z% ~0 v c4 K$ n3 W4 z }/ } n# b U6 H9 Y. _
& N8 P( Y+ _% A
: X! J/ b1 A+ X! E! m4 |
}
! Q. |5 I" d# |# q9 ^, m1 w$ B
2 {, z2 T% t; F' w9 a7 N. n% @ |
|