|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
7 u4 Q& `- q8 I, W! H! o
NXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值
* f' f9 O, [2 o5 O2 n
3 `' @% t. \- W, A, G4 G! \- b' u' L, J
static void do_it(void)
, H Q& N. m4 t1 |, d; W& |{
* `2 }" D7 L! U logical is_initialized;9 \$ ^( m8 s0 g4 c" e' u3 k( ^
int object_count;/ R) I1 a2 G3 V
int type;1 v S9 H& b( p+ ^5 t2 S0 C
int subtype;
/ X- m) N) I6 N' Q$ a+ E3 s tag_t *objects;% _' A) O' q* o3 ]5 x$ y9 I S
0 u1 K N9 ?' i8 c0 Y& Z, t. M! F7 K9 o) e" K1 F$ N' s i- A! b- z1 ?: G
$ ^( r- B# W" Z
6 N; v: L9 E1 V
char mesg[133];
6 N3 M3 Y) n- D% S
, N3 s: ~) G* n+ t, [8 f5 r$ V! g* X
// Get the work part
, g! L4 D8 {% f, [7 M; z$ J/ n Session *theSession = Session::GetSession();: k3 U% j1 J, c; O( T- i: E
Part *workPart(theSession->Parts()->Work());0 B- z( x1 I9 ]+ I
Part *displayPart(theSession->Parts()->Display());
6 ?* E% O7 v$ Y/ p9 R
- v2 R+ k0 P% z; @5 i8 O
! K G |- ~6 f* N* G/ Q
# [: @. g0 L- C
3 V% \3 ~! O( Z! _' S0 | if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;
- J" D$ g: T/ m! n }, c. n4 L* p. g+ [& z) q
e, o" _2 L7 c9 T+ L
/* Get selected WORKPIECE object in ONT */
4 f8 } n8 y/ `0 O. g/ ^ UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));
: G |# }; E c8 a) A7 W' ^
! Q6 @- S3 {+ q, f5 p! \; r4 P7 f9 d b& V+ n5 B1 `
+ H4 c( j, h$ q6 }
# \; F; n" G- V
if (object_count == 1) {
% E+ \. Q; C9 I3 s t+ g UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));
9 Y$ s4 w9 E; w
0 V5 J( ^5 d$ O- A8 h* G; |8 w9 [3 C5 C9 y% }
7 P9 L5 e; s& z7 O
+ V5 a% S8 C! b if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {( h6 s; ^! C! G1 r/ s! X
7 F: E& j1 i- E# U9 X) t3 j8 |: _! K# ~# c7 Q% k
tag_t ObjectTag = NULL_TAG;: T8 y* i2 B$ A( ?- R
( } }; ]/ n- T
3 o6 P! M& W! w2 O2 s. D# b2 h1 h: l
// Get the object from the WORKPIECE tag
3 c, r) g k/ u) i( P2 F CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);: \5 p" j' E. j3 D4 u( @/ p: c9 e
; h. }+ ]2 n% `
# \6 s" D! |1 r% E! v, t
CAM::MillGeomBuilder *millGeomBuilder1;* u% S$ |+ U! W2 Z8 m0 M( M& e7 }
millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);. T/ p1 S( k: W: ~2 D
2 f* B$ ~3 w/ M, n# B- Q5 f
0 {: e ]& {4 U& V, y // Get geometry set list$ \: z& q, L/ c5 H
CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();
3 f% ~& ^8 i: k8 c) J0 t std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();
& _& m; W& j, R2 ~; ~5 i& G
/ E* l4 Y' A; P+ k0 R
' v1 a0 O. d, W; F- O q // get geometry set- a; h' \( Z- Y4 I* N& Z/ V @8 f
std::vector<CAM::GeometrySet*>::iterator iter;
W2 W' \9 E: B for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )
% J/ H4 k4 K0 {6 r1 V; X( q( w8 } {. w6 [; s0 W5 P7 }5 B
CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);
, X% p/ U& w: v' K! l4 k ScCollector *scCollector = geomSet->ScCollector();
e* k; P5 G2 j0 ^ std::vector<SelectionIntentRule*> rules;/ \# k" ?% Q1 J' ?
scCollector->GetRules(rules);
' c3 `2 j" l7 D. `- Z; T8 s1 Z9 v1 U* {/ ^9 J; o ~
' @0 o5 X; `5 i2 _4 x! t9 Q
//get selection rule
' r) H# I. X5 C4 ^ { std::vector<SelectionIntentRule*>::iterator ruleIter;0 o% ]$ j7 O3 H0 i
for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ ) @0 @0 m6 k% J1 j) j v- a
{) o# u9 E1 ]1 q1 f
SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);
7 S; ~& w4 P# H6 \% e NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();
- S" i5 ]3 S/ U+ q$ |) K //there are different rule types, here just use body, face as sample6 @' C* I1 s: v# E. d/ Z* B
switch ( ruleType )/ i, z+ u6 e7 {& j; w- Y1 ^
{
+ ?% S' ~0 y+ e/ v8 g# U/ j. j! ] case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:
- R, `' e$ ]' j! H; [9 o' C {
9 F0 Y$ f1 Q9 }. F //get bodies
5 w7 q" C/ P& O) k% Y NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);
. V: y' L0 b7 }' W std::vector<Body*> bodies;
% g p' t- z7 \# y! @. E' o+ K2 t bodyRule->GetData(bodies);; k, O# a& w3 Q- Y8 S ^
std::vector<Body*>::iterator bIter;# u: s! A# Y7 A- q' ^" i0 c6 l
int index = 1;
# O9 P8 R, m: M2 C for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )
! d# V/ i6 L: y2 u {
: l5 V! k L) z$ k2 O- D m Body* body = dynamic_cast<Body*>(*bIter);
% B7 a; j) K0 x+ \. O6 K ObjectTag = body->GetTag();
/ r9 V* E$ }6 C) ~ sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag); * N* I7 B# ?/ t9 D0 }# h9 P. F
WRITE(mesg);
! e8 V: B: E0 f+ w8 r ` body->Highlight();
! [2 [, I5 z! C index++;
5 I2 M! g. m0 O% P O }
8 }8 T1 D# M3 s s/ L6 Y }' X/ _/ O) z. I: Q% N
break;
* c. g1 {9 O( f& A+ K6 M/ A% z
- y; z5 k }, I- ]9 ~
% k/ r. v- Q; I$ C3 J. J case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:% a- ]0 S4 G* e/ T1 `; {
{% |* c2 m& D6 Z
//get faces
, ~7 y$ j; i3 L1 U5 f, K9 D m NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);2 c; a7 i: C, {$ r: C$ P* @
std::vector<Face*> faces;
( @+ O @9 y& _/ [; V. O% s faceRule->GetData(faces);" \5 U6 D5 A5 q' X0 v
std::vector<Face*>::iterator fIter;9 L% ~, @ Z c g
int index = 1;/ W# G" L: X, g1 G+ B9 F, A3 _# b
for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )
5 t! S$ Y, R! i& @" p+ g2 F {
: N4 W; k+ w+ |% e. ?) H8 t" [ Face* face = dynamic_cast<Face*>(*fIter);
; ?4 k4 u# u3 d. S( B ObjectTag = face->GetTag();8 L# r! X- V$ r
sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag);
* K* i; V0 ~1 R2 w7 `) N WRITE(mesg);
; H) [1 D2 v- _6 e; q/ s index++;
( c0 ?$ K; S2 T, B& }8 ]* W }
2 f6 n; P5 p9 J: y% H4 j }
Z! Z, v. Y( V3 G' W% V# P break;' }6 v3 T7 h& i5 ?4 I9 R3 o7 H
: T' V5 O- {5 N4 O r
4 `8 Z( x' e2 z6 ]- q% s: o% q default:
3 D4 J" r2 X' j. M2 I/ u& E break;
, P- U' {9 u L8 W+ L) c$ ^ }
4 _2 L3 z) M8 S) ~8 u0 a5 o2 j2 u# Q }
, T7 ^9 N1 N/ M( u$ _ }
, m8 [4 T$ J) Y; L7 q5 O/ Z: A
9 I! t$ `- K( S
; O0 b$ L, X: k4 h( F
- c8 o( ^: c& _# Y3 E% e) `' O' R& P$ M/ \( f4 q
h; y# _& a/ U* P S# ]: ^
" h) x& O+ P2 a0 d* b1 k$ B
millGeomBuilder1->Destroy();
* ?4 T; v9 m1 g' ]9 w# z3 J6 v5 Y' |
6 y8 o0 K3 W- U6 s) x& g
} else {
1 e' N+ P/ t8 | WRITE("type is not UF_machining_geometry_grp_type");! H3 l$ W7 I. S' U5 L3 |
WRITE(" or UF_mill_geom_featr_subtype");9 x) d* D& `. x) v, b8 p' h
}
! H4 W' D+ T* o UF_free(objects);
! S5 Z" ^( F9 ?; s; y# c2 `! ` ?2 P. [
) q, H- t5 L& e, P0 e# c } else {
( i" ?8 c t2 j3 a) v WRITE("The number of selected objects in ONT must be 1.");
. P8 O% b- u# g! R8 A$ ], P }
. A2 A* @, H) j' H. }5 w. S
# P4 t% `; y( ?
5 l7 {/ W% |5 u5 ?7 I# B}5 w' F9 T# |! u0 V2 y" x
7 g# E. I z9 A; o9 [- A* @
|
|