PLM之家PLMHome-工业软件与AI结合践行者

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

[复制链接]

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

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

admin 楼主

2018-8-23 08:32:50

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

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

x

: o& ~5 U. A9 T( B- SNXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值' @- e( M2 J3 f% A" V( t
$ A7 _$ n2 O9 `; x/ P

1 R0 E9 L7 I3 xstatic void do_it(void)
5 E$ b; X8 w: u+ W{$ E* a7 f; t1 `( T' J( ?
    logical is_initialized;
) L7 }8 g- A8 l    int object_count;
$ _- ?! T, w7 t: _    int type;
0 a7 ?. n2 b/ ~/ G7 m- T& b7 u0 s) S( I    int subtype;
0 B3 L& t: B: B3 q7 C    tag_t *objects;
7 p$ H1 t+ s: H( v4 K3 D# A' ?  i
& e# t/ a4 M- {8 b  l  p+ O+ A
5 Y- I1 f9 b+ g& F1 [
" S/ l! u' o/ U! g8 P

1 q' m& U: w+ P    char mesg[133];( x/ @& p# b* W- }

8 C4 Z. l7 Z3 J
, i. S- d4 ]5 `: K( i; P6 r
    // Get the work part  \' L8 q1 E( W
    Session *theSession = Session::GetSession();* r  J4 L7 [8 K1 m
    Part *workPart(theSession->Parts()->Work());* S0 Q1 O. L+ c! Y+ Q8 g, P
    Part *displayPart(theSession->Parts()->Display());
0 o0 ]' [& c+ l" Y( N. P  L5 c3 M9 Q# K9 @+ X5 Q+ \
1 J) h% w( s- z! r  O; y7 g
3 J% I' l' B- p& i4 t
* r% Z5 ]: m, J6 `
    if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;
7 G. E2 F5 d( \7 |6 _8 I% |
! y) b8 e8 @# Q
# e) f0 p- ^+ _$ s
    /* Get selected WORKPIECE object in ONT */7 k, g! {1 e2 r! M* ^. \) u4 d
    UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));! T7 ~$ U- `" Z4 E5 U" ?
2 V& \: z6 o9 w" i9 v
* i/ v: n4 F3 ]6 T2 i2 K* q6 |

- s6 j1 H  z- f  u3 m3 H9 D8 Y+ J

' [, i' q8 o) y. i4 N) y" @0 r    if (object_count == 1) {+ `! F) z4 ~. `9 m  K8 S
        UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));# e5 u$ @( f+ T) G7 z; t- j

# p/ @) @4 q& V1 k  W3 L
0 ^. I$ T. @6 K  `
* ]- t% J, M3 t7 F! c' `
9 U3 a) D  N! J
        if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {0 c7 V2 ~  C9 x/ |

0 Z" @- L/ P1 R, m# h) c

( h+ m6 X* @- Q" A' A  ^            tag_t ObjectTag = NULL_TAG;  s0 e/ j3 S, s7 R5 M  `. M

- f! g+ q7 ~; }3 Q. }8 o
4 |, i2 W+ [( H4 E7 Q- J
            // Get the object from the WORKPIECE tag
* C5 q1 K6 W& T% U            CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);  {6 t" z* m' E3 U! B6 U2 x  r

5 T9 K4 _) u5 \; J1 s

4 _% @# \( `9 z8 r            CAM::MillGeomBuilder *millGeomBuilder1;
6 O% f8 k$ {$ z& d$ X            millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);6 s6 R: j( V: E. b, r; i

9 q$ S) ^& S3 f7 @
4 c2 w! p7 q& w% a" L# S  i0 L
            // Get geometry set list6 j& R/ y( f' u  M  k7 C+ y
            CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();6 o7 v4 Y: r3 U. W
            std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();
' R$ y- e; q4 ]# h4 b
3 q0 D  H2 ?7 a6 O5 M0 s/ [
! `( K0 k; \6 z. \! c
            // get geometry set
8 L+ i8 `2 E6 F8 G            std::vector<CAM::GeometrySet*>::iterator iter;: {8 y% Y) K; O
            for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )
: F: x  o  f* x+ W' `4 k  V            {. c5 v. Z+ i3 v$ T: F1 l; y
                CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);
6 P( M; @% t( q1 w+ P: P8 f                ScCollector *scCollector = geomSet->ScCollector();            + O. _  a: V% S  W$ z
                std::vector<SelectionIntentRule*> rules;
( \  a- z/ j( k5 H$ U                scCollector->GetRules(rules);
; D4 z5 p" e; i, Y) |* c& O. ^. x
1 }9 e1 j( q' g; ]

9 I8 w) f4 F- |8 }" G, |8 i9 G                //get selection rule4 c5 H, D4 h% C: w3 U& W
                std::vector<SelectionIntentRule*>::iterator ruleIter;
5 [9 }9 ^; a& K# ]6 Q                for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )) m. I6 D- m$ g, B2 Y
                {8 l% r- [6 e: T) Y. g2 \) |
                    SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);
# a1 G8 S9 W7 T" p# I                    NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();
9 J' @+ `& W8 ]. g0 U: H                    //there are different rule types, here just use body, face as sample
$ d  i0 q2 L, y5 q2 p                    switch ( ruleType )
  V# j3 Z: b) J                    {
& P8 v7 c8 |; C) s                        case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:
  H2 p! _; I1 ?( J3 @8 M; q; F                        {4 b" e, y: d2 W; u. N
                            //get bodies 9 v3 z$ |4 k4 I& `7 ^& R/ v9 u
                            NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);4 L/ K6 H3 t% b1 a5 R
                            std::vector<Body*> bodies;
! e' q9 i3 w% A                            bodyRule->GetData(bodies);2 c3 t% i3 W' @! h* A9 o( S
                            std::vector<Body*>::iterator bIter;
* z/ @9 u$ F' g6 B9 m+ T                            int index = 1;
8 J! R" Z' O) i4 w0 j                            for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )- Z0 F$ {6 n- e) f' {0 `  v
                            {
* w% l. G6 u& \7 s8 X; [: M: s                                Body* body = dynamic_cast<Body*>(*bIter);5 e& o1 c  y* `/ S( a! W
                                ObjectTag = body->GetTag();
, A- j9 x! d+ F4 e                                sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag);                                
  _' [0 \8 R3 L2 s" z4 I                                WRITE(mesg);
" l2 q% F/ F, y                                body->Highlight();' d6 u8 `/ U( _/ S
                                index++;. Z' F+ Z# K" P$ F# S
                            }9 e7 n1 X* y# |; V
                        }
1 |8 _' e+ C. f( ], c                        break;
' K' O6 e* P! ^$ [3 c& f3 N4 |
) C( W1 P. B- z
0 z2 g& l1 W! M2 ^
                        case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:0 c  c7 U3 H7 y+ m# n" ?5 c
                        {
- y( [# [  ?: g1 s) b5 N9 H# Q4 c                            //get faces
4 q% y5 u" L' r! U: K                            NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);
! ^9 y+ s, K* w1 ~                            std::vector<Face*> faces;) d  e  ], c) @4 f
                            faceRule->GetData(faces);& A" u2 y) ^! N/ ^, a+ V) d
                            std::vector<Face*>::iterator fIter;& S! M) H% D9 D' A: u
                            int index = 1;/ I( P2 h6 j3 q5 V# O6 b) _$ `
                            for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )/ A: A. h# C; s, }: P4 i
                            {
! R$ p  ?- }" `) C; c  D" W) U                                Face* face = dynamic_cast<Face*>(*fIter);
$ s9 ]- e. ?; ?- O4 z8 H                                ObjectTag = face->GetTag();" k4 S0 k; t8 I9 a- z& q" {- z
                                sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag);                                
4 [4 S( i6 z8 C( A& S! a. y1 ?                                WRITE(mesg);2 ~7 p4 `( N/ G4 H
                                index++;- q5 _7 w; o  Z; [
                            }% I9 r2 \8 b: H
                        }7 ~" V4 ~- ~* Q
                        break;
( W0 E# h  o% K3 q& B. d# d/ [6 s  m# @; l( X

7 v. T, ^6 M+ J, ?                    default:6 i6 J( E3 ?1 _( p& C/ Q
                        break;
5 X2 q9 o0 L1 s8 a                    }
; ]! Z' i9 t4 C; @                }% X( ?# W/ ~/ G: Y- A
            }- Y3 i# }& ]) y7 v
$ ^8 A% k" X4 a$ M: ~# t& N

; F4 K( G, q' N8 F. C$ U7 T  j. }3 `6 Q' o
2 t& K8 T( s( c" X) U
% w: m" o1 @: `" Q+ Q. M
5 t% P/ b2 Q; _. O
            millGeomBuilder1->Destroy();
; l7 \8 b  S% g* G
5 q: O8 [, ]- X6 c1 o  L
# a- I9 O' t: h% K4 S
        } else {' t* P3 T6 R! \7 ^) S
            WRITE("type is not UF_machining_geometry_grp_type");& Y5 p2 c0 |, O. z
            WRITE(" or UF_mill_geom_featr_subtype");; }' K! v, |2 i
        }
4 E$ I! t, l) }+ u2 S1 D7 H$ N8 w        UF_free(objects);) D( v' B( [+ A0 g
; ]) Z2 o! q$ d# R: Q
" j+ N3 h/ Y. P. M5 F
    } else {
! Q8 @* i4 A9 i: x( M1 p/ o        WRITE("The number of selected objects in ONT must be 1.");; ]; F3 [4 S5 L7 t2 t/ r! }
    }5 e4 k% Q9 `% H9 m0 S3 I
; J6 E* m* ]3 R" u& l
5 p( Q! E/ Z; w; Y
}
: D# _2 c: [. ]# \1 U5 S0 E. x8 F" c
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了