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

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

[复制链接]

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

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

admin 楼主

2018-8-23 08:32:50

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

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

x

) N! n& Q* g& ^8 ]0 w( u% u9 UNXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值, d# i% O" L# c4 |* R
9 C5 Y+ i6 L3 Q- X( S9 Y3 }$ h
6 f9 t/ c$ g: x# @4 y* Y
static void do_it(void)
% m8 b/ v. J/ [5 F) T{
6 {! T' z7 L; |5 j# b: {    logical is_initialized;% r7 d( X+ P: r
    int object_count;
+ l. w/ T. K/ X: I8 A: K2 R* Z# B    int type;
, X6 y( \# j6 X    int subtype;* `" L/ D  N" a2 _0 i( Y; d& c
    tag_t *objects;' E  Z- F* `! C  v. [

" c* C8 j* g; n
( Y9 R8 T$ `# L! E, V. P
) {6 E' c1 r% D1 j1 u' e
" s& x/ K; s* E: i
    char mesg[133];
5 B/ T  S6 _( U: X) X; K
! o0 N2 N; c; u' O
/ D5 B4 n: Q  G" d( P
    // Get the work part
" w, ]+ e" N6 K' X. P' Y2 G- ~    Session *theSession = Session::GetSession();9 G' [3 S; K+ P7 f  ~4 C! I% ]1 E/ k
    Part *workPart(theSession->Parts()->Work());
! i  v2 R& o0 a8 y& Y    Part *displayPart(theSession->Parts()->Display());' \- k8 m8 W3 I. p, T9 L

. t3 H/ H) O' ]2 }+ g  r+ B

& |; H  c% {  P6 x7 G8 c* _% a
: O, z& ]8 K; t. N6 Z. C: v
; t' b7 Y- R# r
    if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;
0 \+ E1 ~6 x$ G, r! t. G  u+ C$ _
+ e, [4 u* i( ^% j9 Z( U4 R' l7 w$ I
    /* Get selected WORKPIECE object in ONT */
" c( `1 k. ~1 t6 x% i0 q    UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));
/ k3 }- q/ O4 o% [& Z. @! }( k' v5 f# n, n
/ T+ ?2 @1 c3 h5 h( D) O5 h
6 l: k4 w; _) @6 I! A
. w) D0 P, z+ k$ S
    if (object_count == 1) {
5 t; j" G2 d  F3 @+ n6 v        UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));
9 Z! l7 Y' ]9 d) Q1 C& `* G# l8 f8 d& }1 m

: A% {- U8 R! X0 J, d6 j  Q1 `- u" \+ }3 X8 V0 F- s

. m) Z2 T( }% V* l& F        if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {
! l" h2 c9 Z, \9 M3 W1 @4 |- \6 R7 g. ^4 o
' j- d+ h. W7 m$ B; [4 F$ Y
            tag_t ObjectTag = NULL_TAG;
  I4 J, F( z* y5 e# d) C0 V1 ^& z& u9 t

9 V. k/ T( c  @6 u+ y  R            // Get the object from the WORKPIECE tag! |8 x8 ?! @- P' W
            CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);
" P: R/ o* `( A! X! \# C, }3 ^+ V; \; w1 E

, L# f6 s: e3 J7 M5 H/ }            CAM::MillGeomBuilder *millGeomBuilder1;8 g* ?! N8 u3 L6 v. X/ m3 k
            millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);4 D3 I. j: g! l* `

) t% W7 V6 p/ x/ {9 @6 p) d( ^
/ D7 c- A/ b1 W) F" J6 L- U& c
            // Get geometry set list
: t  z: H' \, j8 }0 Q, w. N* B            CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();0 ^( w/ o& o6 f, ^9 L6 p1 x/ {5 K- w
            std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();) p  I5 D. c& L2 u
) @& D7 |9 G+ Q

- l2 F8 i5 R" K9 T            // get geometry set$ O' U% K; D2 }) K* `; \) @; ^/ B7 y
            std::vector<CAM::GeometrySet*>::iterator iter;; \0 V; S- v6 G# p: S
            for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )* Y, Z6 Q! K  i4 o' s$ T9 ~! B
            {  i+ w9 G# Q1 M! D8 D1 I, g' p
                CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);: ?  I& P/ \3 K- q# z3 S
                ScCollector *scCollector = geomSet->ScCollector();            
$ L, m/ e- d/ K1 Y0 w                std::vector<SelectionIntentRule*> rules;) z1 s& s' f2 {' c2 g
                scCollector->GetRules(rules);
" h! O. D' l" r+ Y1 u6 S2 e# L+ Q

  ?% H2 d9 E( x% I                //get selection rule
  m0 r* K7 |# m; S! i- w$ p9 I: ]                std::vector<SelectionIntentRule*>::iterator ruleIter;" a& u* B8 c; e3 V; w! `
                for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )
7 U; M/ ]- k; x  `& x                {4 h% J$ l" X5 Q
                    SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);
7 F% U& a! Y( b+ h                    NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();+ |. i0 D  p/ ^
                    //there are different rule types, here just use body, face as sample
0 B! b1 u! U4 C                    switch ( ruleType )3 E( [$ W( c1 u: K( z# m, V
                    {" U: ?5 @1 K# L) K9 \
                        case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:
9 `+ `; _" C3 q, j  a0 k. |                        {
9 P! s' U$ B6 j. r                            //get bodies % s, [  g% B! O5 k4 [
                            NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);
: `; Y5 Q+ q( E& Z2 m2 v                            std::vector<Body*> bodies;
6 E% \  ]2 o# t2 r  C                            bodyRule->GetData(bodies);  v4 K3 M& @; B
                            std::vector<Body*>::iterator bIter;9 c4 @, a' Z9 Y- J' e4 b. ^9 J
                            int index = 1;
2 P5 Y0 t# g7 ?" }7 R+ M9 J, I                            for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )* w; K0 e. |  Q8 L1 i, J1 y4 O: s% i
                            {
, u+ L+ `* U6 p, A$ b                                Body* body = dynamic_cast<Body*>(*bIter);
/ B: A2 h/ Q/ M5 h) G1 |, L                                ObjectTag = body->GetTag();8 ~" N% S6 q9 Y  k8 r
                                sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag);                                * _* L' w3 z3 ?3 Y
                                WRITE(mesg);/ m3 d1 I1 h4 \
                                body->Highlight();
) T/ T4 O4 Z7 ^$ t3 B                                index++;
; N* ]3 d! c" s' I                            }
* u. n& Z9 h3 Z3 a+ F, D2 k6 Y# s                        }
: P" \" _7 b" S# @7 l9 ^% A! ?( ~                        break;
8 a6 V% {" n2 ~* E& S- {
( |2 {$ W* L+ r- V* A5 T+ s5 q* s% B2 P
( E0 b& G, p  a3 q0 E, t3 f
                        case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:
! O& @8 B: z0 D) V                        {4 w% M( r; P' H( m
                            //get faces 8 ^2 L# S5 d$ n/ S( }
                            NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);
$ u7 b7 Q0 b6 Y4 A                            std::vector<Face*> faces;
% H- {+ C1 c* @( a5 `                            faceRule->GetData(faces);
" i" y. q' F) }7 B2 c' ~                            std::vector<Face*>::iterator fIter;
! H( e2 f3 l; w, O# L$ Z                            int index = 1;
) g. Y1 c" q' }/ Y5 S4 M7 t9 C                            for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )
+ ]0 m. ~% x1 v2 O2 ~. V                            {
. n: ~2 K( X/ u0 v, `                                Face* face = dynamic_cast<Face*>(*fIter);
- ?& B/ H0 @' t" \! n- D                                ObjectTag = face->GetTag();
7 O- r; C$ G6 z5 |4 q* i                                sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag);                                $ X4 [; K  w5 X7 A$ p- `5 c
                                WRITE(mesg);
) p. h% M: o) V! s+ @1 d  u2 G                                index++;6 M$ N* v" }3 z" O5 L
                            }
' k$ A  p7 l# ]3 \. ^4 ~# m& I8 e                        }
9 S% G& y$ }; Y$ t1 e& }2 G( N                        break;
3 R3 Q& v8 ~  D. I$ j. B; ]$ Q( U9 T, \/ A5 @

) C% r9 y5 U1 c                    default:
$ n' E' N1 i1 g6 O" X5 N                        break;
& v1 `5 ^) g0 R. j                    }* }' p/ X0 u! S( @! u! y* T4 V
                }
0 o* ^: }. ~" C- r. _& b! f) O            }
  D" y0 V9 U7 G3 v9 _; `/ Z
: C9 }5 h8 f: Z) {! T
% Z' o' `" u+ s1 d

& w% Q3 u! s! W! _1 a9 q
3 ?3 h0 b3 x% E* T  g5 j3 z
3 E9 @) \' S4 V( e3 l: O

7 Z* I8 f! G- C/ Y6 G2 k9 }3 r            millGeomBuilder1->Destroy();2 U' J4 U& c7 W4 m! f- ?

, e0 N* z* I* g$ p- W- |

0 i- b5 j3 N, _- R# J( b1 Z        } else {
8 K% @' o5 k6 n% h* f3 U  n, b4 _            WRITE("type is not UF_machining_geometry_grp_type");
/ |9 h. E5 Q+ B            WRITE(" or UF_mill_geom_featr_subtype");7 I5 f- w; y  w5 v+ B/ R
        }( k, I! K! z. d4 ?6 c
        UF_free(objects);0 G! L7 L0 A  }& T# h
+ N+ S7 D/ i& a# i

) t3 J: R5 F( `( u- H    } else {
+ T6 _9 O5 ~6 P4 U! E5 p        WRITE("The number of selected objects in ONT must be 1.");
7 q0 N' t5 e, e    }2 s3 U& g, {* h: w6 i; L
9 _: a' t. h( e& p# j  A! j- F

5 }: q' A6 S  h( g6 v}
' D- |/ Y+ d% W/ a# u+ _
6 h9 b( M% \( f/ e
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了