PLM之家PLMHome-国产软件践行者

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

[复制链接]

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

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

admin 楼主

2018-8-23 08:32:50

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

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

x

+ y$ b, o. Z6 ANXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值
7 k: L$ Y  m' O4 R* [0 e4 {
" Q  @/ m: o+ ]) s" e
: @1 m2 ^3 W8 y  r6 xstatic void do_it(void)
% F, d' T2 _. ?4 t{; |) A% d. q" C* ?# _  P
    logical is_initialized;
" u" b# j  x2 M+ B    int object_count;% j9 S# \0 Q+ F
    int type;: H% |1 |  s$ a& \
    int subtype;
! N+ p, g( J( M- {5 E% O    tag_t *objects;
' y4 D$ ]4 P, s, L9 Z
3 {! v1 V+ x4 b" H( T- L
% U( L3 _/ P7 }# s- y

1 [7 O7 o: U" f. k7 g7 d

1 ^. M5 g% ^! W9 X/ P    char mesg[133];
4 Y: P+ O  ~0 X% Z; K7 L" f4 }7 {" m; z0 @

% J( o6 F6 L( q    // Get the work part1 t6 \) p) U2 C
    Session *theSession = Session::GetSession();3 N( b' W% i! ]
    Part *workPart(theSession->Parts()->Work());
5 k  |5 j6 F3 ?, a) ^9 L) W% [    Part *displayPart(theSession->Parts()->Display());
, y9 H9 W" z% O* g- {. K, y: C4 w) S  ^4 N3 V) T8 E  w; x+ g
- l: U" R! f" L; y3 f9 w4 r) N

0 E/ R$ h* ~5 l) m- b

: [$ r3 y& |# a    if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;
! Y6 V- d$ w) Z6 a+ ?. S$ u3 |+ X* `7 q7 X
  [( |2 g, h; ?6 |: x' n8 h
    /* Get selected WORKPIECE object in ONT */
$ T- T3 z. U, ?- c7 W    UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));  n3 b' w! A2 @- u4 g3 I& y% T
2 Y" W8 _1 t! j0 ]" N3 C0 |

2 W; n. m' M6 P, f1 n
% D( {3 x: p1 W# }! y$ v
. z* |& k8 E% ]6 E! i9 p8 k6 N% y" Y
    if (object_count == 1) {
: n- i# }0 {- s        UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));
" t' c9 g% \1 @( t) s9 a9 q& F, A! t$ g$ D, |7 G; C

  h, ^1 [5 J  |* N$ s# h% u$ l9 B1 D( ^  P
2 E& e7 J% G+ Q7 z  M- I
        if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {5 c3 b# ?$ c/ s  F* k
7 g6 ~$ Z! X) X# ?/ c0 r

1 D" N* L5 W3 E. V            tag_t ObjectTag = NULL_TAG;, ~; u% e+ {. s/ ^
, ]3 k  }5 X( ?# ?
# X. A& h4 _9 p+ U
            // Get the object from the WORKPIECE tag
7 D/ ^: I! u+ A: S            CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);+ N0 C4 r0 r7 n& ~7 C6 M& a% h
9 p( |: X+ h' x( J, L
( ^! K1 \9 w: t7 i7 n* M( Y" m
            CAM::MillGeomBuilder *millGeomBuilder1;
- ~0 ~8 D" i2 Q, @+ K" [            millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);# f, P  @, \' S4 l! X1 @0 @9 O0 l) `9 ]

! {( m6 j$ h8 R3 X/ P
& Q- n( L5 C! a0 f0 N5 k$ G
            // Get geometry set list
; L3 f$ L1 m% v% W3 C1 Y            CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();3 q+ V$ Z( L& Z$ m
            std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();
* h, A* I# D0 }4 E5 z: ~2 l) }, C$ J% ?! L2 S
, R  _& s; W+ i% q& O
            // get geometry set% c- z' K) l% f5 ?
            std::vector<CAM::GeometrySet*>::iterator iter;' A. @% F1 e9 t' @
            for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )
. h7 C  a* i  K2 g3 T9 e5 x3 F            {
# H0 n$ j. T+ E8 G! K                CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);
4 x) K5 [! E" K6 J# Y& s. N$ y5 g                ScCollector *scCollector = geomSet->ScCollector();            1 M: R& i: Y3 l- V
                std::vector<SelectionIntentRule*> rules;
. G: J/ c2 f& T8 U4 Z5 t1 i  X                scCollector->GetRules(rules);
: ~; K4 F. h# P2 G$ H, P
& Q& ^* z" x$ Y; G/ W# y

8 r: V( O& m$ Q* d0 v                //get selection rule
0 |: O( c1 z, k; U                std::vector<SelectionIntentRule*>::iterator ruleIter;" v7 q2 {1 F2 [5 j2 b; ~0 F6 D
                for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )4 a5 t3 n! V" t! S8 w" T
                {" H1 ~8 Y+ C* t0 l
                    SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);
! k$ f" T8 q+ S5 {3 q0 @* R                    NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();
8 }; H5 J- o/ l( O, ?                    //there are different rule types, here just use body, face as sample
4 y8 b) S( ~' b: y  R                    switch ( ruleType )
& }2 M0 ?- h' c  P8 d8 c                    {
5 w1 @6 `& f9 U                        case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:
  l9 n9 Q  t% d9 o                        {
" H- T0 o; x+ O1 J                            //get bodies
  j1 T9 T; A( j" _; |! b9 e                            NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);2 c4 \6 E! ]7 g5 C3 c
                            std::vector<Body*> bodies;* G: l# B/ \* V6 H7 k8 O( n. @
                            bodyRule->GetData(bodies);
- H& d  S# b$ u: K7 G) s; }- ~2 R) }                            std::vector<Body*>::iterator bIter;8 O" M5 `  F' |& f) Q1 T
                            int index = 1;
+ g2 d( v3 [! V2 H0 }' Z) Y                            for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )2 |6 H* e3 {8 {
                            {
/ k- S; x5 [- `3 z  j+ j  r8 Z4 _$ u                                Body* body = dynamic_cast<Body*>(*bIter);
- f8 r: U/ X! J# Z0 C4 {                                ObjectTag = body->GetTag();
5 r, B. ~  a& q                                sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag);                                
6 P" a, T5 U! x" Q( o- `) C/ V                                WRITE(mesg);- b1 Q  e" s( K+ |- f3 w6 g5 p
                                body->Highlight();
& s, c5 ~* m+ C% r! B0 r! C0 V+ p  R                                index++;8 ^# j. m- r7 z' `
                            }
2 E' _% o! ?  e' k1 [' e                        }
/ t2 e' }- Q. }" J" ^8 N                        break;. z8 O# y/ h0 a0 {( L
- P1 i8 B7 ?% X7 L

7 y: ]: _9 g$ N) b* x                        case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:! _9 G# M3 i% n
                        {
- R7 X$ H5 f3 ~1 g, k. g                            //get faces
7 z  \3 x3 J! N& K                            NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);2 h8 ]5 r- R! {4 ^' O
                            std::vector<Face*> faces;5 D( {: E8 b+ G1 r, b7 Q, L
                            faceRule->GetData(faces);: Z; X1 X5 R" x2 e6 z8 ^
                            std::vector<Face*>::iterator fIter;$ b) E, c) A# D1 p5 _
                            int index = 1;
: y1 U9 B1 V7 V9 _4 J                            for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )
' s- p4 |. e4 R& K( Q! O                            {
3 E) L: ~  o; G3 `% r& E                                Face* face = dynamic_cast<Face*>(*fIter);5 F0 s5 p1 d6 ~
                                ObjectTag = face->GetTag();/ I, x3 m  Q  |; E8 [2 o" D7 t( W
                                sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag);                                
& ?3 d0 R% Y6 y7 T9 a$ Y                                WRITE(mesg);
/ `9 @4 I. g' F, _: P) D# ^- c% d                                index++;# h/ t$ h& h( \4 Q3 k
                            }
; c3 v% @4 o$ U. V' S0 w/ @                        }6 b; m0 M7 j( m
                        break;4 F0 M+ C; d, R! t$ T2 P

5 @" |' m: U# y# R6 L9 c; `; A0 n7 M
" }' x( g5 ^3 J6 S
                    default:$ }1 s6 h5 F+ g' ]6 y# i+ n( X
                        break;* b$ ^/ K! E! j
                    }( v! y4 i( g% X0 [+ f( y1 o  o
                }6 p" S/ T# v! b' T2 x
            }+ q4 y) q# f  M+ Z0 _6 b8 ~
2 H/ H, ]! P/ X. F6 D% n
' W5 C6 V  {9 H$ X$ F: }6 v; p6 }
0 X  r$ q- S7 u# N& u% Y( u

& M* q0 H2 n0 H: }3 M0 F3 Q
6 _) H& N. x& s9 w9 t
" K' a( ^8 U9 Y. y
            millGeomBuilder1->Destroy();
" t. @, W. p% \4 c8 C4 L' r
- U0 F4 T! }- M( S! B7 B, L1 y; L3 C0 ~& \

' O& i. t! i% S: p' u1 D        } else {1 g. v  f; A' v  G" e0 r
            WRITE("type is not UF_machining_geometry_grp_type");8 I2 D* a' }4 g8 M6 ^: z4 E
            WRITE(" or UF_mill_geom_featr_subtype");8 @" f1 s+ ^( s' ^" u9 y
        }
9 \$ I6 S7 A- m; u  v        UF_free(objects);
& V7 o/ B5 @' |9 r' J" g3 U7 C; R+ q; U

1 m9 n6 f: x- X$ ^) M3 s5 M    } else {
7 Q- |$ ], E" I8 f        WRITE("The number of selected objects in ONT must be 1.");
+ ?, b6 l  `" w2 ^7 r- B8 X7 J    }
0 p7 K' W/ B+ D2 s  A! M; d6 a- w' ?' B

# l" d, W- V' r/ _" ~" V}
+ ~/ h! r- Q7 i. h* ?; ^. `1 L0 E- ~! ]) C3 N1 L  c: X- Z
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了