PLM之家精品课程培训,联系电话:18301858168 QQ: 939801026

  • NX二次开培训

    NX二次开培训

    适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术对于老鸟也值得借鉴!.

    NX CAM二次开发培训报名 NX二次开发基础培训报名
  • PLM之家Catia CAA二次开发培训

    Catia二次开发培训

    Catia二次开发的市场大,这方面开发人才少,难度大。所以只要你掌握了开发,那么潜力巨大,随着时间的积累,你必将有所用武之地!

  • PLM之Teamcenter最佳学习方案

    Teamcenter培训

    用户应用基础培训,管理员基础培训,管理员高级培训,二次开发培训应有尽有,只要你感兴趣肯学习,专业多年经验大师级打造!

  • PLM之Tecnomatix制造领域培训

    Tecnomatix培训

    想了解制造领域数字化吗?想了解工厂,生产线设计吗?数字化双胞胎,工业4.0吗?我们的课程虚位以待!

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

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

[复制链接]

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

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

admin 楼主

2018-8-23 08:32:50

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

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

x

9 T, {9 h3 |/ c% l1 ]NXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值8 |6 D3 m5 E( ~# u* V1 E* l' B8 G
. W9 k; S0 A! P+ @1 L& C

6 b1 S" l, L- [# F8 M3 Cstatic void do_it(void); O  s8 o6 A; ^$ }, I4 f0 h
{
# u" k" y$ m! {5 Q* B    logical is_initialized;
. ^* Z: r% E0 g4 M    int object_count;
$ [: }8 s% B" E    int type;
& U2 @8 j" Q5 a  R& D) X5 a    int subtype;# I4 {9 f& U" K; P; E
    tag_t *objects;, n0 B% I5 {4 Q6 {- O
- S; J: Q# R: @

% }7 l$ |/ R! l& M
1 N* R; V7 K  b+ Y% g
9 P% P& \) U# C. B" W8 [( j
    char mesg[133];6 G' d8 t, A1 a! b" }( ]  G; \2 Y
4 c1 o  _6 q5 r0 {# T) j
9 t3 X( ?0 s+ V$ z7 W6 q
    // Get the work part" Z" ]# D, e$ [
    Session *theSession = Session::GetSession();  J& J$ l2 L6 o$ `8 X: J
    Part *workPart(theSession->Parts()->Work());1 K7 o0 ?2 U0 e( ~! h
    Part *displayPart(theSession->Parts()->Display());
; j# p; e- ]1 C" {/ q3 g, r
5 a& s) M- E9 V

& o* e- a, I- L- a( D, u, [* ?1 s- _6 j7 X1 i4 g- ~

9 p0 m9 o/ ~8 n    if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;+ k8 F- H. q2 w& p) w
' z' L; c  I  L' D/ E. U/ N* V
) g1 h2 b# W& }$ X$ H5 K  o" Y
    /* Get selected WORKPIECE object in ONT */3 l: X! _' ^; {
    UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));
6 K) p- Q3 r! \$ a' ^6 q2 e; k
+ s) F3 n, Z) @
- A8 e9 X9 U, t6 l. I$ R

. _& R. X* `2 o- D

9 p3 X$ s6 I7 ]- Y! Y    if (object_count == 1) {$ ?8 E3 f( Z# }
        UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));
5 h1 g  }4 O, ^/ S# k1 n* q3 W- K. R6 H7 E! Z% Q5 [
; m- T5 c# k" J. y

1 ^, |5 l3 N3 V$ r9 D; p) c

7 [$ t0 \$ |8 ~* a& G* j5 [        if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {
& w" R$ n# {9 A
, @$ w. g5 Z( i( k+ q0 k

4 J3 I- r" E5 @4 B3 a- W            tag_t ObjectTag = NULL_TAG;# G% a. ?1 {' R7 X" [( X  R! N* A$ z

; [7 {! D- f6 [4 x1 l

: @' K8 X1 d3 \* v/ d1 g: d            // Get the object from the WORKPIECE tag2 y% J4 ~+ ^4 {" Z9 m% V' M
            CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);0 W0 C; w- s% f# `( H4 g9 v4 l

' z8 i* g. r2 b+ c) u
% c  ^" }8 X' X* k. L8 P& X
            CAM::MillGeomBuilder *millGeomBuilder1;. P0 B, \) F( H( w( `3 \$ V* C! H1 k
            millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);
4 _1 T$ N- \5 ~, Q% F$ `0 |; _  L( H3 G/ ?5 U+ S. B

2 I4 N( K! s: t0 d$ L& O            // Get geometry set list
$ H  C! D. t, ?8 M- u( i5 g            CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();
* u) s/ M2 b# u0 Z' _            std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();/ O/ W, z4 ?1 o  S

2 e, G  X& O: A6 j) `5 u* c
$ u/ E2 x9 Z) A& z! z. @8 \# q) p
            // get geometry set
6 D- W! n4 `' r2 V! A5 Q            std::vector<CAM::GeometrySet*>::iterator iter;# s2 @. D* }+ _4 e' j& b
            for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )0 ^+ H# Q! B  X6 X/ n
            {
, ~9 X6 T' F( ~* T                CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);
! ?1 ]1 A4 l) S: @                ScCollector *scCollector = geomSet->ScCollector();            5 _# J: g2 ^; b( v: _* F
                std::vector<SelectionIntentRule*> rules;
8 v' w1 d0 z$ W: h9 j5 t                scCollector->GetRules(rules);
+ K) e7 V# e5 j! f1 B! k
( ]& g& k, \4 U. _  ~) k$ I1 J

! {0 j. z; m9 Z7 v+ x                //get selection rule& H% F9 M- U$ S5 y: H4 Y
                std::vector<SelectionIntentRule*>::iterator ruleIter;
. C7 _  N& h1 T- c/ q0 J                for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )8 r( H$ G8 J5 Z8 K* y5 o
                {! }* d  p1 L0 y, r+ ^+ f. a
                    SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);6 }+ m1 z+ T( {4 \& A$ c
                    NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();
% X& d$ j) K0 L4 n% ~, _, K. {2 O                    //there are different rule types, here just use body, face as sample
+ M( V& t& O, I. \- B* T, o2 O: G                    switch ( ruleType )
) ]5 B: ?: N7 S- \/ X" [$ }                    {
! o2 ]+ ^0 W, m2 q/ V4 h                        case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:
' v, L# p4 S* m5 P, C                        {
9 t$ e$ {% m. A1 L; _( k                            //get bodies & u: t, u# c  @( A
                            NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);: n. z' t. w. ?) r  V2 P) ~; _
                            std::vector<Body*> bodies;
7 l+ B1 L7 S- R$ {% l) K3 S- b                            bodyRule->GetData(bodies);
! }2 K2 l6 |1 z! Z2 ^4 |                            std::vector<Body*>::iterator bIter;; D, @" F& X( C5 `; ?
                            int index = 1;! v" }: l1 C7 H* N! Q# h
                            for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )3 i# q' U# y' |- \9 c8 T7 P2 p
                            {
. C$ b2 n/ H+ ^- t: v# D4 m                                Body* body = dynamic_cast<Body*>(*bIter);
8 {- R4 G% W" n  d' m: Y                                ObjectTag = body->GetTag();' e* V" J0 J$ L: T( h3 n! R
                                sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag);                                
+ ^6 b. u2 ^9 `& L1 [' F. ~                                WRITE(mesg);
. R5 n5 e; Q* `                                body->Highlight();
4 s* L. y$ @6 {8 y3 W' `& B# ?                                index++;3 r5 c6 n8 ]4 p7 `  X9 A3 S
                            }' i+ `/ `7 O. b- I. K( {2 w/ A$ g
                        }
) H2 C% k/ ~' ^7 g0 [                        break;
6 }6 D( T/ \( g0 W3 b7 y7 ]
$ E9 }) @' i4 g# v3 w: w* p6 j, t
) U9 a, s9 @3 {1 H5 z
                        case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:
! i. d" u8 r* S% \5 a                        {
' t! S- o$ M- _! t; u                            //get faces
2 {& L( B. ]. L2 G4 X                            NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);  N, R. a- ~; [. O8 M
                            std::vector<Face*> faces;) N6 @% p# t7 J1 B2 m9 R# H$ |8 w
                            faceRule->GetData(faces);# j' O& M6 N& ~! A
                            std::vector<Face*>::iterator fIter;" R4 G; D; u* q6 Z+ U2 ^  P$ B# N) ^% z
                            int index = 1;
( z- a2 N9 H6 Z, z) m# A" n                            for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )
* V1 C" [* N/ R& y; p6 h3 ]                            {
2 U' o' G; m) P& c                                Face* face = dynamic_cast<Face*>(*fIter);
  D# q# w8 ^% {+ ~                                ObjectTag = face->GetTag();. F3 D' ^+ E  I
                                sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag);                                : X9 a; {4 U8 S8 T: A* ]
                                WRITE(mesg);6 l% l# A& ~1 Z! S' q
                                index++;
; t) v9 m" H) z- v! h                            }0 x+ e# y/ w+ S, \3 @9 v" x
                        }
' }+ Q6 g/ a1 {) S                        break;# H9 K$ b, m) C9 J: |

# m7 x% g! R. A5 `
6 Q3 [( k4 G/ A/ |7 M; Y% ?; @( k, p. f
                    default:$ L% g$ l/ f8 k4 p$ A/ X# D
                        break;0 y  _# p# u# F) r
                    }
2 d5 y, x5 E# j! Q1 Z. D) a                }# a5 J, o+ F2 [) t% D) d
            }/ Q5 F4 x7 s6 ~
% v" Z- |6 _" r

7 t5 U1 l# T: ~2 U3 E% v, S/ x+ ^0 v# r1 f- Q

+ c+ Y5 P( l! A6 O7 U3 x
4 q( S( w" L: H8 e  E# p# J  Q% D
$ x, o- y" F2 y4 u
            millGeomBuilder1->Destroy();* e+ E1 `: f& t! t
" q3 r: j$ j  K9 ~6 E  `1 G
/ U5 B, k" T% g: q5 a
        } else {
. j/ y; O0 s& Z+ D( F; K: m8 C) p            WRITE("type is not UF_machining_geometry_grp_type");/ J$ }# H& s& \; U/ f
            WRITE(" or UF_mill_geom_featr_subtype");$ U+ O: p, c& m  e1 a7 t/ O4 `
        }
+ U3 W7 }( d1 {+ j+ v        UF_free(objects);# \( n7 U: e: [# R
% @9 h, E2 {, F  n" V

9 ~) n- @6 s  R4 \1 F2 T    } else {
3 O& Y5 [1 g% t5 S! X        WRITE("The number of selected objects in ONT must be 1.");, V8 v) s3 i) b/ e% @" K5 J
    }
; M  H. o6 ~  b% u% _0 e) ?+ O$ k
5 n, y0 W. H  O- c# I' C1 }" Z
}
& F  U' `' g7 G! h* G; [: I% r: f$ K! W
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了