PLM之家PLMHome-工业软件践行者

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

[复制链接]

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

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

admin 楼主

2018-8-23 08:32:50

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

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

x

; W9 r3 k/ A6 r0 BNXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值
6 s3 X$ V1 t1 u
' N) ?5 W& d1 }: W. I& |. L7 ?; D2 G# t8 E
static void do_it(void)- G9 [# I9 N1 S% |# O! d, F
{
/ w, v" l# c9 ]1 H4 T. E. s+ T    logical is_initialized;
. L1 g: m7 x; l: t; r  d) M% \) D    int object_count;% `$ I" r/ c6 d% a  N0 e
    int type;* j  A5 x: ^5 x/ J* Q4 N) F. q+ D  }
    int subtype;
( q2 Q3 h7 e$ v) S: I: ~    tag_t *objects;
/ o4 V+ N" l# W% B9 W, T  W: P; L* j0 h/ X& {* y+ V0 z( N
: `, q# F' P6 Y# ?4 d1 [4 @

% M2 g4 ]. y& N/ @% S+ @& I% R) N

: {* n% M  w4 O; C* w$ S" v    char mesg[133];
! T; c* e5 |! d: O9 p- a
- V9 w  d' g3 D% |

" \  z/ b9 P* G; Q    // Get the work part# e; `0 y5 ?  }; t, z5 J, @: P: H7 p( C
    Session *theSession = Session::GetSession();
  [; c  u3 ]9 `6 @& Y    Part *workPart(theSession->Parts()->Work());' q2 p$ m- [+ ^9 M$ N' \
    Part *displayPart(theSession->Parts()->Display());
2 _5 w0 N6 g* \; H2 n) J& ?: f
9 y8 F' E3 x7 {! ~

3 I% |9 g& P, {4 C' s* c& u7 U. {9 a% H! r! I& ~3 I, k4 A

3 M; k7 x" B" [( i' v5 X    if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;
9 G: S4 Q# |* w; B
) b% W+ L# ^$ d% J. X  {' W

% N  F2 |0 e0 G    /* Get selected WORKPIECE object in ONT */
# }( ~% g, Y) C7 M, \    UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));
( q9 V; J# m8 v2 G, e
; P' |3 Q# F  _; D8 D3 k. X
$ e$ p) q% C* @' w

' |- [, D" v2 L# n4 V+ Z

$ U+ o" {! Y* M4 n) q    if (object_count == 1) {/ z7 @. B- G: `, X# i2 u& V
        UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));
( b5 O0 k2 J6 H5 @- n" n/ d7 ^6 _, U, v* o
9 u) F/ r5 C+ d& K, R4 ~

) _4 N$ \  S7 q, O
. |$ `$ ^. G, c( k* B
        if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {
4 A' @2 w5 u$ W1 K, I/ Q  d2 u6 {" |# r

' d4 s  p7 W0 }! g            tag_t ObjectTag = NULL_TAG;1 J4 t) M8 X& w) o9 x( r' `6 ?) o

6 p9 x2 n0 g& M6 s, V
9 S" U/ E( H9 J8 B& U
            // Get the object from the WORKPIECE tag
2 F& o: A2 E7 Q0 X+ l            CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);
* P7 L1 @  u% J1 c4 n$ ^  Y6 W& Q. Z  V& p

: S5 u, O* R) o: w            CAM::MillGeomBuilder *millGeomBuilder1;
# B" v$ H9 N) V$ l4 W8 Z6 c            millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);. T" ?' q, w! G

, D' R  I- [0 A  o

5 e2 n# \* [8 s" n            // Get geometry set list
2 t/ W9 h: a& S6 {            CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();
# l# Y" s' H1 P1 B3 U7 W  B- S$ i            std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();
& m* ^& F' F+ x/ x- |% U1 W5 s
; J/ Y& F. B+ Z" q7 Q" Q& S

8 }2 v9 ?2 X1 V! G0 d            // get geometry set
/ i# C0 \  R( c7 Y, m+ g1 [) @            std::vector<CAM::GeometrySet*>::iterator iter;
' R! X, z. i9 L+ u9 c( s9 {            for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )8 v( c) |: k% U( j! I
            {) I$ j  h& X0 S4 s
                CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);3 F$ b( f# h4 K4 L( W! |. W: Y8 V
                ScCollector *scCollector = geomSet->ScCollector();            
" a' F! o& m$ L% G                std::vector<SelectionIntentRule*> rules;
" P9 s+ u/ [. y: ^0 I4 T% h, [                scCollector->GetRules(rules);
, m$ r) Z) |, f3 I0 L/ W  D) ~
" d0 ]# F( \1 ^+ o5 N

0 [) [# _- _  o( z+ K1 I/ w                //get selection rule. w0 t; `5 t- Y" Y' D- g6 f6 g6 q. s
                std::vector<SelectionIntentRule*>::iterator ruleIter;
; C7 [5 Y" Q1 a9 q' l8 g. ?                for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )" ~* G7 b) g( X
                {# u4 `, O! O/ l3 N. q
                    SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);
: S& b1 Y, ]1 y. g  P6 y                    NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();
* u' o& t% I# s1 v$ |: h                    //there are different rule types, here just use body, face as sample
* M/ N7 [& s+ J4 q, x                    switch ( ruleType )
3 O9 c4 L9 c! F$ t& l9 K7 M. ?0 A                    {$ K0 I  `8 N  t7 w. d! S- h
                        case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:
5 w% v8 l! N8 x, B% _$ T. x                        {2 Y# i! P. s0 I
                            //get bodies : ^1 K( h3 y/ C8 }( z
                            NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);. C6 [! @: ^* ?, Q9 J; F5 @% U$ J1 w+ w
                            std::vector<Body*> bodies;
: E0 z' K+ o* j7 g4 b( n                            bodyRule->GetData(bodies);
' _8 t! M/ Q9 B' D, F3 N                            std::vector<Body*>::iterator bIter;- S0 M5 u; H  E1 O% k. d
                            int index = 1;& x0 `) s$ n: k, f# |
                            for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )
4 V7 j; y# N' N6 U                            {3 r& ^* s  h' _
                                Body* body = dynamic_cast<Body*>(*bIter);2 @4 N* I. d2 T8 H: o' [
                                ObjectTag = body->GetTag();5 l( S9 i, J# ^( G* P
                                sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag);                                2 T/ j5 j2 ]3 j! m. o# c+ U3 R
                                WRITE(mesg);
0 D) }0 F9 E1 @; k1 K                                body->Highlight();8 H( V$ v! `" p0 ^, u4 q! P7 q5 [  v
                                index++;
8 O; q! {! B$ J" H- C* A3 @                            }+ H/ t0 ?! Y/ U# S( s0 G5 R4 i
                        }' ~# x" |1 O# |  A
                        break;
6 N4 G+ l0 t$ k- a2 M8 Z8 H) f0 O& n

2 g( L1 j$ ]3 c0 t& c                        case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:  h( E- [- T) L2 ~3 \
                        {
2 ^9 f6 x: _* _" ]                            //get faces
* N" K3 [4 `/ A1 @                            NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);8 Q2 O$ u. k$ L( A
                            std::vector<Face*> faces;
2 M/ [' k  x% x* B$ e" }" W                            faceRule->GetData(faces);
- @2 X- d2 B2 N8 N/ `5 `                            std::vector<Face*>::iterator fIter;) L1 r# j# s- Z) r/ }
                            int index = 1;
( T, J4 r7 e7 |: k5 {% }0 B- V' X                            for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )
1 l1 \( t9 |+ N" g4 D                            {
  `2 J6 `7 L! `1 z                                Face* face = dynamic_cast<Face*>(*fIter);
( d( c6 u  }2 s: ], ?                                ObjectTag = face->GetTag();
) J- |. G0 i& m3 B                                sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag);                                
0 J; ]( D* {' S# y; E8 W. w2 x                                WRITE(mesg);
/ c0 j" y2 P7 p$ {. ?+ B                                index++;
: I$ f0 A( R8 L+ e+ Z2 e+ Z! u                            }
. l& |1 U' n: P3 G3 b                        }
2 Z2 F6 ~3 ]/ Q                        break;
0 O. X9 }5 n* M# C0 ^1 Y& R8 X0 c! u0 y' v; P) j! ]

9 L, G7 @( R! Z; ~7 {" S                    default:
7 W. _$ j+ P( e2 b                        break;, x5 c9 d3 M+ {4 H* N9 q. K1 ~
                    }
' y9 s1 ]# {" |9 T& @2 z& A                }
/ l, p4 J7 I* v# M+ l: Q            }
' y5 c: Q( C; C& C7 p3 s- s/ Y$ f4 h) ^0 i1 k
; o+ c3 X% T& W& r0 l) K9 O5 @
% i$ Y. s6 c' t6 M

4 [: |# h3 J! e' C/ `- b3 b/ b: ^$ d4 _( F
- J) {2 {/ @# h; U3 a0 z% g9 ~( s% Z
            millGeomBuilder1->Destroy();! x1 z& u5 z8 l/ S! u
* V5 B- X: I' x2 f. R! {0 M
, l. U6 u# W* x  v; B
        } else {
( I# }2 k3 [. T1 k" u5 z8 ?            WRITE("type is not UF_machining_geometry_grp_type");
% j0 G/ B6 Q6 M: e# i+ g            WRITE(" or UF_mill_geom_featr_subtype");  d% x4 q2 j6 j/ m! _2 P, t  K
        }
/ y/ z' m& W1 @; w+ ~        UF_free(objects);
" f6 |. I  N3 c- }
2 ~( S( B7 |5 s
3 ^  e4 z5 O8 S8 @* W
    } else {) C; [+ w( `; |9 u
        WRITE("The number of selected objects in ONT must be 1.");  E# h2 X7 D7 D! ~( `
    }
0 T7 w* B. v+ J, V$ J# K( l4 h& R) e7 i$ ]1 I1 J
7 X2 r/ c; f. x9 g6 J
}
, N: W+ l' L8 P; L( }  A
9 z8 C$ f* `) J/ k
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了