PLM之家PLMHome-工业软件践行者

NXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值

[复制链接]

2018-8-23 08:32:50 4936 0

admin 发表于 2018-8-23 08:32:50 |阅读模式

admin 楼主

2018-8-23 08:32:50

请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!

您需要 登录 才可以下载或查看,没有账号?注册

x

6 ?9 s( C" L  k% rNXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值
: k( F) Y6 z) A* @2 D4 P+ w
; s% ?  p0 c3 l/ \& I
0 t: k8 t$ w( U. M1 i  dstatic void do_it(void)
: w2 q9 d, h* J/ n5 e{
$ c+ `! m7 l: Z. u& w    logical is_initialized;, L" @7 ]) U) J7 n/ [1 l4 L
    int object_count;
6 s3 ^* j' G$ I' p    int type;
5 J- S, r) m) J# E" n, W+ i    int subtype;$ D/ Z+ J( K) W" V7 D# I
    tag_t *objects;" P5 A  \) X( g& a% \( {

/ p! j0 |8 q$ F8 e+ m

% ]: L: e- K6 C4 S8 [8 |% {7 I! R% C6 ]1 V" P" w
% x! m7 j7 _1 G% _5 e  j9 Z0 r
    char mesg[133];
5 e4 D$ g( G& t8 u. `8 I* [. f; x/ U3 g( Z! S
) N  N" Z& n$ X- Q& t) [4 i
    // Get the work part
2 W, {/ i; g' J7 ]# t    Session *theSession = Session::GetSession();) Y9 f" ~. O& i  x; C
    Part *workPart(theSession->Parts()->Work());* L$ T+ r6 s6 g' }! c  b4 q9 M
    Part *displayPart(theSession->Parts()->Display());
% ?) }& f6 u2 B2 J
! M% T) j5 f( {

" [' u0 k, H, T" E+ y$ j2 r5 s
; f/ c4 A6 O- K( M0 \8 V
9 A( h, Y; o9 r# s
    if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;
4 \$ w/ Y6 n/ \- t' o& Y
1 Z8 J' w% }! A- M1 }  f0 w

# o# K6 Y; Q- d" J7 u' a9 K5 H; {1 K8 C    /* Get selected WORKPIECE object in ONT */
- @" P5 ]4 Y% p$ S  S* y    UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));
$ \3 l9 I8 q, Z# ?5 |0 H/ g6 s7 H5 [1 @$ M
( ~& t& ]1 V7 r0 S
* s4 E: E2 j0 `0 H; G8 A9 F. v

' r5 L; N# l- f7 Z4 p: _    if (object_count == 1) {
2 Q' }; i$ u8 P; F, P: M' L        UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));
* K8 D+ U: P0 k1 q% y5 F
  C- l7 h0 ?; C% h
9 C$ J: B' h: y
% ~- S4 f* n6 l) E. h

8 U$ c6 c; w/ z% \2 r7 C% N: f        if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {
3 n3 i1 C2 s0 ^: t( C4 q8 N- V  z: D6 ^0 U; m, _8 V

% A5 n) `; |. F, ^            tag_t ObjectTag = NULL_TAG;+ `$ s5 o) e4 {- u8 e1 q- [

/ V7 P0 ~# r1 Q$ I5 t
) I0 O& D8 o0 ^$ E
            // Get the object from the WORKPIECE tag1 ^- _. A! n& H$ s% R, {
            CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);2 f# ^/ z$ M6 U+ \$ M) T1 a( l

5 R) g; l# T- W, ]6 Y' H5 R

2 ], ?  g& q8 {, q/ L0 F- P& J* l6 X            CAM::MillGeomBuilder *millGeomBuilder1;
) \" J8 c4 c, ]& b3 B! ?            millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);
6 @* f; D' o( B; A" Q$ S5 m+ e( K$ {- Z# x/ ]

/ {5 A! S* d0 Y# H: K8 a) W            // Get geometry set list
( [; U: [; W6 S/ g            CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();1 e  U3 x$ y+ {) U( Z1 x7 F1 D
            std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();
* F% ?9 f! X  q8 I9 J) {7 v/ m& V$ B1 N. D

; _1 z1 H. t: X6 ?% x+ S& h3 S            // get geometry set3 o; T% O0 r1 T+ O' c) B  q; A
            std::vector<CAM::GeometrySet*>::iterator iter;
; ~6 t7 c; G. M. p6 L! Y% x            for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )8 i  N; l' e* O/ T) q/ g, o' w% w& ?
            {! ~. K$ \: P' ?+ Y# s! U' Z6 K3 L
                CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);
1 V8 S2 I* B" Q2 i- Y5 s& X                ScCollector *scCollector = geomSet->ScCollector();            6 S* l8 X* j5 o. @
                std::vector<SelectionIntentRule*> rules;# k2 {! E9 U5 n6 C
                scCollector->GetRules(rules);3 O" D5 H! R" w0 e: E9 L
/ x  `" V. R$ _
0 f/ n/ U/ n3 w/ u9 o+ f
                //get selection rule1 r* u4 v* G$ G* u, f* f$ O
                std::vector<SelectionIntentRule*>::iterator ruleIter;/ D5 @9 Q! E4 ~( W# `/ R
                for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )
* ]( n& M) F9 W                {- i5 }6 c& S0 S5 E& w. Y
                    SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);
6 M4 q6 \# t: A- W' t                    NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();
5 Y8 H6 w$ W( }( I: ~/ e                    //there are different rule types, here just use body, face as sample
2 r9 R* t& z: p( R( X0 \                    switch ( ruleType )
' c9 l% O" H: g9 K; L& P# X                    {
8 T% K4 t$ `1 y3 q                        case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:
* r* o1 k8 m4 h( M                        {, R& e  _- L: r, o6 I% Z
                            //get bodies 3 P+ p: H1 f2 O
                            NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);
& G9 l3 M# f2 C' V  a                            std::vector<Body*> bodies;+ a+ o- r* Z# e: b
                            bodyRule->GetData(bodies);
( w/ a  b2 o. Z; _" ]/ a: [7 Q8 ]# J2 o" X                            std::vector<Body*>::iterator bIter;
8 Z% }5 @9 A+ z: o: E& j6 C) _" g7 m                            int index = 1;) |/ A5 S! r0 P5 Q9 M( l* f
                            for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )# V2 H" p* H% J$ {# a, |6 Q
                            {
$ ~2 P, D: Q$ H) g; d, i8 x5 K                                Body* body = dynamic_cast<Body*>(*bIter);$ T4 H4 n* d) u7 f4 F
                                ObjectTag = body->GetTag();9 E  K1 q6 ]# @/ k5 l, x
                                sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag);                                
3 Q3 r  Y4 T; `1 l  g; O! O                                WRITE(mesg);/ V$ X9 x$ e' s% s7 b" }$ c3 [
                                body->Highlight();& Y2 z1 ]2 O+ a, H6 Z- Z
                                index++;
' f7 R% s3 V9 A: j3 u& x                            }& _, o" ?- |1 r- \
                        }+ o' Q2 s% \% {; Y
                        break;2 [! x, C' ]6 H; {2 [
4 l" c  m5 f7 A/ a# z* Z6 T+ H

, h, ~' [' u9 n9 ~0 H( L# i                        case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:
, _. l$ W: U9 B: Z! d- }                        {; ~' x6 j9 o' h1 Z
                            //get faces . P' _: b1 O% y+ A% u& J! b# N
                            NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);  Q4 ~0 G; T  [. q7 k
                            std::vector<Face*> faces;% A* y% ~/ Z, E0 F3 w" i& |: R
                            faceRule->GetData(faces);  j: u% ^/ X) j- ^
                            std::vector<Face*>::iterator fIter;
- M6 @1 i4 v; {& |( P                            int index = 1;' ?- k' F6 V" s" `4 d9 {
                            for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )% U3 j* K' [  l$ o+ K4 u3 M
                            {
( L; c9 s" t  t0 c" ]( d6 f                                Face* face = dynamic_cast<Face*>(*fIter);7 A8 N+ z- I- H5 h+ `7 a
                                ObjectTag = face->GetTag();) f3 ]. f# g6 s2 e; E) J8 p: w
                                sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag);                                
3 \; n6 P' [, n& p" P  E0 Z- z                                WRITE(mesg);
, S$ D6 U: p* o& t                                index++;' P; }3 ~' v7 z0 u
                            }- S0 Q. X! d$ w+ T, Q0 ?
                        }6 E' V6 ~" ~+ p) h
                        break;
) Z. Q+ i! r* _4 [4 G7 C3 I$ g  {% w- C) F; z0 h' u0 N

2 Q' p" F8 W4 c; [- O. K                    default:
7 N1 B/ ~% h) ^0 [                        break;* J0 k/ D: W  k4 W
                    }8 `& ~! k) Y# N+ ]
                }. }  a  M* O9 N0 s( K+ a
            }
9 X- F* L# D+ u- Q" R9 J2 r6 U/ ^5 n, H8 U) X* i* P( r2 x+ L

/ D3 q6 H0 z: i3 d/ Q$ q' U
0 o7 C  ^/ M1 T  x4 n

* _. D$ C8 c8 {2 t' |9 q! }- F: Z; f1 N# v
" ]' x# ?( f0 H, z# h
            millGeomBuilder1->Destroy();
! z: ^# o$ \3 A. P0 ?: ]0 z- P
1 [* P) m' z) d9 D, x
  s8 d" ?2 |: `; A' Q4 T# S9 O, ~5 [
        } else {. `) s& H+ c& o/ E( q/ j  [5 Y# L7 `& e
            WRITE("type is not UF_machining_geometry_grp_type");
4 `; `5 k4 X, Y9 g3 d8 [1 `3 v            WRITE(" or UF_mill_geom_featr_subtype");
. b( `# w0 |+ T  G0 k* o        }
8 h, N# K/ Q6 B( W" ?        UF_free(objects);
; {  N7 |1 D4 c& r( S; l# y. X4 |) b4 M2 Z) b2 U; R8 Y* Q

7 P0 _% p4 ?) k  b5 |8 L6 w5 h    } else {( H# d  n7 |! V; S& l- ?
        WRITE("The number of selected objects in ONT must be 1.");9 F; x. r7 }* P, o& E) R
    }
* R- {( C8 a8 L/ u5 V  f5 ^! |) o, O6 z/ B5 x0 y/ L+ g6 a5 z
! o; m1 F7 `2 k; ~: [' G
}
5 k; H* \# E' o' R" R) d
; ^; E* ?6 O: W
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了