|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
2 H) G! `) r q* a3 ]: D! v7 Z
NXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值
1 D! T! [ }% c! U/ `2 d: ]3 n. N8 W/ h% c: \3 i
7 w4 u% |6 E# pstatic void do_it(void)) K1 g: P Y3 D
{+ z4 A" p/ `( j. P3 i' K
logical is_initialized;
3 v& W6 t2 N7 g3 n0 @ int object_count;
' l) J9 F! W. y, ^( [% A5 x6 t int type;
$ @- Q) _8 s& [ int subtype;
1 U) h$ U' i2 P1 ^! h1 L tag_t *objects;
/ F0 {, M) y, f# z& @' V+ v4 t0 ~0 ?$ i8 t' s N" y3 f2 @
) k) l/ z' n1 Y, w5 c
6 E$ v6 c* _8 z' d
9 W `$ e7 X0 N7 H4 t5 O' Z char mesg[133];: T0 D$ Q9 Z) E7 y. \
5 d" E7 L' j7 N# q
& x/ X) o& X* C# A% U2 m5 @ // Get the work part X" Y8 n9 Z# l# P1 c) g N
Session *theSession = Session::GetSession();0 _3 b" V( f5 b% F; C3 I9 N# G
Part *workPart(theSession->Parts()->Work());
0 ?/ `5 q) [' I Part *displayPart(theSession->Parts()->Display());# T0 m! k* _4 A2 ^. F" o4 `8 H
+ `5 v; v. G: i7 H, l
( l) L* _6 J0 U9 |. I# p( c: e8 r4 E# I1 W# l2 N" v' B% r; H
9 v+ w% K7 }$ Q) n( L/ u
if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;
4 [5 S R* @% J6 G, P
0 ^; _" s; m$ \" t) e
8 g. U: @9 l. J5 F) N: @5 x /* Get selected WORKPIECE object in ONT */1 g: i0 p* t+ ?- O' `( m
UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));
, K4 d5 n6 V3 F& ~9 @& m% F+ r+ D6 ]" R# Z
( a4 P1 {4 l5 P h/ e, z, i, l9 C* F. S+ l& o
7 w4 O' s) \: U8 D' S* a! g8 d4 ] if (object_count == 1) {
. Q: z8 r; { z$ y* v/ X: u UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));
; i; B5 P* W, c) ?2 J; O& X
1 K/ p2 Q% x# W- ?( H* H9 ?" @2 z6 K' g% e( P
7 N0 x2 M5 G+ d
% g8 i, {+ G4 R" Q; }# F
if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {
' @ i$ O# ~3 F8 Q0 N3 L% v6 E8 }) A
' V' R5 b* r+ {9 ]" v, c, b3 ]
/ z. t' s+ U5 p( h9 O tag_t ObjectTag = NULL_TAG;! S. ]5 h F& }0 Y2 T9 B/ R# z) t
9 Q, P6 i a0 K0 r; J9 }, D7 t! n" _/ \
+ o2 b6 c4 @9 d0 z
// Get the object from the WORKPIECE tag
' }* A. V& F$ |1 a; ~ G8 f1 I3 J$ ? CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);% |0 k% J T- n; k- _5 `
r+ m3 [& o. v$ ]9 Q
7 |6 H/ h% o a4 | CAM::MillGeomBuilder *millGeomBuilder1;; E- n9 H9 Q; B/ w
millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);& U" [5 n* ?2 q$ f( s" |
' s' _# o. C- r F
`9 Y5 t* ]( j5 q
// Get geometry set list# a" J; f' ?# q& d
CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();+ S! [- ~6 q% F. m k* y; P: X
std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();
2 g# H- \3 P. L; N& l* j F2 C4 X$ l8 J1 R. ~* V" D$ G: e
% c9 B1 i }) b0 j% C6 ` @; D5 q
// get geometry set
0 O- P* f- i8 Y: ], H std::vector<CAM::GeometrySet*>::iterator iter;
0 Q8 a. K; y9 `! M& n) S4 D. J for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )/ P: U+ W* T" Z. ~9 Q i9 T
{+ v% F. e: I! J9 B+ R9 H
CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);& f2 q* ~& G4 M( k' _
ScCollector *scCollector = geomSet->ScCollector();
$ X; Z$ ^" f4 }& d. U% A3 c6 ]7 y std::vector<SelectionIntentRule*> rules;5 |, _7 N5 F: P2 }
scCollector->GetRules(rules);- [- c a/ B' F! m L
9 @1 k% K. K9 P; A
' }; O: H3 H; K+ _7 E+ [8 j //get selection rule
, E! X8 A/ D+ V std::vector<SelectionIntentRule*>::iterator ruleIter;5 z7 s: s' ^4 Q: Q
for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )0 L& t6 u- c; [) U& k9 W1 V
{3 g% c# ]: P( C* l/ `9 U: x
SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);
2 \( q M0 |, \* d5 u( F7 a NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();+ _7 V, x0 k2 D" j
//there are different rule types, here just use body, face as sample. j) ^' a5 i+ D2 n$ D3 n
switch ( ruleType )
& R! ^- d" n \3 n+ p {2 c7 \7 A0 k2 Z9 `
case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:! l9 z/ Q' C: z5 o4 w
{2 M [& ^+ k; \: o& n. j: p
//get bodies
* G$ ]3 P+ V' O5 O2 ]. _ NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);
% P5 Z' {0 V# u" w' P$ _ std::vector<Body*> bodies;1 s* d' {7 E1 q, x" a3 U" E
bodyRule->GetData(bodies);' a, r1 N) \! H0 ?; ?
std::vector<Body*>::iterator bIter;
" J5 |9 w; T# `) \, u( i1 m( o/ u- P int index = 1;$ G D9 a0 a! _7 i
for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )
+ {1 D. E7 F5 T* x; T {5 [$ l6 H& t$ R" c1 a0 S- s6 i4 J
Body* body = dynamic_cast<Body*>(*bIter);
. F: `. ~6 S7 m& H! f D( X% c ObjectTag = body->GetTag();; x( r* P( T7 M+ j+ k) Y1 U: b
sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag);
; S* _: b( n) Q* t WRITE(mesg);/ y ^* f( M1 @; Q
body->Highlight();- V6 O: F' F* g3 O. I; y+ U
index++;' N8 d7 Z9 x, N/ B S
}3 i' P* v8 k% e, r& i- k
}
g2 r! i9 L: J% o" ?5 D- ^ break;' B. S0 U6 }, F1 ` ~/ T. @4 Y& J! \
/ z3 l6 D1 W6 ]8 h. O
1 u3 w6 E: C! I- L/ ?; v; W# a% Z
case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:8 h8 g$ T( A1 J4 `; a
{- K- H2 t0 h0 }5 F% Q! _( M& w! F
//get faces ! @7 x/ g+ j9 z: |- |8 a
NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);
( f. O4 g3 z. E# b& S) t std::vector<Face*> faces;
5 J3 t+ S: O% F' E) k1 X faceRule->GetData(faces);
2 d* ]9 Y% |9 X4 k; p! H/ Z std::vector<Face*>::iterator fIter;5 W' J" j0 V; q1 n) o; H
int index = 1; h+ F v! |) C0 J( N
for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )
( k- v$ `8 c2 M" l4 F- o; t {; m& C' ]* G* i5 i/ P% d: p
Face* face = dynamic_cast<Face*>(*fIter);* E4 |* G7 x' E8 K, K2 s
ObjectTag = face->GetTag();1 b4 W& H% B6 r) |5 d: {, l! Z
sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag); ! X& }: ~' V+ Y- g- M: P
WRITE(mesg);) z$ P( m+ j3 c+ H. ^4 l8 Y0 z v E
index++;
9 a# Y p$ V, `' u, t8 s U- Z }
9 Y" m6 W2 ^7 ?% b% ]' z. `1 d }+ w4 M: X7 w6 |# n! \9 N
break;& S2 `! m! Y+ \% G9 j& U
n1 b. W! u( J$ T
# T( ~* ~% ~# ]# R: g H
default:- X8 Z3 v; ~) G' \2 W* ~
break;
) X* V6 W) d) g. [6 o$ e }
; r, n9 Z2 J. } }$ `6 s7 Q4 j8 F( \* P9 G; u( l: q* f
}5 m1 G# ^7 Y; y; z" q' S4 {
" Z+ t0 `& W" o/ W6 ?4 S" |) |! b$ U* {6 O: g) r
7 b4 z# E8 W2 X# L
/ j3 G* K# p* m# `9 J; {5 d7 B4 B7 H3 v; z+ r* H8 `0 r* ]- [
7 Y6 u" r& Z6 u; s% Y1 B' @1 C millGeomBuilder1->Destroy();
& O0 ?5 Y: l# l: x
2 {& f4 s1 E1 _- O6 K
3 M1 j) l2 U; D! B, f } else {" V( N! D3 c& H% T4 M
WRITE("type is not UF_machining_geometry_grp_type");. e$ r+ x! u' t
WRITE(" or UF_mill_geom_featr_subtype");
$ @7 h& m9 |2 r1 ]- ?, n* @ }, j# i3 O8 u g2 c Z8 b! T
UF_free(objects);4 K1 Y- |/ H" M( p# u d. R
4 J5 `0 o" P" D( m3 t
: t- T9 y% |# X1 I' U- S+ |
} else {
# A1 S5 y$ }: i3 O: H WRITE("The number of selected objects in ONT must be 1.");
" u* Q; ~- F$ @. J( c }' ~/ M- O' l d* |4 {
- a2 o; N7 N: z4 G( R1 @- a, H0 R$ K3 R. S8 |7 h
}
* C0 h0 x* L6 u6 U" P5 T: Q+ s/ e: G1 s
|
|