|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
" }6 m7 e9 ^! j: V y0 r% }# C/ B
NXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值
- u/ ?8 n c5 L3 S6 E# v
! T# ] h$ D2 W, n- B2 B, z
* _; G/ V( U% n2 s1 Q: vstatic void do_it(void)
+ @+ }4 N4 W7 r* Z! O6 V: U{ E) {7 i( a' R7 b8 ~2 d1 i" z
logical is_initialized;, x3 G2 _) a5 ?" |5 D7 d
int object_count;" g. q" B0 K' H# J7 k& [
int type;6 \5 V# i, p+ A2 U) @
int subtype;
9 K6 j; D; `+ t( @% p: Z5 ^! g tag_t *objects;
3 r: \6 i( m/ f, q$ u5 B$ x B. n8 z3 e; S- p8 [
5 f6 q( R5 a4 K, S! |
/ Y0 F( Y' b; @! [ Q! E% Y# m# l) a V% M% }4 y$ k
char mesg[133];- O* O' k& a5 n) w
8 d2 B( E: K/ L2 s; I
) C$ U, F5 y* O5 {# ~ // Get the work part& {% l$ j: c" Y( a
Session *theSession = Session::GetSession();: K/ C8 Q) {$ W& o/ c
Part *workPart(theSession->Parts()->Work());. N5 X0 B5 v, d, T' @
Part *displayPart(theSession->Parts()->Display());9 x% m: G: C/ C! s* D
0 m0 `8 j; w! Z5 O2 r- I1 _
; J4 j4 `7 _2 U- S7 G" l
9 D' X1 u1 s) a* o! \1 @3 _/ j5 N+ m- W% X" y) C
if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;
# V. {; p! }* w7 I8 v+ A f v- ^) V5 J1 D/ v% s2 n6 M: t4 q
% I6 W% Q. h1 j /* Get selected WORKPIECE object in ONT */
2 ?' @# J$ |3 }. o) } UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));2 ^4 Z: X o5 }9 G: P
+ E5 d+ ?' M( Q. X" S8 @
5 Q' m5 o+ m9 J+ J# Y% _0 G9 V: ~) i. N3 n7 B8 ^' V+ k
1 h' i2 L0 O# X! y' j/ [
if (object_count == 1) {' E* j" ?7 c4 f" ^. K, \ v+ n
UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));
, W. f4 n1 S2 l( f) j2 L& @, c' b8 W0 u7 a
) ?$ }6 t, P: g+ x9 A6 @; i5 Q# e9 Q! k0 _
/ ~2 `) c7 c" z- |1 s c if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {+ m, a v3 S. {" v
! h' j, u- x' i
8 S+ Z5 X" x$ ? tag_t ObjectTag = NULL_TAG; P, s+ w# H' B+ U& s
8 I# A5 R4 i6 e
( `$ @. l3 A- A+ o' P4 @ // Get the object from the WORKPIECE tag
) }" ~4 Z( F2 B3 R" Y CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);- u0 c6 ]% q. L
8 r- y# E9 S# g" P1 r. e6 C. D7 U+ D* S( q e& I" r) o' x
CAM::MillGeomBuilder *millGeomBuilder1;
/ n& \: r* \+ a/ p( e! s millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);, P/ J9 N& R! I% q) |
) p8 A. J4 c( s/ I2 q2 Y+ _% E. A+ c9 d' W
// Get geometry set list
7 X" t) p( Q' ?' D CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();
2 c. R& g2 U/ P: u) C8 h std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();
/ l9 I& i* X5 P, U* |
, x5 ]; Y2 E0 K, Q7 O# }' x0 U4 T% x+ m
// get geometry set) v5 P# R9 n/ R" B2 Y5 h% t/ ?/ w* k1 |
std::vector<CAM::GeometrySet*>::iterator iter;
4 z" r' I3 _2 [2 Z- Q for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )* F2 b) {4 A+ v; S* H
{! H# H% ?, y! H, S$ U$ {7 U
CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);
4 T* J. B1 f' b ScCollector *scCollector = geomSet->ScCollector(); - j# s+ g3 w5 r" S7 g K
std::vector<SelectionIntentRule*> rules;& r+ v L% ?) b2 A$ G1 ?3 ~
scCollector->GetRules(rules);
b: X; W- N) v! F' @, k7 j- C" x" r' x: J+ U, Q9 g
) \. X" I( Z! g/ i
//get selection rule# K7 P# I' m) T7 Z7 i1 x, ?
std::vector<SelectionIntentRule*>::iterator ruleIter;* m7 n) A* ]( C# y
for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )6 z+ g, c% T2 l% W/ _+ a
{
5 I' |: L4 T; g; M& s. ~ SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);
2 K# o5 z7 v* n NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();
6 b; U& ^2 U" I$ q //there are different rule types, here just use body, face as sample
, u. {* l: l& h( P switch ( ruleType )( u0 C" S. W& I$ U" p/ \
{# o4 p6 P/ G! ]/ W1 r
case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:
; r3 T9 J% ?, C$ N8 E {
0 o4 E2 g% i! W0 V //get bodies
2 _9 L& F) d% j/ q# y" d: P NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);' {) k9 u' v8 W) F* c' e2 i+ c X8 }
std::vector<Body*> bodies;; O* _* E0 \# j& Y9 f
bodyRule->GetData(bodies);
5 I) m" G* Q: \7 F1 ~9 i std::vector<Body*>::iterator bIter;
4 c( H6 c3 u/ G' l$ a/ v- u) O. c: u int index = 1;
- p) S% K+ P/ Q: s+ O) a for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )
8 G. d" I+ J$ U' Y' X1 a$ g. M2 X6 N {
8 L, ]6 S% O- S( q7 w Body* body = dynamic_cast<Body*>(*bIter);$ M0 a7 d1 N z
ObjectTag = body->GetTag();
; n3 C- Y) W3 Y4 v8 b& f sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag);
" }) p6 J8 B8 T5 y+ X% t WRITE(mesg);7 E% `2 V: b+ f! c: J: {
body->Highlight();( E. |- n" B) c a* i' ^
index++;7 }9 c9 R+ h# E6 g% K) `
}
- G4 y$ v) E; ]! }! i } q$ m6 c7 c6 U3 y
break;
1 ^6 u$ L/ x" v8 g M' F; f' j7 M v' O3 i
" W- E R5 Q+ P$ D% f0 `0 b
case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:8 @4 H/ K5 @# {6 s1 I+ P
{/ H( o) N, j% r5 O" W' A
//get faces # z1 q+ q+ {6 S. C3 N1 U
NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);
$ n. C( k+ q1 H s' S std::vector<Face*> faces;! _( q, s% t6 Y& [" [
faceRule->GetData(faces);
; f( b6 {* }2 Z! Z, o/ _ std::vector<Face*>::iterator fIter;
. L' _5 S. s$ i+ j6 Y0 d" ? int index = 1;
9 H; |* }( \! u for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )9 h0 A' E7 ?' m: c4 a4 d
{
6 h. A% o9 O- F/ T3 ] Face* face = dynamic_cast<Face*>(*fIter);; j" f/ H) @6 G8 h: C
ObjectTag = face->GetTag();: \+ B5 ~& q( F v* V1 \) P
sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag);
1 _7 U' O' t6 a; o1 V WRITE(mesg);
" _" T. c8 x; W P/ @ index++;
+ L: O: j, [$ L; e/ r8 l! \6 b }
9 O- t* |2 l4 c! Y* c }4 ?7 M j6 G: V+ F
break;. R9 d8 A2 v" U2 I
3 h [' @8 G- q! {5 g# k& s% W: S3 h! Q
default:/ S" Z& z% K4 v4 o# K! Y6 |
break;. D- f( W" w- ?/ U3 y
}% G' S' ~7 @+ q4 b5 q1 V; Y
}- k5 a$ |& I u; _" ]( G- H$ p
}; }4 l( y# x" W3 f, H3 C9 Z9 y( |, R
R+ [$ g* r, Y
% R. e2 f+ f$ L
+ l4 P9 x$ `* j0 C" t) f. C% E' K: C6 r3 p4 ]: ~( O+ }4 n
3 q2 }- O, O- ^9 P
" m& \3 b r9 h# d; n; h
millGeomBuilder1->Destroy();8 ?+ r& c3 Q6 c" I, `/ B
3 Z/ m: i& I/ R& }1 r# f
1 B4 b# h. o) ` A( N1 C# V1 k } else {( f- \7 a9 |; x! J: E S7 C) K
WRITE("type is not UF_machining_geometry_grp_type");1 b# b! z2 G1 l/ L4 B
WRITE(" or UF_mill_geom_featr_subtype");3 d3 K& O5 V5 z( d7 b" h7 b
}! ?+ [, Q- S$ Q
UF_free(objects);! B- t* L- A- ?5 ~# F) \( J) z: z
; j, |5 v+ Q& d( B4 f
6 b$ {/ Y: ]: o8 h } else {0 }$ s4 _& s0 g! [& c* I" L
WRITE("The number of selected objects in ONT must be 1.");
/ w+ R8 o& \& E! b/ g3 r! e }$ T- y- Z7 O% x. U) S; p7 G u0 s
' ^! E6 ]6 \$ Y9 d5 I- o9 I4 x8 A& U; C Y
}
+ b8 n, O. V/ y1 Q0 t* W+ I D$ |% f1 C- z' }3 Z' D( f2 g
|
|