|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
' \7 I! {+ G) z4 J! I$ P0 N5 J9 k
NXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值' f& Z& P- k$ T& S W
' L' E) ^! u& v! l: B; _+ }5 S3 G9 y3 z# @3 `
static void do_it(void)
' o/ o \; S* i# i{
+ i% K) i" K1 n9 } logical is_initialized;
+ W7 L2 g0 L0 V# e4 i; P" {9 o9 G int object_count;
, f) {3 L d A: @& m I6 I int type; r, Y- k& Q2 x" J* D( Q: A- i
int subtype;8 e6 a+ G' x: j$ o) j0 T! G
tag_t *objects;
0 J9 { r4 S5 S# D2 u' S
) c) ]) {5 E% ?
% w% |! Y# W& g+ a0 d0 I& Y3 r8 ?2 {
: i. h0 x& M* }; w7 i
3 p6 Q0 d' E. g2 y char mesg[133];
6 Q% }' K& {1 }* K7 y$ u+ \: L' c: n0 w" Q0 A1 v( e: t/ `$ [2 s8 O
" L! R4 X6 O% K8 Y T1 P, r' I // Get the work part
; O3 C! l9 G7 M: |7 S [ Session *theSession = Session::GetSession();
$ j' O2 u8 [7 X b* u$ t- R5 h# O! ^ Part *workPart(theSession->Parts()->Work());5 W$ y& M/ k4 z2 f
Part *displayPart(theSession->Parts()->Display());3 x0 m( z2 O0 C# J6 t' ^
) Z1 Q% [& f) k# j
1 |2 E' M* }( B m
1 v8 y7 q9 J$ `3 |! x: C$ u+ k8 P' |: B4 }' C0 F- U$ u" h
if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;! b# b9 ^; p0 z
$ c( c. l* |7 j4 E5 \) U
! O: P3 \7 s; m# P1 [. E
/* Get selected WORKPIECE object in ONT */- R. V6 X0 e2 ~! y
UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));; i% m @/ \8 C* e* J" K. V# _
6 I K6 _! s/ g4 B V* u
0 p$ D( |3 V0 x$ J3 V8 ~
5 S. w/ s8 L5 F* ^' J. ^) @3 K% s$ k) [" N& \2 t Y3 y
if (object_count == 1) {5 C/ o3 S# p: c% v
UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));4 i9 S# P( S. e
5 N5 F" D# v: P
; S- h5 D+ Y# G& g+ g9 H3 o
" s1 s: j" n- m# \; M! t2 {" p7 U9 @8 u, I) U; s
if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {
! K; _7 a4 Q8 ]) G8 R" i8 O/ k, ~( Y
/ U1 k# w( L4 G& X2 o4 m, ~
% c( O& S$ S, ^5 O+ k1 V' @ tag_t ObjectTag = NULL_TAG;1 B& L( ~8 L9 \1 [: ~% ^: P/ {; d
) L; N5 ~, `& z7 C8 x/ m2 j
7 @% n! ~- P8 ]! M! h, ?
// Get the object from the WORKPIECE tag: d, E* p; }4 t# m% G
CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);) G6 \5 {6 O( H
9 M" z. B( S& {8 G% I
: i, D- I+ ?4 ?. ? CAM::MillGeomBuilder *millGeomBuilder1;
4 d: H6 l$ \. H! h millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);
. G- x1 o5 _. B: V# M" Y
; w& r f- I g/ N ~: _8 K) z1 F; }) E
// Get geometry set list- w, u- e4 f8 y$ @
CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();
; H! f! n h; K9 u6 u std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();" I% L2 _$ [: K9 @7 G
. [. Q' q& M3 x/ _/ H6 u
- u) _# t# ?3 F: f // get geometry set
* m# ^7 W3 `! j# \* Z7 ^! i std::vector<CAM::GeometrySet*>::iterator iter;
2 _9 t$ M6 h& L, n" |! b for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )
$ o7 i9 K6 A- a- b {
6 J* D3 L; S/ W0 U CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);; {7 E& `8 m. x- N2 Y. `
ScCollector *scCollector = geomSet->ScCollector();
& A. V" k: {. j9 f std::vector<SelectionIntentRule*> rules;8 h1 e# _" j7 x/ n' w8 w. Q. c
scCollector->GetRules(rules);
# ~: Y% {/ w# Q& O+ d* r, G- ^! @1 g+ b- R: ~5 p. X
/ B' Y' N4 \: J5 l
//get selection rule: V8 o6 x3 I9 D& q2 `! k# L
std::vector<SelectionIntentRule*>::iterator ruleIter;9 B$ M$ b. `& o$ E2 c3 m: E
for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )' a) ~6 c5 t1 M
{9 w# N3 R8 S# L. z* ?, r% i
SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);
. U* V/ I2 v5 M: M% N9 S+ L NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();! P' W9 i% i" o- L( W: C
//there are different rule types, here just use body, face as sample
$ Q# @' w- q, x, J& I! B switch ( ruleType )
- S- X1 v; u1 n7 _; F1 d' P- y {2 z8 @4 Y7 v: C
case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:6 r4 n6 }5 R3 e; |
{. q$ W+ u8 U& I I& f% D' ?
//get bodies
+ B0 f8 A0 O8 Y/ t5 p NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);6 G) Q! D/ L, D. I0 _4 Z- X1 I- F+ v
std::vector<Body*> bodies;
% M* Z$ @9 y9 a, Y( s bodyRule->GetData(bodies);
$ r; w" T# d) c* E! y std::vector<Body*>::iterator bIter;
8 O8 u" m. ] o" W5 S5 J int index = 1;
# b$ B# q" A, ` for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )
% K- l3 o2 F- b3 ^9 [ {0 h* Z5 i( X0 m9 ~9 W9 Q0 p; q
Body* body = dynamic_cast<Body*>(*bIter);) \$ K$ ]% Z4 b" X/ F$ k$ O
ObjectTag = body->GetTag();3 S& f1 C* @* }& C
sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag); : {4 `0 G: I9 ?2 e4 e
WRITE(mesg);
& u* E: r. ], v' W body->Highlight();
- f& {5 A4 f' ]& X' a, V2 P2 x index++;
5 v/ Q2 k. \5 i' j8 p }
1 }5 b% P9 U' l" U6 T- M }0 N9 Y# O9 s7 b8 n3 ^1 s" T- W
break;
2 K- L. T+ D7 F( m" P; u/ J* u1 r! L, M
0 a$ E4 s& G$ [4 h. N0 Z3 Y k case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:
* `9 H+ h) S8 ^7 n) d# b {
, D' g/ h) S! [4 q# h$ f. Q //get faces 7 e! E6 a5 k9 I( |: b$ B+ t
NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);
; p4 c8 ^( l/ H' O. O/ p! u std::vector<Face*> faces;" ^+ V2 b& A6 J$ Z7 [
faceRule->GetData(faces);
* C* d! d b' m( v) f F std::vector<Face*>::iterator fIter;/ K g& w5 g0 k/ @
int index = 1;+ s7 d7 S- a5 _7 d/ v
for (fIter=faces.begin(); fIter!=faces.end(); fIter++ ) n) v9 p! M) _! B
{' U# f, k: g- J8 B- {
Face* face = dynamic_cast<Face*>(*fIter);5 q8 N; C# q7 o& C" Q5 t
ObjectTag = face->GetTag();( M0 h. z- M) z- H, }
sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag); 8 Q; Z+ f# N1 a2 D6 o# ?0 l2 ?
WRITE(mesg);. E0 W x( V2 z+ I: R
index++;
! ~3 I" w. ^' z4 f: H }
/ I" N# U$ t; r4 K/ F+ F0 D }4 p; {5 @' d# p: [6 t
break;6 X3 C. |0 u" B8 ?' R5 T+ A# k
: A/ u0 y, C' J4 u7 i
9 M1 \$ E9 E1 k ?! B default:
& q5 ~8 _- P/ O( W6 \ break;2 e" M( _7 d4 H' d4 z6 ~( y3 T
}7 Y. w2 C9 Y A; g- X6 q; f
}4 D r* u7 x1 j
}
% v: e( ~2 u' G* J) ^4 p
7 B* J6 L& N0 K, _8 z" b8 Y4 O8 b4 Y# w
9 V: ?5 G$ Z. B; w1 Q: K1 T- V1 h# o0 U$ W- w O3 Y
( ?. R% l4 q! n/ A: |$ o
j4 `" @9 Q' @; O* B1 u millGeomBuilder1->Destroy();6 s. W6 Q2 x& @7 q& }. t0 q$ J
$ r. S: K3 C: @' r; W& g) j% _5 W* H& G/ b; w0 \. o" b, R% M6 k
} else {
1 ?0 l# g `2 I/ Y3 t: g WRITE("type is not UF_machining_geometry_grp_type");
( ] w0 |2 I* |; _9 j WRITE(" or UF_mill_geom_featr_subtype");; a) X* Y# X! h' F# T! I- _
}) D; v1 Q) |- ]3 k& l
UF_free(objects); n) Q: B) E7 C G! Y
2 t' m4 }% B3 P
9 b) k+ E" Z. K } else {- k4 `+ ]) Y R
WRITE("The number of selected objects in ONT must be 1.");5 t* ^& Z! o; {* ~7 n
}
/ w+ _4 a9 J3 q n) o: L/ \2 s* j2 t' ?; v" [! N3 f
# }5 g+ m, Y: y, H# n}
. q; v1 W0 A: d0 k+ `3 P5 _% t7 ^7 ?
|
|