|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
1 N$ E4 Z4 |- N o7 A
NXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值: m2 P- Y. Q% @) `8 w8 J: F8 j1 W
: s' K+ s$ b5 I9 F% w
3 f: C. {( _/ Y: Ostatic void do_it(void)
1 j, c& y( w* k, L2 l" u0 L{1 ?, y7 W: L( W- ?+ t
logical is_initialized;
+ S4 i6 \- a! G, f3 S int object_count;% i7 a$ i- H* V% I# Y! M
int type;. u9 [: V1 y+ ]$ C/ S \7 ~6 k
int subtype;% f: v/ `# B- C+ M2 K+ j! ~' N
tag_t *objects; Q/ ]) w& j {
2 d, J$ D) t! K( W6 o, x7 V
. e7 i. V2 x3 y3 B& ~* N: J3 Y4 v9 _' I5 _* u
& R! E- B7 y* N) `" H Y
char mesg[133];8 t5 L0 R: n( C! L4 y" }
: Y" c& ~" k% d8 N9 B; W
% V3 S/ ?. V4 ?2 f) k2 w2 ^3 E
// Get the work part
" L# d! a/ Y1 F0 Q7 N9 ^' k Session *theSession = Session::GetSession(); ~' a; f$ H7 R" p0 A7 r
Part *workPart(theSession->Parts()->Work());
7 K% E" J) @* }; x" Z; K1 e Part *displayPart(theSession->Parts()->Display());
5 L2 M2 D, P& |6 `: V7 h9 y. o) O1 C
$ `8 Z1 }% c z# v5 s& O1 D, K, i6 @
6 p. ^, [+ C }3 h
6 n4 h, f! {# g0 }& M: _* v- Z
if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;
% d/ X% J0 c4 X! q a
x. `6 k {9 k' y" Y B* R$ m3 N6 V" M2 I9 K# \
/* Get selected WORKPIECE object in ONT */; x4 X7 z3 J% K- c
UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));! u. |$ J4 |8 w
* I. `/ H9 ]1 u
" ^# d8 N* x: M& d2 G
+ K& x: a2 A7 _+ k8 u4 _
* q4 @6 g" ]3 G# h if (object_count == 1) {- {- D4 X) i j2 U' r5 c5 ?) s
UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));6 w/ v# B& b+ i' A6 [
4 |5 I, `* S& \7 d- |% U* T( }4 @- Y$ @5 q
' |: }1 ?1 d. \3 h$ e2 @7 R% D
( c" V0 I& W! v; i
if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {% [ E: F, {4 j+ u
( [6 F# u# w) M- Z( ~1 j$ z( q: |- A9 X3 s9 H" A( P0 K* ^0 W
tag_t ObjectTag = NULL_TAG;
7 r8 R5 G6 S) P7 ?* c+ q6 x; A# f% _! w( A
3 D4 ^* A: f1 F8 u // Get the object from the WORKPIECE tag
/ A& f4 U. x' s5 N2 j4 e CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);4 L) S) A! I) R; _' I
( |* A1 K! Q I
+ W( G. C8 q' r2 O/ w L( U CAM::MillGeomBuilder *millGeomBuilder1;
3 G! q/ X4 O* `8 a5 w millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);& m9 ?+ X) @% P- p
* ]# x! ^. v$ x, w# j; ]
k; H* U- y1 a' a/ Y: y# q
// Get geometry set list6 n4 L5 |4 Q3 z( @0 z# ~" s1 Z
CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();
- J: O" \; v; z% w# r b- V3 N std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();
! S$ l5 Z K$ }1 M' a1 [3 G* W
, ?$ [5 C7 }: f0 b( Y- k
q2 l. G" b ^! m // get geometry set
# L/ R: ?- N c. Y9 m std::vector<CAM::GeometrySet*>::iterator iter;; E" K9 T( \% y5 ?5 H7 S+ p
for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )# Y1 R4 ?+ R( F$ H1 ~0 G, I
{
5 n: D' ?& S& U$ c* x+ _# b# N4 h CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);
1 ]! A9 U6 M( l6 ?8 ?! u/ ?% B ScCollector *scCollector = geomSet->ScCollector();
& P# k$ q) d# \ std::vector<SelectionIntentRule*> rules;
5 X. q7 Q) J5 v) Z) a( K! S- E scCollector->GetRules(rules);/ R. i9 K9 ~4 E5 B5 k# K; T+ D2 X; G$ |
$ t( M- E7 n7 Y: ]- a0 l. A5 s/ c) g: d9 o
//get selection rule
3 b. c$ B6 f8 x8 Y5 ^ x+ y std::vector<SelectionIntentRule*>::iterator ruleIter;
: G! X1 }; P0 K/ j( U5 _ for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )
# A/ C) A- O7 ?8 {( s {0 O' L4 Y3 ^) v4 l
SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);
1 [; c* b% P/ U! F/ v+ u& F NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();
# h3 {: o! V9 G) Y2 X //there are different rule types, here just use body, face as sample/ F0 H$ N" @- ]9 r8 o4 Q0 t; {
switch ( ruleType )3 T9 ^7 Z$ q. _" ]% ]
{1 N ^4 y+ l) X; f% R( A
case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:. h! L6 r7 w, L1 D
{% O. g; Q8 l. y* }
//get bodies 3 x& ~6 P1 Y* Z# P+ B: t4 e
NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);
' V, ~+ i: i; k# U std::vector<Body*> bodies;2 l) w) t2 d# x* m' g6 ]. {
bodyRule->GetData(bodies);
, N1 e+ v: d; d1 o) }* o std::vector<Body*>::iterator bIter;2 Z! y# }' r4 X8 ~; Q
int index = 1;9 `3 W7 E8 i+ V* \5 F; w L6 ]1 F
for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )
$ x) \/ a* ~6 Z u& K' c {
% F' G8 ?! S# q8 j3 U$ A- M3 J Body* body = dynamic_cast<Body*>(*bIter);: t$ Z' g, y% J
ObjectTag = body->GetTag();$ @; \0 d3 P7 k; p/ p
sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag); " e. t# S2 r) n# D. w- u) V# c/ D1 d
WRITE(mesg);
5 d6 D8 |7 s% p1 Q9 Y$ X% z3 V( I body->Highlight();
# X5 _- ~+ ?2 W( Z" r index++;$ z+ ], [% \3 _" P y' T, N
}' S0 B+ k1 {- C9 b6 R0 i9 P4 P
}
/ O0 s9 L9 U# K8 |. C! G; L break;7 J/ j6 m3 {' [ M- O& h
% B/ p3 T. d$ f* E( Y$ {
6 q- ^: P- \6 T; t: a# \2 \4 Y case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:
5 b1 _. u: F Z" U8 | {
, v: [. t# c7 [& C) m( f //get faces
" S; I0 D J( _) f, l- b- x NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);
( E4 V! i4 ~1 ^1 [0 ? std::vector<Face*> faces;, G- Z0 W m4 v# h" T- r$ d* _
faceRule->GetData(faces);
8 v2 m: F' k" R3 \ std::vector<Face*>::iterator fIter;
8 @* G# ^; [8 }/ E int index = 1; D6 u0 n5 n. V0 f2 z! ^
for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )
( @& z0 H7 x) E! W {6 C- K% C' `1 [ k& ]# W% g
Face* face = dynamic_cast<Face*>(*fIter);
+ h7 D ?0 Q9 q" h ObjectTag = face->GetTag();. S8 H3 B( p8 J/ T% N) L' u
sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag); 3 k- f: z/ W; \# k
WRITE(mesg);' A0 F: D0 _1 d1 v7 n$ j( n
index++;, }/ V3 t5 ^8 W: _
}
: ^2 [/ u+ l, Z( x8 F2 H! X4 K2 Z }) q7 e6 _4 E/ L! [% f
break;
# ~1 O; d; R/ ~$ s4 q9 X0 n* ?. y+ J( E/ x# F+ q
1 h# ?& Z$ O. |4 Z5 K% [8 Z) n default:
* Q$ N6 o. O! c break;) l8 L' I8 o- X0 n( o B: S
}9 [/ V# Z2 H6 d
}4 ~, T2 d/ H" Y4 G) j, _- q6 p8 {
}
7 m- P4 u1 p' Y8 R4 X
" M3 D0 K5 Q3 h! d* j; Z, q8 \+ K/ ?1 K
3 |- z q3 p9 d0 G: |0 i
# P% \. u' [7 q2 s. j& S5 Z( Q; G& d5 X& b2 f( r
6 T8 j4 ^8 p0 @/ Z, [ s& ~ millGeomBuilder1->Destroy();( S8 u- y, c3 f/ a% S
7 Q1 C# T& d8 Q: d" g) c [: F
7 c6 R) H ]4 \' H# T
} else {
# a0 _8 o( {. r/ L( c: V WRITE("type is not UF_machining_geometry_grp_type");( K8 N, {/ G3 x) l% w0 j8 D
WRITE(" or UF_mill_geom_featr_subtype");* @* [! z1 p2 s% E; q5 g
}
5 K Q+ I1 W1 J UF_free(objects);
* ]$ Q$ p# h, i/ s1 K5 _( W0 W- H7 d2 G; a/ t' ^: H3 [ V- w9 q
, I2 Z' [7 x& R } else {$ k* c5 I \ y) ]
WRITE("The number of selected objects in ONT must be 1.");
3 j- {% N) v# j6 F7 G0 g }9 w) `# v; k3 ? Q5 w( u, d
% a8 ]% I6 |/ T' D4 z. I6 C+ J* r" z8 X; {; D
}
' z+ K3 Y! X: C0 i# Z
4 y/ t- J$ i: o3 j. B8 W |
|