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

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

[复制链接]

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

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

admin 楼主

2018-8-23 08:32:50

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

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

x
9 {& M0 I' n" W
NXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值4 T" z6 S; E  M3 \; P' r+ x
$ j8 C0 _2 ?1 X* K# A
5 b& V: m$ f  Z9 E3 c4 |0 ?
static void do_it(void); R3 Z5 F$ X0 N
{
1 j+ a/ n4 q$ V5 _    logical is_initialized;
! _0 j, n3 g" O. p2 d, e! M+ ~    int object_count;
; b4 [! S  Z3 b& S+ ~+ C    int type;
) [( L3 U; U4 Q& O    int subtype;
# K2 D' }  s. Z+ N    tag_t *objects;
2 ~4 m" p3 f7 }1 T, J5 ^* G* ^8 Z) J$ t

! Q! Z9 b$ N; F
% u4 p& W. j. `+ G* \0 j
4 {: j: L. f" a( I6 ]
    char mesg[133];0 y& W- }$ N5 I; }

0 |( J4 ]0 u0 h0 T% f7 s

' x7 Z7 U/ |* l/ B5 d- E    // Get the work part5 ]# j2 v2 S1 E- L7 }
    Session *theSession = Session::GetSession();
4 _( _" [0 j' _% A2 r0 h    Part *workPart(theSession->Parts()->Work());0 J! S9 A9 }. _6 x9 N4 ~
    Part *displayPart(theSession->Parts()->Display());
' j/ v! ]+ @8 s  Z0 _* N- l7 J0 C0 D
0 t- V6 ]( q0 g+ K% _- A6 R4 o
. `* R0 a; w% D" ^7 b/ J8 h
8 I) ~. Y' k7 a1 O3 ?
    if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;# _5 c  H: r, q& q2 S0 N$ ]
. s1 s: `( @; H
" t( a; t8 X; V- _  S3 }+ |
    /* Get selected WORKPIECE object in ONT */: S* N$ @, @) S
    UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));! F  w5 n1 j0 m2 i9 d
; T! ]8 f- s; o4 H

, {/ C' U: _# M$ s, E! t; h: P9 |9 E; ^( m3 X. M
" W/ G9 U# m' W2 Q1 K1 I" f2 W
    if (object_count == 1) {
/ d; j( J# `# z8 a        UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));! @8 r8 V( O& [3 s$ r' u4 Q5 o# x
2 A5 V- j  u: u( L8 X; b$ ^
3 \' O; @% C3 P7 T& i

9 k" S* |( ^: @6 ]9 X* u5 u$ W
8 d: Q3 n& c  t6 N, b' t
        if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {6 A& `0 L3 o' W0 P
" v+ g/ ?. {7 R' d# ~" V5 P5 O8 e

* o! V. o/ q% {2 B. H            tag_t ObjectTag = NULL_TAG;
/ u1 |: X/ D$ C- i. j. k! |! I% P( `! v  L# S' i8 [/ ^+ d3 w

9 ~0 f: _  D# {3 a; u8 J) K1 @3 y            // Get the object from the WORKPIECE tag
5 y+ C! i: U% n1 q8 Y; P1 r, Z  v            CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);
+ M& |% B' p5 R5 N# O: S0 w6 H  C, P
: W9 C0 j; s2 b2 \& c1 o3 s( w
            CAM::MillGeomBuilder *millGeomBuilder1;7 {' p! D4 q4 F. P
            millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);, H  W  Z9 J# d$ u5 S5 ]$ J
0 e9 U' n+ h4 T/ O0 O( _$ s" [

/ Y/ D7 n1 O- k* \  _            // Get geometry set list
5 R* y, }/ X: y: @            CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();
# `6 h5 e8 ]* q. S7 k) p" a            std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();
# G/ V3 {) b9 r8 n7 P" J& V) D/ j0 B) l+ u& M5 Z: t5 N& A
+ {/ G- Z$ m* r1 ]' Z0 j
            // get geometry set5 [, K$ p+ V1 S7 l; Z: Q
            std::vector<CAM::GeometrySet*>::iterator iter;
8 A/ g; ]2 l; \            for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )
7 e0 p6 ~& D0 s* q) B6 F* h# @            {1 x2 Y& ]7 p9 f' I
                CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);& p' W; F$ ?' T; B
                ScCollector *scCollector = geomSet->ScCollector();            
% L# j# e% b+ I7 I2 R                std::vector<SelectionIntentRule*> rules;3 S, x& |% ^8 C: |
                scCollector->GetRules(rules);/ H/ L. k5 b! P% ^  A

& z% D6 G9 B' Z! S. U

0 G$ F, N. G1 S6 s% I: Y                //get selection rule% |+ h$ H* ~" n& \. X$ T: T$ p0 g
                std::vector<SelectionIntentRule*>::iterator ruleIter;4 @0 s, ~  ]/ ~. k& I1 _
                for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )
6 r: ~, Z/ V4 v) [1 F1 t. n2 o- H                {) x7 c4 [: X( J# f8 f: I
                    SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);
" ]4 U9 B& z! X  X' Y$ J                    NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();
1 }! M) [: w/ v. @3 {' _7 s                    //there are different rule types, here just use body, face as sample; q* D4 Z" t1 v' Q0 N7 V
                    switch ( ruleType )
' ~* R" D# }& K8 N8 `                    {
1 E% z) D$ |3 w" J                        case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:
; Q5 U% d7 P  B% U7 S: ?                        {. [2 v( {, b: g
                            //get bodies
" J( h8 o+ G6 j8 D* y                            NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);
1 P4 d4 y& y1 h; A9 T5 U5 L                            std::vector<Body*> bodies;) S! k( v# O4 |$ o& C% G# S
                            bodyRule->GetData(bodies);  ~- Z# C. z% r) {' b9 ^, F
                            std::vector<Body*>::iterator bIter;' f/ U0 o4 x4 X$ a8 a
                            int index = 1;
/ ?; y; ]( M  i1 `                            for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )* e8 g1 Y- E5 H9 R
                            {
/ _' I$ b: ]; W5 w4 c) a. y                                Body* body = dynamic_cast<Body*>(*bIter);+ e( |& s( v. B( Z
                                ObjectTag = body->GetTag();# b  U0 L; \$ u9 G* g% h
                                sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag);                                
# v  _- h% Q- m" D: U                                WRITE(mesg);: f2 E9 y% L$ o' b
                                body->Highlight();
( V6 }; j) d+ _) K" G& J& K' Q                                index++;: d. [* Z9 j8 ^: l- ]
                            }
2 \. }/ h1 @$ H* i/ M                        }
+ y; x2 H1 m! [5 m                        break;
6 I8 |2 S: J) |, [0 }$ k6 y% R8 D% q1 F/ `

; C5 H' x% T; w3 D                        case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:& Q$ p# [$ l. l$ H% ^& s- X
                        {
- w/ ?8 l) _5 S                            //get faces , l# M  a# n9 B2 A) G5 b: D
                            NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);3 y" G. F7 R+ F* K
                            std::vector<Face*> faces;3 \! |6 o7 @, a  p) O4 p
                            faceRule->GetData(faces);0 b) t# x0 S+ z, i" |6 x; R
                            std::vector<Face*>::iterator fIter;& t0 A! N3 [! ^9 O) `2 q1 @
                            int index = 1;
( j7 ?$ W( e4 M6 m9 ], J8 K  O                            for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )
, N+ c3 S; i9 L                            {% `+ p' R" r. d& a1 s9 m- l3 C
                                Face* face = dynamic_cast<Face*>(*fIter);, t( y" w3 Q! d# H; W6 ^
                                ObjectTag = face->GetTag();
# c3 \9 k! M# X1 d# E: Y                                sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag);                                
( Z8 A, B7 w7 k. h4 q- P                                WRITE(mesg);  N7 `" p+ u5 V5 V; y% e! z0 D; }
                                index++;/ Z0 @5 k2 h" q. R9 J7 M4 Z
                            }. P, B- V7 u! w4 G6 ^9 v" ?) A
                        }& i$ \9 ~7 x* J4 B7 s% ^; u
                        break;
3 e$ y5 ^, W# K" m) ?% |# F# m
4 w4 J  \2 N1 h
. q7 x, t* K, P
                    default:( u) [/ u/ _6 z/ d  }
                        break;, Q9 X: U6 d) }, O# Y' b' w
                    }9 Z. B0 A" R6 ]$ ]6 z  O
                }
( V8 e6 U) F( `1 ^' {% Y/ ^9 D            }
, Z, P$ S5 T* h: t
' n; ~! o; j, s& L

) x* r7 U( X# \- G+ C) s
$ h! m0 X4 k( ]: V2 m% l/ l. `

0 r/ Y5 r0 w0 D7 I
3 L( u# c- G, \* N; w; m/ W

; S8 Z) L( Z7 }. L            millGeomBuilder1->Destroy();; @* E: `+ ?5 X; O# J; q
* o% q! Q- _. U4 M& {1 c& @
, o9 p+ J" y. M9 m
        } else {
4 S, d7 N! a4 P! h5 y& ?: W            WRITE("type is not UF_machining_geometry_grp_type");  q& Z% z% ^5 k# y" K2 E% B" i
            WRITE(" or UF_mill_geom_featr_subtype");
7 }- y2 S8 K( N7 i" N" W        }
- i, w$ q3 R* P- Y        UF_free(objects);( p7 W  `/ o; b2 F& A) {: z" t

3 X+ d0 N! P1 G

8 I. N) P+ U! f    } else {% P4 z( ?& [; r- l2 u$ G7 I
        WRITE("The number of selected objects in ONT must be 1.");) M1 S+ x% q- b2 B0 Q) K
    }
6 \+ i, R( x+ H# I7 o5 ]# t/ v( I$ r! {
7 c5 d) |# r$ E4 i" g" _! W
}
: ^, L+ H! D/ S$ ]+ [4 O! h2 d7 C$ S) o' _! M& d2 _
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了