|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
- n" A$ [, P! k4 M% u
NXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值
6 L( t) Y* H' e% P% z7 j @' \7 Z
, P |4 X, x$ Z
static void do_it(void)4 q ^, M: u% \- L: g! k( P
{* P; |1 g+ }* i3 A6 l, C- @
logical is_initialized;% c7 `1 e7 k3 `) r# i- w
int object_count;, f# O& l' L! ~
int type;
2 P2 k6 i" b0 ?+ x8 I# ?% F3 } int subtype;
7 P( v, |* T6 w tag_t *objects;6 Y9 |2 ?5 p0 M0 n, h
# \1 G# N7 i: J: a+ M8 ~% b q' U$ E+ `6 e8 J/ E% ^3 a
% A. d0 K' c. t0 `$ U3 P9 C; T4 I9 h: v
+ ]9 \/ f0 O5 {. j5 S2 q
char mesg[133];# Y: d& V3 m @, @+ m+ Z
S* m; o) S2 A4 Y
' R" ~8 a0 {4 i- M9 V // Get the work part
/ q" M& \% P% K" n* o, S! U Session *theSession = Session::GetSession();
4 o! U8 q3 P* q; @7 r- A# H; @ Part *workPart(theSession->Parts()->Work());
$ _5 N' X5 x( `. Z6 X! S; A Part *displayPart(theSession->Parts()->Display());& `; |3 _/ I, [$ \6 b
7 x0 F" h O9 a e
3 O* y. m+ F2 m# j5 Q
" y9 w v$ u& u5 J9 a0 `$ j. A; {( S
if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;
! o1 m3 q5 n8 f5 D- z7 N/ i$ G, L7 d8 h5 y/ A9 s
- d3 E% Q9 X, I" V' s6 W/ g$ Z
/* Get selected WORKPIECE object in ONT */6 T* }/ E l; B) x# I0 b" P7 ~* x
UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));
3 B2 x$ p& c G0 _7 [( k) {- B, F4 W0 P$ A' J) e8 x) V( h+ J
2 ~2 Q7 A7 ^8 N _. ^ I
2 f/ v- J0 @8 |) [( v, K$ C* Y0 t, x; s# B
if (object_count == 1) {. C& ~" n/ R4 }
UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));
$ s! f3 S/ K4 ~ N2 K1 e) j
: p: l& `4 ^( ~* {8 C- }7 V# ^+ N( {6 c" H0 e
; L. G, t% }; b5 b
4 A4 M7 ?9 q# b; m9 q1 L* u
if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {
q0 y9 M4 [3 J: I6 ~( H3 E# M+ ~% s1 W" y
3 f' U) C: r4 W! K& v4 _
tag_t ObjectTag = NULL_TAG;
8 b# V. {" n. W+ R' l1 j. ~! H4 F* P% c# Z. p
5 r7 Y2 M3 n, u/ Q
// Get the object from the WORKPIECE tag
0 y* r$ x5 }- A/ z, K9 B7 p CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);
) o4 j# U" L5 {2 m$ B- h
* [, i( }5 Q9 j% U' _
( R* s6 F9 @9 n CAM::MillGeomBuilder *millGeomBuilder1; o0 S+ r% e( ]/ D: z0 R- H
millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);
. `* r# D6 S- }* x+ Y" W
+ Q" X) @# |0 ] ~ m# J3 l8 E- D' s8 P. T& `$ r4 B N3 x
// Get geometry set list& F* ]6 B4 Y+ j4 s- i
CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();
$ |) L( c) l& R8 e" W& A r8 z$ t std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();
6 l7 }3 S) ]- U# }' |% J; P- W( c! \7 R/ E, D1 ^
( {/ Q/ k! F; `: X5 M+ F( d // get geometry set
+ j& _$ i4 ]+ R( i std::vector<CAM::GeometrySet*>::iterator iter;% O( B+ u* d1 e+ q9 d8 x: \
for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )" {/ m7 N* |0 g" k+ ]6 T
{
& o, E6 ]) U8 `' a, \ CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);% q. E p0 w' \* E: e: _& K( Y, q
ScCollector *scCollector = geomSet->ScCollector();
$ _/ Q z4 G' {7 b std::vector<SelectionIntentRule*> rules;
1 K% Y9 J5 f3 s- Y4 w2 |2 _5 b/ Q scCollector->GetRules(rules);
- ]3 {# M0 v$ v7 c* O* c$ d2 a6 ^- e ], |+ U- l; c+ `
X! q/ t3 l% }, T
//get selection rule. v, C6 m9 H/ h) b2 j7 {" e+ x- v
std::vector<SelectionIntentRule*>::iterator ruleIter;
/ d' N4 ?! U, k0 M6 J7 N for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )0 E( o' q, m$ h6 D6 j: D( F1 b# D
{% u# J D; f e/ W, d
SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);
E2 C0 m# w/ b5 `& k4 i# p NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();
! M9 \( X; g* e2 f1 {) q. v- P //there are different rule types, here just use body, face as sample- f m! g5 c! E5 C
switch ( ruleType )7 x. O p/ R, i% u
{
& K6 V. i7 p& K* Y( N8 Q case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:
5 w/ L" q. w6 p" y6 G {
/ f" ]. X; q! n //get bodies
3 g* O8 p8 ?7 z" ?& y NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);
2 D6 ]1 V) N/ Z: a5 u std::vector<Body*> bodies;
. \% Z N4 \5 p3 c; r bodyRule->GetData(bodies);
f& P- I# p" A1 N* h1 ^ std::vector<Body*>::iterator bIter;
5 G( N* q: v8 F8 L. Z int index = 1;1 b% J- F& N; B5 F
for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )
4 |/ g( e3 X$ y7 s; l {4 ?0 f( w0 W0 i6 `# |
Body* body = dynamic_cast<Body*>(*bIter);: K% _0 f; R) b X- F' ^
ObjectTag = body->GetTag();0 \- o3 u3 _; k# t0 ~) D6 w
sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag); , ?7 s3 U& w+ e. b5 `; {) S
WRITE(mesg);
+ m( A9 i9 |: W7 g" n body->Highlight(); D+ H. R9 S) n; Y* L
index++;" n+ O3 I- \, ^; V9 e6 \$ `0 \ s. m
}6 O$ `, @- O7 i/ w) G) @; l
}
! r; R5 i6 a6 r, t) c1 } break;% S- P8 @) _# t0 @4 `& }
/ y8 n- Q T$ O
, }7 o) d9 ^6 Q' E1 m7 s& K4 c case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:
9 T: R/ q$ v' ~ {
$ i+ G7 [/ @5 L //get faces
4 H ]$ Z7 K: b. D% w& u NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);
8 p. o' b. I. m std::vector<Face*> faces;
- v3 s. E. K7 P0 [% a2 x0 n faceRule->GetData(faces);
1 U: J2 x3 T4 h6 b9 v# w& r4 ~ std::vector<Face*>::iterator fIter;7 C5 O1 ~5 e# ~6 v- }
int index = 1;
! _3 @. O" K, E1 o g for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )/ A5 o, J1 `# I0 e) {
{
1 M8 ]& Q$ p' K W9 t Face* face = dynamic_cast<Face*>(*fIter);. k6 F# d8 X! T* X7 W) d# M% C/ Y
ObjectTag = face->GetTag();
2 i! }9 N6 P9 e) m; c sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag);
1 C" O4 o5 v4 c, v* l5 ?" P WRITE(mesg); J4 }5 j6 N1 ]. S c/ [
index++;8 X& U, H X+ W, N6 T
} p! ]0 p% B7 B5 t7 q4 k
}
0 e3 z7 E, o, [; K, T2 q' o* \2 W break;
! x9 o/ a; i9 Y3 U6 b
! Y0 _( u' j4 B0 Q/ i1 O k3 d
B. d4 G5 Z7 W3 I4 ~. D/ p default:
0 T3 Z6 C6 n0 V( O3 Y! ~ break;1 c% J8 K# I" L5 {
}; f1 j, v. o2 ^5 i" s2 V
}
+ P& b' T7 A' ~+ e) ], ]# u! k% c }& L4 B5 g; v* Q
, O$ o/ l/ x) T7 {( `0 a
3 f$ r( m2 f" j$ k0 y% O% _
) b' B, h/ ?$ V( x; T- f: r
# x: o0 p2 A# |
' H* A) k+ s, n4 a7 b3 A8 X. R$ n7 t7 C |4 l: n
millGeomBuilder1->Destroy();8 c) n9 O6 i# T( ~( d
( A$ R* D) Y) J4 [
5 n4 H- a: E$ i, v6 [/ c
} else {
8 H/ q, J2 l7 n# ~4 c6 R! z WRITE("type is not UF_machining_geometry_grp_type");
- `8 F& a5 Z2 Z' z8 m% S WRITE(" or UF_mill_geom_featr_subtype");: w$ t5 x* {9 d* }! f6 z, B
}
4 i9 d; i4 \5 p$ t$ G) n8 ~$ j UF_free(objects);* ]+ J }4 Z3 j
- S4 I3 h+ [ g+ m5 o/ Y
& d3 T0 f2 _8 y: [- U6 T" U
} else {) I& Q! T/ V6 _* u! g1 s8 `
WRITE("The number of selected objects in ONT must be 1.");
; F% b- i5 ]6 N# ` }2 \3 X5 b1 a% y. r- U
- H' J0 A" j6 A+ c! u, D
3 ^) F' N5 H: r9 Z% p
}
7 m% t0 U4 N4 @9 }+ B" W5 H+ [* D& f( G8 m, u
|
|