|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
+ n3 F2 [. t6 b+ b0 `9 P+ q6 _
NXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值
! u6 g. t" I/ i; d6 X8 j. a8 p c/ J6 _+ F5 W" D
( p- e* T# u; @0 {0 s0 ~5 L0 e0 a6 E
static void do_it(void)
3 |1 }$ ?/ v) e& ^4 O# }% l5 X% i{ u: E! d5 y" n$ o5 n0 c4 G$ E
logical is_initialized;
) e/ X4 S( v+ _: }; Z int object_count;8 }6 b& a% Q6 s' e; X
int type; y8 X' R* j, t7 y5 c. `4 ~
int subtype;) R% g( R7 z z) _
tag_t *objects;
5 i& C" N" z6 z! r( U$ h- N& d6 j/ I/ I* s* Q5 p! Q
3 B; v8 l$ A8 A/ b3 @0 m5 @
' t" C6 \1 ^1 c q- r: r
- a+ u1 e% j' \& e j. N char mesg[133];1 K' J6 n9 O9 S0 v- h$ u4 I, ^
0 T4 `' t4 v# S o$ \+ r% |6 t
% v3 ~$ v8 v6 Z- f' N // Get the work part
3 d8 Y2 G* B" b% V Session *theSession = Session::GetSession(); n9 ?4 A5 ?: E/ n) o w
Part *workPart(theSession->Parts()->Work());. j& d! ~6 K: y
Part *displayPart(theSession->Parts()->Display());9 Q% D7 o* J$ o. p! ^
: a; ?$ R# R; g6 D% T
- x8 b' ?6 {/ O! s
1 Z& t# u1 I+ M4 `2 ?. m5 L/ E
& B/ y2 y- q6 {& o6 f8 {6 X if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;7 o! H6 i! b, W2 ^' z$ s- h+ @$ [
+ e. P- o7 G1 e9 N% q
) \; F6 q# K) J7 N! u J /* Get selected WORKPIECE object in ONT */1 { m; i) p# f" H- G0 d k
UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));
( ]9 L% y$ ]! s7 I: e# G
+ Y* R) P3 n' _' y& o& I1 O! v; r' x- B# k0 u* U
3 b3 l% i0 A+ l9 k" _7 u
1 B$ ~7 y8 Q8 ^% k
if (object_count == 1) {
8 o3 P$ s% W l ~ UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));
) H9 D% x+ N0 D1 o+ h1 ^4 B6 x6 V' F
b9 Y2 T9 i$ T" O. Y
( z" L0 [, o. Q# O! f! J0 R/ H
0 ?0 u3 \' v0 `8 P if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {
, x0 w( \8 {' k
3 M. z5 E3 z8 O0 L' I3 ]
0 c! y( p4 z+ W! t: t tag_t ObjectTag = NULL_TAG;
% c+ m, f6 Z, Q+ e" s7 U6 z9 @
3 L: c8 r) @/ R( x, S( t( D" D$ E, t6 C& i
// Get the object from the WORKPIECE tag, [/ k1 I# ~) W k* N
CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);
( s6 |; b' k* m
v6 d% I/ V9 u) q: ]" `: j( |8 x4 T) d M+ S
CAM::MillGeomBuilder *millGeomBuilder1;9 u' H8 h* E; M) h5 s
millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);
' ]5 `- _/ }. Z
: T# ~# N0 D2 ~) d* t" u. ~% T$ X, Z8 O2 \ F2 ^5 [
// Get geometry set list
2 V, h, _0 w5 ]: ]3 g4 V) u6 V CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();+ e, V, M9 m0 G) \- {7 n8 c4 W
std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();* g7 N: { I; j* H0 ~) ~
. _9 q$ r! T5 z4 P
. N0 V, J2 ` u0 _ // get geometry set+ v* @/ _( n8 d6 I) d8 ]1 H2 ?
std::vector<CAM::GeometrySet*>::iterator iter;
& e) R6 L9 ?+ a# ]8 n for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )
5 U' |; T( U! c& U5 r( C {7 p% ^2 T6 m4 Z# Z) \6 j& K8 K8 l
CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);
+ o5 C1 m" F" k" E4 I$ S ScCollector *scCollector = geomSet->ScCollector(); * K4 z# q: H) G2 s
std::vector<SelectionIntentRule*> rules;$ H0 J- ?+ @+ P; N
scCollector->GetRules(rules);0 _: Y# ^$ x& i6 E5 Z. J
- ~! w2 g& H; c
4 o! B9 @. R& f6 F- n3 l X: | //get selection rule9 [3 n- A! I* A' A
std::vector<SelectionIntentRule*>::iterator ruleIter;2 M* k- a N: z: i
for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )2 W; Y" ?1 ?( D' {6 P
{4 ]7 R1 \3 W5 }4 W6 |5 u* Q
SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);: t* T( r; {1 p
NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();: Z+ Q, C" @# [: e% K' N; T& M
//there are different rule types, here just use body, face as sample
+ C2 B" e& w' y switch ( ruleType ), B9 e: I; F( K5 u$ V7 t
{
6 r! z u4 _3 w# R/ W. K case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:; Q' |4 C8 _' P: d) n- w9 [
{
, |& |; B- K3 D //get bodies 9 n; f, B4 [4 M
NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);+ S$ O: y9 R' f' H/ ~
std::vector<Body*> bodies;
$ U) e! H+ B; P bodyRule->GetData(bodies);: Y3 h$ e# ~' r6 L5 c
std::vector<Body*>::iterator bIter;
- m; E* ~. I* w int index = 1;
7 a( G" V6 F. m! X& l for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )# F7 G, I3 p" `
{
1 P3 D0 A2 {2 @! W, f! V Body* body = dynamic_cast<Body*>(*bIter);
' `* r( F- N; O( u ObjectTag = body->GetTag();
/ ?3 \3 V) o- f' x sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag); # I" W0 g1 A7 Q# G
WRITE(mesg);5 n6 v& V" O5 d. r: @2 J
body->Highlight();: Z. Z& ?3 F' M+ v# L
index++;
, @$ K5 u! Q$ d5 s& ]& x: m }
: h! [- V' d$ L6 n" O8 e } e* ?) o0 b& y
break;+ r8 p, _1 J, }4 t* y
% S# w3 O% F. m3 `1 M8 l
7 l' O+ h5 P) T- c- F) g case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:
7 _) Y- @" o9 Z {4 Z2 m# J. B8 t
//get faces
; s3 W7 f n% m* i NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);
6 T. H. A4 U% n std::vector<Face*> faces;
( \7 K! A/ X7 E, L8 J faceRule->GetData(faces);% u7 O" F; d$ p
std::vector<Face*>::iterator fIter;
4 v: y9 S7 H( L: K' @: f int index = 1;
; _, e' k. S& E- l' Y& v, K* z! z for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )
$ S6 w, q3 R7 V! H r. i {4 M$ }) X. A7 o2 ]$ O
Face* face = dynamic_cast<Face*>(*fIter);, W* d }9 d1 [$ S. _( V
ObjectTag = face->GetTag();
' x2 e$ E( }3 `0 b sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag); 7 J7 f( x& i8 I3 P% J, u
WRITE(mesg);
4 K( w0 }4 Q5 L# k8 v6 B7 F index++;
" {* i5 f+ X$ D6 K9 k% Z( v( p }
8 R2 ]: V& j" E9 b& L9 \ }2 u0 e$ b8 w. O3 `
break;$ c; v7 d5 A0 q
* ]- d1 x: u- O2 P% H! k1 Q3 y2 u5 h: u, C$ ?) f/ N
default:
5 G5 |/ U; P R8 A1 s8 { break;
- M5 ?& o H( p5 v$ t }' E3 s% u. X. b, b
}9 Y4 J1 a3 O. @2 H- P
}. S' G2 c# `9 C$ P7 n
3 p7 w) z% }- b7 Q4 W# h
' f& T( p4 w3 p; M& A7 M- t, n& s2 J
0 m8 l' V; H( L3 w4 f
0 U) X% Y6 d( e' V; ~, b$ B: x) Q5 C2 I( m
- L$ P. I# a9 P0 ^9 q millGeomBuilder1->Destroy();
3 N+ F2 y* p Q" ?/ O' V* `) I( a* H) P$ W' `; Z$ p
) W9 d8 e( y& z+ Z) y: l K } else {3 x: E0 Q3 ^) |; o' a: F/ u
WRITE("type is not UF_machining_geometry_grp_type");
' o3 Y% e$ w4 k1 E8 o: G WRITE(" or UF_mill_geom_featr_subtype");
7 U! L$ q3 k- j: ~8 @# B }
+ B/ }: u3 P8 N' ]6 R% l( r$ n9 R UF_free(objects);
. T. V6 w, t( B" E( p# f9 i1 g) @8 z% ^3 d6 h4 h. y9 B6 |
- Q" g- I t3 h; ~
} else {* N) |5 g3 I1 h& _0 m
WRITE("The number of selected objects in ONT must be 1.");' k2 P G1 f) Q- e# r
}8 {, I6 T' H5 }! p. V
& m; z1 R) R; H, L1 v- _
7 u6 X( ~, W6 U0 B6 ]9 l}
4 j! [9 A4 q& b% I
- `. {2 @$ `8 Y% E. b! u |
|