|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
/ ^- S* U& z# F. M$ n6 f# dNXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值3 ?$ X9 W2 p% n2 ?) O1 q+ d! t
- {+ |0 T8 {" Z3 a) L
3 i& K! \* l! h( w2 L; W
static void do_it(void)* s( Y) p0 y! z' p t
{" Z' P% W G$ B- S
logical is_initialized;
6 h+ O. \9 B/ E9 W; C/ y9 v& a, U int object_count;
, }4 {: _2 q9 W1 G% e' L% t1 \ int type;
1 j z/ K: @: c% E int subtype;
7 r* E* H1 l+ J1 L9 n! u2 M" \ tag_t *objects;
) t6 X% O: n" P
( f& V: c2 Q, O/ Y# N/ Q* { M! N& @9 O7 Y4 Z3 a- x- i
& [ g3 x' A' [. m8 x* W& F0 d+ }
4 ~3 N: }# @- q- ~0 X% f. ~ char mesg[133];' j" m# d/ e5 X5 [: ^! X, Y
! W& C+ B+ i1 h; L9 H
7 P+ z$ F' ^7 r& ~
// Get the work part
$ J/ t5 e% q( {; ?+ {& K Session *theSession = Session::GetSession();# S4 V# w* V1 g- N3 ]
Part *workPart(theSession->Parts()->Work());
8 h9 v, o% r1 V- S3 P7 q0 L Part *displayPart(theSession->Parts()->Display());
& _* l+ N# ^0 R7 h+ j& m0 V8 {* u3 p, ?7 M5 z; ~2 U% b
( N! i _! M+ O, B9 `
: a1 l' H7 R. n
7 A1 X+ E% F2 m9 i/ {4 ] if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;$ h3 q8 k) w5 N3 c+ Q/ [' k- z
% N4 S" y1 I& X) ?" u, @3 j8 O
/* Get selected WORKPIECE object in ONT *// h7 s, Y2 h9 q9 i
UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));
7 Z3 }9 s* r" r& d% D* _1 x& o5 d( R- J( z4 M
2 ]7 v1 n0 [& t- k" M+ Y% K, J) r
$ G; Z8 g9 i4 ]. c3 n" d
, O- b2 S: ^2 _8 S! E* }! D, }
if (object_count == 1) {
1 N L! I/ }' @/ [7 S UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));$ q7 s. X K- F0 M1 v6 _$ A
" R8 `# D2 u O q l
3 ~3 E% i, y7 K3 R) Y) h
6 Z$ Y0 v4 S8 @- c3 s+ R4 {: J
+ E' S+ N& @7 [2 v U# M6 Z! Z if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {
1 |. x: _! ?: ?* S
$ @, }; ^ i1 F2 `; A1 U. z- n
9 n4 O# X4 B3 A/ _6 G( o+ P$ Q' X tag_t ObjectTag = NULL_TAG;/ x' I5 E# H; T4 o0 m) Y& C3 H( L
' \8 {6 X: O# g: @, A' v9 e, [/ M
! G9 x0 a0 e# U // Get the object from the WORKPIECE tag
9 j. S7 i/ ?4 f( L: Y CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);
) s4 h: Z9 b( I1 _! a) l
! l/ [& N$ y) N0 v9 p7 B
) ?0 k+ B' J# q' E) }1 C CAM::MillGeomBuilder *millGeomBuilder1;) p% ?8 q0 U" | c* D$ d, Y
millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);
3 ?% t& T7 k( U! s! H1 R. `4 g" x/ ]6 f3 t K
/ R$ q* I' R- A; Y8 Z& L1 N
// Get geometry set list
# {8 ]3 K/ D! w$ O% U( G7 g# B CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();* S' V* A0 \) }+ X0 L$ o( V; o
std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();" U2 H" ~# h/ L) Q7 {9 _8 N
& @4 j0 J! l1 ^6 ?0 I" [* N
5 @3 r0 X* i; W' J" F+ ~ // get geometry set
% P0 z- @. {; P std::vector<CAM::GeometrySet*>::iterator iter;! D) W' E& |' _3 p7 w
for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )
: o$ v: |+ P$ d& w7 _. f9 a" U1 C {$ O) f5 V" }5 P. Y- J
CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);0 N4 A9 C- j5 j! G; D
ScCollector *scCollector = geomSet->ScCollector();
* S5 R- E& ^' G+ @% o A std::vector<SelectionIntentRule*> rules;
% Q" `( D$ i' l7 f! E scCollector->GetRules(rules);/ I: ]( T1 g" O
& y' W7 S+ N. n4 e
7 X$ r: }6 l( R% }- [- Z6 ]6 t
//get selection rule0 i4 e7 _9 w5 _% {) K
std::vector<SelectionIntentRule*>::iterator ruleIter;2 u& s6 g/ e5 _0 @5 h
for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )
5 g n7 M$ Z4 } {- L( |7 j" z( c! M
SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);) t+ o. J6 U( ?, w2 ^! u# a
NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();9 [! R# M( f/ d& O
//there are different rule types, here just use body, face as sample% ]/ b+ E7 m, U) T" ]
switch ( ruleType )
* T: {5 v3 |) `/ [. ~; D0 m& O/ y0 V5 c {4 P3 M+ @; g" X
case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:
) \+ d+ C z5 ] a3 o {9 m4 c1 W7 i3 f, d
//get bodies
! X3 N0 z" T9 R+ h$ L NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);! h2 D% B w& m
std::vector<Body*> bodies;
" e1 ?! N& T. Z& A3 Z7 G bodyRule->GetData(bodies);
* w4 m; _" ]& ^4 _5 k9 T. @! I std::vector<Body*>::iterator bIter;
- b2 Y& x3 Y5 H% e9 A0 X4 y int index = 1;
4 N0 r8 @8 t8 }2 s0 `3 O for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )" Z0 Q" @) ~' E, p; V
{
. h4 A8 g/ o8 F( Z3 L9 U Body* body = dynamic_cast<Body*>(*bIter);: ~8 ^& D2 @) n9 `5 G
ObjectTag = body->GetTag();
/ N+ i. c/ g) t sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag); & E. S$ `0 v0 l% D; L7 A, f& {" g
WRITE(mesg);/ N0 r1 m( b8 L7 R
body->Highlight();
) A/ z+ |& t' Z6 O+ t index++;
o/ i3 s% E' S+ V }5 P, h' @5 W8 \6 a V+ ?! ^4 q, J, z+ S
}
4 E P0 y8 S) i7 `/ D' @ P Q break;
, H4 j, q6 c6 S- Y. N& Y9 O* K& d- c6 e0 T1 x- d9 Y( }
e1 r! W* c& n% I/ p5 E case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:3 d3 \0 G' a& ]+ B Y
{
, Y, x9 r* ]' I& S; a //get faces : t" ^& F$ N* `8 q/ |- V% H
NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);
' |& w4 |/ j. `, ~* q7 y& ^( W std::vector<Face*> faces;
1 C; ~, B* v) q2 o7 Z faceRule->GetData(faces);
% U/ y" d( h; ^# G std::vector<Face*>::iterator fIter;
7 Z, u9 ^+ ]- S9 e; \# R9 v7 p& S) r int index = 1;
8 N' |7 Q1 Q S7 f# }; t for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )# R* E4 i2 y- E
{
; e( \4 p; X/ I* R Face* face = dynamic_cast<Face*>(*fIter);- M3 o7 F9 x) I
ObjectTag = face->GetTag();
" p% J. `5 _! n: v sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag);
, k7 z6 [( c- ~# p' u( n# u WRITE(mesg);9 S3 H/ r! @: o5 Y; m9 Q7 d) p* Q
index++;
5 ?2 B# z. [1 w! W' P }3 U l ^2 ^. d9 \( L! r( {& G$ |
}+ h: }/ _7 \- W0 C! U" w9 f# p" Z
break;8 m; A2 Y' O0 U7 D. r8 c2 O+ [- _
4 N6 ~& u4 ^/ X* Z3 e' d9 { R
% o( V, G" H) t$ j$ l+ A; n* d default:, s: G4 J! i2 B; T* U; S
break;
+ N4 S" {. L: m }/ Z) Z' \9 A0 I- o) H7 L6 _
}
0 V- t( `! L* a. b5 U& p9 n3 j }
* D+ N$ E- A7 {" m5 H+ \# \8 z
V9 @/ |. a: P( W: {; F+ E4 h. v) ]
1 ?2 y9 g9 r8 p( W/ z/ A( ^9 x$ i% D' y
" O5 ~! L1 y% u& ^* L" @4 w$ u3 u- E6 M r
millGeomBuilder1->Destroy();
4 J. s# j' K) K+ u% k& B/ c, }8 a5 g: m2 C- \3 @% U- L, w, }
4 u4 j6 ? g' W) |. s9 E
} else {
! _3 l5 Z- T& m5 Q WRITE("type is not UF_machining_geometry_grp_type");. r" `2 P. f' l
WRITE(" or UF_mill_geom_featr_subtype");/ p6 I( z/ g% d; W$ q9 m; M
}
% m9 i. s# m' i2 H4 p UF_free(objects);
- c7 S) e$ O6 f9 S+ o5 D5 J7 h* }8 l
3 C' M2 d% g1 u- [/ M/ ^. r8 a# X" t4 a. h
} else {
. M6 m4 [* L3 Z5 t( E% e WRITE("The number of selected objects in ONT must be 1.");$ |* V, X4 C: A9 W, x
}
5 U( z# U) I3 w# S0 S, t% ]0 Z9 L- }+ I/ d" I" u% F
& Q5 J6 M3 _$ J& K, l$ r. m5 H; A
} ?2 K7 @+ w3 Y. O7 V4 e7 Y0 `) R2 t
- m! O' {6 e* ^' @: c |
|