PLM之家精品课程培训

PLM之家精品课程培训

联系电话:18301858168   |   QQ咨询:939801026
NX二次开发培训

NX二次开发培训

UFUN/NXOpen C++和实战案例

适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术。
公众号二维码

关注公众号

点击扫描二维码免费在线高清教程

课程详情
Catia二次开发培训

Catia二次开发培训

市场需求大,掌握核心技术前景广阔

Catia二次开发的市场需求大,人才稀缺。掌握开发技能潜力巨大,随着经验积累将在汽车、航空等领域有所作为。
B站二维码

在线原创B站视频

点击关注工业软件传道士主页

课程详情
Teamcenter培训

Teamcenter培训

全方位培训,从基础应用到高级开发全覆盖

涵盖用户应用基础培训、管理员基础培训、管理员高级培训及二次开发培训等全方位内容,由多年经验讲师打造。
QQ群二维码

加入同行交流

点击扫描二维码加入QQ群

课程详情
×

PLM之家plmhome公众号

课程涵盖: PLM之家所有原创视频

×

关注B站视频

所有高清视频一览无余,全部在线播放学习

×

加入PLM之家QQ群

同行交流,疑问解答,更多互助

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

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

[复制链接]

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

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

admin 楼主

2018-8-23 08:32:50

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

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

x

( I; s2 a- o3 vNXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值0 h2 p. Z& W0 {9 r( w
' |- A$ @) f% W% y# w1 o* Y
1 W) V5 O4 f8 X# D# h
static void do_it(void)2 M9 f( O. n; Q; P$ B
{# ~6 ~) d; m$ l' S* L5 c& o8 \* _- x
    logical is_initialized;
' ~, R6 r( Z. t% w/ {! h- I- u* o4 o0 t    int object_count;
3 X0 [1 @9 |* M$ Z    int type;
2 |+ L- a2 X+ v  G0 v3 x$ l    int subtype;
! P: W& u5 M$ D% [7 r; D! O* H    tag_t *objects;
; H; ]% l+ B( d% M
$ \! r5 e) R1 H6 ~! z
4 _, `4 S; Z2 R# t

3 }$ _; A/ A+ \/ c  H! d7 C0 G

1 N$ _" Z3 p7 y1 u8 D    char mesg[133];: t7 ^1 ^5 v1 M6 H
8 y/ u* _( J2 N
/ H, k  R, ~' b9 V% g) R
    // Get the work part
9 {5 T. _1 z5 J8 n    Session *theSession = Session::GetSession();9 {+ R* N8 D! v0 B' ]  L
    Part *workPart(theSession->Parts()->Work());
! ]/ z4 e* d- X  k% B    Part *displayPart(theSession->Parts()->Display());- y. P& P) k. `, N8 @, N

  v' u! x$ s0 x) y  u2 P
0 `% `/ E1 C" B

; ~! F+ C6 w! b4 Z+ b3 n

0 A: `: q+ z- n+ A$ v    if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;
5 ^/ @) {* U; I2 u2 g
+ r9 |# Y+ d8 F8 E! l

4 U7 v  U6 O% B# Z/ I    /* Get selected WORKPIECE object in ONT */# w, A2 a* y% A3 [# F* d5 W- m5 g# F, R' I
    UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));
0 M) Q/ U8 }* Z5 i  V$ l  e5 ~/ M, v6 |* |/ K3 V  J; j

: U# V; W0 M4 N" l" p9 D4 S  u/ g' A6 D! W: p4 Y3 h. m

; p0 X$ G) {; p; C) ]+ M$ d    if (object_count == 1) {( `2 j% ~9 p. g8 X1 I" s
        UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));$ K% v. o/ s$ `( g, N6 V# K7 W

7 f9 ]1 Y$ c% m& e5 p

6 [+ Z/ a3 n8 S+ h8 C: v4 r% o9 B, N- S; t
! c$ x- S2 c& C+ z
        if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {0 H: L3 d) h) H0 p, P0 {
8 u  }2 Q6 _* j5 C! w/ s& ^

3 R- ]" D& y2 |; z7 E0 V9 E  O& v2 \            tag_t ObjectTag = NULL_TAG;* K: M; }+ t6 n8 G

6 Q" O8 {  s( }* L$ |! \2 k- {
# p; s8 q& c7 `9 ^4 |; I* p
            // Get the object from the WORKPIECE tag9 c! n8 ~; t) P
            CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);/ u2 I# ~7 \0 F7 s* e1 |

+ B, F) X3 x- o0 H  s2 s5 x

+ P0 O/ P0 N! F            CAM::MillGeomBuilder *millGeomBuilder1;7 N0 y. X6 t3 a0 \
            millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);2 t/ ?1 t4 `. I! t

( {, A1 X+ @# K. n  t  ~
* Q  X/ h* i* q" t+ y- c* x
            // Get geometry set list3 V- o. U4 B+ J8 V  s4 v6 H
            CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();
' M; J! V5 L6 @" x- }8 h$ I! [. T/ A            std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();2 i' [/ [, ]- K4 X- n
$ X' G4 L0 Z9 V* i' [

% w+ r; d6 E) n            // get geometry set% l: S. O9 C' H8 c+ Y4 l) t
            std::vector<CAM::GeometrySet*>::iterator iter;/ r; h2 A% D2 b# \" o( P8 E
            for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )
( P0 x8 o+ a% X( R% P  @) h! J! p            {3 t, v0 ?+ o( J0 B. n, u
                CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);
) O0 D+ a: Y* [7 n4 \* O2 k$ x! B9 s                ScCollector *scCollector = geomSet->ScCollector();            
: Z' ?+ \6 W/ a, C                std::vector<SelectionIntentRule*> rules;: ~6 S4 X5 O' f8 O( R$ a: o; ^
                scCollector->GetRules(rules);/ s7 Z; f" r# \  M

; p+ ~- x. h# O4 o
4 u/ z1 E- t. _5 a- `
                //get selection rule" R3 f, p. j  Z; p% |; y# w+ W
                std::vector<SelectionIntentRule*>::iterator ruleIter;% H. c# T2 ^# {( k9 Z3 G, F6 g
                for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )
, U; h+ ]4 w7 \& l- Q$ q                {' E) j" h! |5 T% x- r7 [
                    SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);
) v) g0 z9 J$ o) T0 q                    NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();
$ G. P9 y5 s2 o- j& b8 @+ N                    //there are different rule types, here just use body, face as sample
) M2 H, m  e9 U& s: |                    switch ( ruleType )) C. c: O" a! S' w& Z' [
                    {% r% y5 U! e3 \2 I# {+ C
                        case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:
# s7 o+ ~& W( [                        {
4 s, l- X6 R4 Y9 m3 q' }                            //get bodies / M$ x% O& n) l# }0 r6 Z7 p2 J
                            NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);' O4 H: k2 E$ Y0 L
                            std::vector<Body*> bodies;
, _; V7 u7 P$ O. q                            bodyRule->GetData(bodies);3 Z7 |* V4 {) C7 k. p* f
                            std::vector<Body*>::iterator bIter;. I: b  U0 n) A9 _1 a& a* n; F
                            int index = 1;' m3 d# A  ^2 @& l  `. u2 h
                            for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )# p; o( t' ~# Y& c
                            {" {& ?; E& D. c0 L
                                Body* body = dynamic_cast<Body*>(*bIter);
" |7 P- ~2 h2 z) P' L5 x  A6 t3 p" Q                                ObjectTag = body->GetTag();# v* Y: S. ^7 I# V+ u
                                sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag);                                5 g0 k% W; h. c
                                WRITE(mesg);' i3 }2 T+ q3 m( R& L
                                body->Highlight();
+ n  F7 L1 n# N- I& h& @                                index++;8 s0 _8 s) U6 V" N
                            }
  Y( i& l" {2 J                        }8 y$ p1 w) V+ a* z2 O
                        break;; p5 N2 e2 O. W8 y
0 u  p# K5 v/ ^# q; w4 D
: a; s8 k; G& Y( N$ h
                        case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:9 k4 h2 e+ P  j* \
                        {4 X1 d# b( }) X3 d4 q# P
                            //get faces ( v- R3 Y5 y& Y$ b, z5 p/ n: V* ~
                            NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);
+ i+ g  M8 |- g0 m0 l2 u/ E                            std::vector<Face*> faces;, u# _/ z& w/ I; C' A
                            faceRule->GetData(faces);
# K% [( {) u1 G) q; ^                            std::vector<Face*>::iterator fIter;1 y% ?7 v) ]- k3 m+ z5 g3 J
                            int index = 1;9 @9 o+ R, G  }' ~' |
                            for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )' G* D8 U( g6 T; B+ R
                            {+ e4 l8 U" D+ K( i
                                Face* face = dynamic_cast<Face*>(*fIter);
( \# C; v4 r8 @- r& X1 G                                ObjectTag = face->GetTag();
- ^2 c( ^% y7 }8 e1 b; R: p4 i                                sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag);                                + Y2 K- s6 M6 N6 d. X
                                WRITE(mesg);
0 {8 I- K% ?) N3 i: d5 P6 Y- I  u                                index++;0 m- d3 g- Y& |
                            }
6 ]4 d( U! H; l- a! V                        }
, m- N3 B! z5 F+ }6 v                        break;
; o3 ^- v; M6 J% b" K
, X. l; ^( U2 ~; P, g, C0 s- Z
9 K9 l- y/ ~% L
                    default:; r2 d; p9 F) E* t
                        break;  t9 U8 p6 I, A! ]: J# B
                    }4 \8 w/ ^6 {3 J+ u
                }* V. g$ ?5 X1 Y
            }
- F- Z1 x' G: s: c- k/ \. L2 i) z6 r9 G, }1 n' n0 H- N

1 P$ b- W. n, `; `7 ?6 b7 K, H& u3 N- [7 b" i
- k* F8 X5 g2 y. c1 @: v. |! G

8 @9 U7 _7 M: ~0 P4 |; F! P

+ u. T% e; k0 e. h. j! j/ m4 m  [            millGeomBuilder1->Destroy();
  q8 V& _% J- e# z  u! P! k5 l/ A0 J7 S7 X* |. p8 {
: Q1 k8 f0 e- R. O* m+ q
        } else {
' \% Z/ r* s; c. T0 V2 _/ e# c& t! }            WRITE("type is not UF_machining_geometry_grp_type");
7 R- v) b& Y. |0 n' N- P  \% x5 ^            WRITE(" or UF_mill_geom_featr_subtype");  ?+ P1 \* Q5 j/ i+ u
        }3 E1 g) i1 ^/ s5 B3 i3 B- J/ M1 X
        UF_free(objects);
; b7 Q  K% @' B
( |% E$ C1 X4 c, j7 m

6 N* t, e0 t6 Q2 ?: U7 X  R' U    } else {
1 _1 J$ ?) ]- `7 O  C# H        WRITE("The number of selected objects in ONT must be 1.");
/ O& d9 w% q: X- y, p* c' F    }
0 w! i: w2 W4 y/ B9 H: K" N& Y# u& A. Y( q- N, c4 p

5 J* `% N% [! {! B* I}% g" z' H0 R: e* |% T  \$ ^& C
6 }1 V, y" |' S, l: f
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了