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

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

[复制链接]

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

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

admin 楼主

2018-8-23 08:32:50

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

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

x
& J; v2 d) v4 w" b4 D0 z
NXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值
! r4 k) [9 x4 w! Z" e# z8 k+ q
2 w) M  x2 H  p" B  l  t- t
3 A# P+ I2 c( N2 hstatic void do_it(void)3 h0 S: M6 D# D% h- d, Z3 j
{+ o7 m! H% J  R0 b
    logical is_initialized;2 `' \) ~2 x6 d
    int object_count;
! T2 U. z8 [; O3 ?* p    int type;: e/ y# y3 @8 c0 d3 J; h
    int subtype;
+ i' _0 T( f& X# o( f' ?8 e    tag_t *objects;# M) j  Z8 y8 O3 P8 r, V! b
" ?- d- p& e4 K8 a! Q2 w

9 R6 U6 I8 e5 @
  S0 |* L" O& H0 ]
" i3 Z! t+ d" t! X2 N0 A9 w
    char mesg[133];
1 ]+ X. K7 @. |; i
. k3 _# z0 W7 v0 Y- J# }" Q7 Y

+ d( x) }% g5 \* R2 s/ b: Z8 l    // Get the work part9 }( ]  Z/ q- \
    Session *theSession = Session::GetSession();
2 U2 v+ o% W) r6 o  X    Part *workPart(theSession->Parts()->Work());
+ P. B. c! \( s5 k. w, M& @    Part *displayPart(theSession->Parts()->Display());
8 P3 ~2 c. i  h- e) y( d
4 i& z  k- j1 l8 t( a* @# [1 k' i
/ w1 o  ?2 K* u2 R6 G+ L
5 h1 j' g7 i' x' _) j

1 f* R5 {7 w! v9 Q- \" b: q( O8 B    if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;
; K0 X4 P' V& H1 V) P; |7 _, L5 v/ O
$ P7 b2 Q. p* q' _
    /* Get selected WORKPIECE object in ONT */
- v3 G& \$ `& g- H+ x    UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));
8 {, a  s+ c8 o% O0 o& V
. o' `  S0 q% @/ s- e9 s4 v
7 ?. \7 t7 X/ r* Y5 v8 p* m
. P! b; l+ D' r1 C4 G, S7 O
1 B/ Y" H4 g" p4 V! H
    if (object_count == 1) {. D6 E( z4 S* U1 W) y8 R
        UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));
- f5 }, [3 K2 I8 @# @& J( T# g$ e" F: |, A) `: L
/ Y; Z( b% w  o" i
1 ^' D2 K3 G0 ?/ }3 h7 `4 p1 A

7 q( K) r5 P" D% C' E' q5 }        if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {+ R) e$ J$ C  k+ d( q, X

7 Z* n! r6 S2 i
& j/ \5 c0 u0 v3 W- N. g
            tag_t ObjectTag = NULL_TAG;% ?: [( L) i4 I  S( Y; Z$ ]
% p' w& R  e8 v4 V% {$ ?( G" y
( n* V/ \/ w* _
            // Get the object from the WORKPIECE tag
3 c& Y* z$ _: o) u6 k' X1 x4 o            CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);
5 H: \, ]+ G: x4 o
7 ?- E, L8 Y! R# O0 y, ]
$ {) [, X6 P' d" i; D
            CAM::MillGeomBuilder *millGeomBuilder1;
( Q3 U! d* G+ @! P            millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);
6 e& L. {/ y8 r0 Z* c6 }
* l  `5 n! m- H

* t0 `' X$ f2 R% U  W. f            // Get geometry set list
! K" _& b* p, j' G! m$ l            CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();
! P) G4 S. P7 C, [3 d, c4 W4 f            std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();9 D8 E% I, w& S# C4 L6 @
# h: H6 E& J1 N: }# R
. ^2 g! b( X% D1 A" |
            // get geometry set
9 R- _4 Z/ i2 o- b            std::vector<CAM::GeometrySet*>::iterator iter;" a  I- i2 @2 z
            for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ ). D9 Z- n" A. k9 ^- b! D7 K
            {$ `' _- y1 C9 F, H- N
                CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);
+ e4 D+ n* ]! z# D5 M5 z& {                ScCollector *scCollector = geomSet->ScCollector();            5 d  V; G# W8 N+ n: h8 W, a
                std::vector<SelectionIntentRule*> rules;3 f: ?$ a1 b, B2 [. ]1 H
                scCollector->GetRules(rules);. R2 ?# ?8 v$ G$ r

- O( d2 o1 U# Q
% w+ T7 y6 J2 K( y
                //get selection rule
5 f* `" S& ~3 r: Q  T7 P8 }) H                std::vector<SelectionIntentRule*>::iterator ruleIter;4 h/ k& {! b( {, w2 R
                for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )/ O6 ]% y: P! G: t
                {: V- ^9 S; [  n  y5 r
                    SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);
0 N$ U' X# k4 L; b; C! G                    NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();
- A" d1 S) C5 g+ a! \* y7 f; C                    //there are different rule types, here just use body, face as sample2 `1 M3 ^0 u6 r- s. v3 G
                    switch ( ruleType )
: V5 |* o- O1 C, c% S                    {
% D6 ?" {2 P5 G( N- n8 G1 N* @                        case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:% Z1 ~( Z7 x, U, G) j  `
                        {/ @. s+ |# x! O
                            //get bodies 2 d0 o1 v6 \4 v+ E, O
                            NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);
2 `7 @1 V. T1 O! v& W- R2 C9 X                            std::vector<Body*> bodies;, s3 |+ f3 |0 W4 S$ M
                            bodyRule->GetData(bodies);
/ J  o. T: Z% \: ^" K9 P) z                            std::vector<Body*>::iterator bIter;/ ~9 W& h+ \3 n! ?# B: D4 c
                            int index = 1;5 I  H8 c5 O' B7 b: J! E
                            for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )
+ j4 k& P) V3 g) Y                            {
) s4 F% U% w+ B, Z/ w/ M+ D; b2 R                                Body* body = dynamic_cast<Body*>(*bIter);
1 i0 |# \5 n2 J: ^2 l( k$ w( Q4 ]                                ObjectTag = body->GetTag();
$ D& j" r. c- U  ^. l! {2 I1 i                                sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag);                                
# {0 N: E! {) l/ l                                WRITE(mesg);
: Q7 T6 `0 G9 x  J                                body->Highlight();
0 s/ W' H% |# A: V                                index++;  g4 ~9 r. w' Y# w
                            }
( Q. O' n$ x( `                        }  O, l2 _/ D9 b+ ?; s
                        break;
3 ~. L4 m' Y7 e/ y2 C: K3 m# n
* v) q( ~; F; F( E+ ?" l

6 {4 L# |6 P& \- ?6 S                        case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:  c+ {& M/ [: _5 i, V% B
                        {
5 y$ Q) K) D& t                            //get faces , p- Z1 F3 t! m; x% [3 X0 q. o
                            NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);
$ f2 j0 }! |9 r7 W                            std::vector<Face*> faces;
) O% s2 k1 K6 M/ T                            faceRule->GetData(faces);
! k9 E: d6 h7 u6 ~' R; V9 x                            std::vector<Face*>::iterator fIter;
- G6 E9 C8 k' S2 @0 V7 U% n5 }                            int index = 1;
, |7 Y6 Z' r& L1 M. B) S                            for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )
: K# }( Z; P- s8 b                            {
, b7 D! K3 w3 B                                Face* face = dynamic_cast<Face*>(*fIter);
6 z+ B6 M, Y- P/ \) g                                ObjectTag = face->GetTag();  k2 ^* o+ G: v' _
                                sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag);                                
, x* u8 N( Q2 w" d                                WRITE(mesg);
! \, k) u, C8 N% m                                index++;
- ^8 a# L% c0 j7 q/ {" d; l9 o                            }
' ~# j4 i5 Y, i5 e" K/ W                        }
. M  e! {/ O1 S3 M) W+ K7 H. ?                        break;
* G. o+ x3 e/ G. G) ]3 Q; o* |
* y* H. l8 {( U' |
/ H  N& b  E! x! U, B
                    default:
: V% Q( [  w! ?5 i% d. _                        break;9 N0 e# a& ?! d3 L
                    }5 A% N/ ]  A8 j4 |8 j
                }! R- V, P- t- S
            }
0 h$ Y: X# w7 Q, i: H* z* M/ e/ G  y' C* ?
) ]; T/ C1 M) |3 Y! M& }+ \
& J( ~# N1 \& E  d
1 H, _& J3 q0 `: T
7 h( M4 N' R1 x0 L. ^, N( O
2 z6 T; N. U! V( M' x' U4 x
            millGeomBuilder1->Destroy();
  u0 ~4 A' {4 z9 l8 J
9 ]; e# R# g5 r  s5 Q
" y0 L% x" x4 D
        } else {* T7 u& w6 q  }  I
            WRITE("type is not UF_machining_geometry_grp_type");
" {8 p' P$ z# I8 y; c; I" i            WRITE(" or UF_mill_geom_featr_subtype");: ^3 e3 L1 R: c: R0 _. o6 n/ U, M2 T
        }3 r" \) f& C0 c' i' g
        UF_free(objects);% N# k8 \% J% a/ o, S
  m0 P$ h  ^+ k1 }/ L
) Z9 _8 c1 C: z# E8 D
    } else {  M8 d) R& Z# T& Z, c; ]* V
        WRITE("The number of selected objects in ONT must be 1.");
# _+ i% e& H' a+ s' g    }0 G2 k6 A  U6 f& }/ a
$ L1 t3 Q/ U4 u9 N6 U# v$ a
0 ~/ z1 l# i! q5 A4 V; j  H+ {9 [
}) L. z, L/ d& g0 ?, m1 S
" z" P. E! H; ]4 o4 L% 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二次开发专题模块培训报名开始啦

    我知道了