|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
$ v& b0 i& ?; S, w/ Q1 O
NXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值: a# E$ P* `, {$ }1 f3 w
) r8 w, k3 C: w F* s Z% U b2 S- Q2 u4 G# ?
static void do_it(void)- H: T& e" J- M3 T
{
( w# a! _+ A( `. I8 d1 o logical is_initialized;
( g( K0 y& c$ X. y8 g) y5 V" h0 `3 | int object_count;
6 P9 X; S& {' f) ]' }( A! C7 J int type;: L4 g. K* w# m- B+ X
int subtype;$ @' a" z7 {% g9 V, o5 ?5 {
tag_t *objects;
* B: S( B, Y& @9 Y1 o
2 p$ T1 X# ~' v% M
' ^4 ]4 p0 L- J7 x3 i( E2 j: _8 b' k- K# L8 t3 V
+ r4 W! \( w9 r char mesg[133];
3 A- s2 a/ R9 E! r. }- E3 ]' h* Z3 ~2 c2 y+ N* r; k. s
) m2 U3 g7 X( M' v5 `
// Get the work part- }3 }7 Y+ o; L- O" R$ K
Session *theSession = Session::GetSession();
8 H0 J, w. j; M Part *workPart(theSession->Parts()->Work());
" t6 e: r9 G1 b+ ~ Part *displayPart(theSession->Parts()->Display());
6 q. ~& d5 n3 Y7 }$ S% N: o2 e: a4 z0 X0 _
0 L5 f" V9 e8 r: @' r( `' }
% `* P! B: E1 L0 l& Z3 m# h w
# Y/ u5 I+ i' y if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;
" D2 j% _$ y5 k: N4 I' P
; i9 | F0 f* I+ T Q
2 Y8 x, C: ~& |% W /* Get selected WORKPIECE object in ONT */; X+ k8 G+ L8 `2 B, W( }) f5 ~
UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));" k9 U4 V: ~9 m/ s# L+ R
% v5 p. X J. m7 H" V
& A% D z; q( M4 d2 O6 e
! n1 x/ s$ T/ E& d j
, J( O9 f6 I& V; }/ m if (object_count == 1) {( ~. J. [0 w" G
UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));) u- N" m+ [8 }; |! U' u: q ], E
/ i% v$ e) D: h6 C8 C$ N$ ~
/ @( v1 [" {: `& n
% o6 K+ B2 e e5 P% o, q$ d3 F: Y
5 m* A1 \/ Z6 l7 \ if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {
: l, \, f' s, `/ w+ l
) ^' q* x2 k% Y: K$ a! T* x2 n0 h z" | f7 d6 W4 i
tag_t ObjectTag = NULL_TAG;2 h% l6 e$ l8 K! B4 k1 j) ?
9 Z; a2 B2 }5 d" b) k* c& D/ @5 ]2 |$ G U2 ^
// Get the object from the WORKPIECE tag
* J3 g- P( W- k! _# n* H CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);
+ n5 O4 O: O6 t' c% i; v
5 T0 e1 |* x7 i; z# h
3 I; ]. v; Y, G0 z; O CAM::MillGeomBuilder *millGeomBuilder1;
0 W2 ]: |% M2 J$ a) D millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);
& B6 D2 e' R, v# G. l% |5 j+ G
" W3 r6 k2 n K/ p: s6 Q4 d+ v
: C* Z3 P4 i l // Get geometry set list
( K) U0 \1 L* v1 F% } CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();
8 f. i. V5 Y& K: }+ J; ^7 v std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();
" g2 `1 T& w0 o2 S2 O6 j
' W* K& k: {4 }( a/ b; B% L% K* F) L% I T5 X
// get geometry set9 x6 F3 N# S$ C- b) T! A* {
std::vector<CAM::GeometrySet*>::iterator iter;
* W* N, d9 ]! j2 H2 W- B for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )
" R, G. S( q# D" z; i/ B8 u8 x, |/ } {8 B5 h" d; D3 n( W3 M
CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);
0 n# l* r/ E, T7 `1 E. Y# C( } ScCollector *scCollector = geomSet->ScCollector(); 8 g1 Z. K$ o4 X; k8 e, t
std::vector<SelectionIntentRule*> rules;; c+ Z, I1 l6 n+ K8 [
scCollector->GetRules(rules);
/ M2 \/ J i" P$ V& x
: t$ B+ C; v1 E9 _7 a- E$ r
Q9 E/ {+ r. ^ //get selection rule. v6 u* d& b: i$ K/ T5 ]7 c
std::vector<SelectionIntentRule*>::iterator ruleIter;) b& G; {0 D; J7 q
for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )& O' I# W: l4 Q( c
{
; n. M( c4 U6 f SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);
; F3 i2 k6 m% B6 f6 i NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();
: `2 \ r+ S+ T8 R9 P! i, Q$ m //there are different rule types, here just use body, face as sample
) c3 o& J6 c0 V) u: X2 `1 z switch ( ruleType )3 e& ~9 p7 h" M. Y' x* _# o7 k/ m9 d
{
+ p2 ?6 ~8 j0 ]& L* z& o8 M case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:
V8 |+ G# b. t' S {$ y) e. v( A( I) K- B- D8 e( J
//get bodies ( m+ F L% [2 y( ?# {' J: |+ ~
NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);$ F( ?# \, i4 B' q; i
std::vector<Body*> bodies;, v' o3 E5 A3 } O5 v% R: G
bodyRule->GetData(bodies);
/ Q9 V& n& b/ b std::vector<Body*>::iterator bIter;
5 V) q! n, f3 a% Q int index = 1;0 G) \ D& ]- Z, J4 E
for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )
( `) r G" F u# v8 | {
) i( i1 ~& J: e2 w. K/ e) r( Y9 K Body* body = dynamic_cast<Body*>(*bIter);- Z% b9 X6 n I& Q
ObjectTag = body->GetTag();) [4 X$ ~5 S% B$ j& b# [2 R4 E
sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag); - P5 |# [/ R! N" q; q8 Y3 k
WRITE(mesg);1 o6 d, R5 |' O; I& {; e
body->Highlight();# J! w& K+ \) H' c+ Z) i2 n- k
index++;* L8 w/ o$ D! K8 y0 p
}
% m$ @! K* c0 ? }$ S @0 \5 g$ r! l7 X, A W
break;+ N1 V" F, h$ U1 i( g3 Y
7 S" r w4 A) N- X: m+ B; h
9 m7 x: J; N0 ]% R! u6 E case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:
' k* d! }3 E+ l5 d6 u6 V4 U3 t {2 F0 A6 m: y h9 \
//get faces ' d! {: j$ F* ?6 k. c' q) h
NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);
" Y, f& M2 m& b, ] std::vector<Face*> faces;% s# }% j- ~9 Z; Z, l* v2 W d& {
faceRule->GetData(faces);
7 Q( T2 |# X/ n4 U" \ std::vector<Face*>::iterator fIter;4 Q* f1 H' v4 y. W) R* c; |# `
int index = 1;4 t e7 h0 i3 j u" M
for (fIter=faces.begin(); fIter!=faces.end(); fIter++ ); a! f- @' z8 k5 @. Q& D
{
: V4 ]- A. b5 V2 q6 W Face* face = dynamic_cast<Face*>(*fIter);
' x) t3 g9 D; b1 M ObjectTag = face->GetTag();% V) d$ M$ b3 w# J) a) X5 _
sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag);
) `/ @5 |* L4 M: g/ y WRITE(mesg);
# C$ [. ]5 _7 g' L/ [# G4 d' O index++;4 ?- Z5 q. r" {* t. n6 n
}
$ u: |, x; s3 G7 s1 @( v) ^/ | }
- W# Y8 D! _. w; K+ n break;
) ^* }4 q# E6 |0 C
8 g! T0 a* g9 z
y" U a2 B/ V- G default:( @6 c; K5 p/ B0 o, p
break;& e/ N( |/ T2 s/ o
}, D5 K* }& X) _; x9 D
}
6 B5 X) F6 ~. \! ? }5 b0 M/ \$ z0 I: ^/ C5 {- e6 T' F
: P8 M* k: v4 Y
5 \: i- F7 [/ y$ o# o r
3 ~. X* w- Y8 K8 c8 m
- ~5 m5 R% K S5 l
0 k* u: J+ \7 O: u
! V4 `3 \1 ]$ {) j( x9 T* J% {9 a: w millGeomBuilder1->Destroy();# b- O# N/ c: j, f" o
$ ^6 u. Q4 V7 F0 m
9 i) n6 |, J1 y
} else {
/ f7 _, T4 |. f WRITE("type is not UF_machining_geometry_grp_type");
+ r% ?* Y! ~# n$ i WRITE(" or UF_mill_geom_featr_subtype");6 e5 x$ \0 G6 f- {/ x1 J
}
: X/ \/ g# G9 C( G2 S UF_free(objects);
8 ?: X1 j1 k1 P9 w5 C. ~
% ~3 b* M2 |% t( g
, z1 u* ^- s n: {- G8 p } else {
- y' t) Y. U# }% R) e WRITE("The number of selected objects in ONT must be 1."); n- P- h9 j1 q
}
% R# c( \( ]) N! D9 S+ h' Y" |9 {
2 j4 ]1 g! G2 Y, ~2 f+ ^}
) W% H( Y( S9 q% B4 Q/ }$ x
6 G) U. A, R0 h4 O$ s& T5 ^) E$ o' [ |
|