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

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

[复制链接]

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

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

admin 楼主

2018-8-23 08:32:50

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

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

x

2 @$ f% X$ c- [5 m3 ]NXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值
# `% j- ]: l( w5 e6 ~
# G/ W8 a0 }7 Z' ?! t# N, v' N& ?* S7 E( Q
static void do_it(void)% n# ?. N0 P/ B/ K" `
{* E. d+ R# L* }1 g' m8 ~' n
    logical is_initialized;8 i/ ^% p8 m' w& s
    int object_count;
4 ~, |: A- B" G/ o( f1 r, R; m    int type;
( u, {" [7 ]- X- a2 W    int subtype;
& q  N, a6 K% ~  d% E& U5 J7 N    tag_t *objects;* N. X+ p  B* k3 P, z# v
9 ^; z3 B! |) ?/ f, {( D( J' U

0 P5 H9 c+ G/ U3 i8 j/ ~
# M" g7 T9 {) [! J" C, ~
9 t: U0 p" k" M5 x2 k! _
    char mesg[133];( H4 V, C, i. N$ ?9 ?$ {; z+ {  Q" [
4 G% q: E. [: }. u

7 n3 e7 q5 O: t/ r6 }4 r. C9 O$ S    // Get the work part5 ~9 p; Z/ l/ I* c5 i
    Session *theSession = Session::GetSession();7 t" I: C, E; C6 o0 _* z
    Part *workPart(theSession->Parts()->Work());; ~; @# Q+ I8 X$ l4 e0 T% Q
    Part *displayPart(theSession->Parts()->Display());  R0 g1 L- C* {" e

; |$ J' `( K5 h- ]+ P; e
4 {2 ~* i% p6 g2 @8 V& E( M
$ A' d( S: W" l4 q" h+ t
) y1 Q3 A" ~8 r' k4 p% F/ C
    if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;
, |' G" l# i# S" i0 x8 U; U9 ~1 Y7 {) t$ W7 H' g4 v
0 N8 y( }0 W! m7 A
    /* Get selected WORKPIECE object in ONT */( c2 m! ^" o$ y6 G' Y6 ]& K  n9 m
    UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));3 K) R) U1 Q* L; U. c

; D. y8 f! D. ?+ l+ ^8 \8 W1 t

# J: J# D+ x2 _" m: d" Q
( M- L7 g" K* c, _1 H. a4 [

' m2 o% N% F2 E    if (object_count == 1) {
2 J& z% t1 b5 B! E        UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));
( v) j; H& K8 ?$ c2 Q9 z6 ?# v" Z* C2 K1 K. N8 \( V$ h

! T. L2 _2 G. A  {  B4 X; \' X1 j6 E; h0 `# ?% G4 g5 E
5 p4 k& b/ u7 H' a, g: \" {
        if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {: f7 m" f. _% v2 k$ C( u2 n3 A

4 t# v$ |. P- |' T" _7 t2 k
7 r1 V4 u$ |& x, D5 J# t/ C+ C
            tag_t ObjectTag = NULL_TAG;3 V& E& v, _! K  N* p

  X$ u2 d, X) _0 Z5 X$ V

* q$ x' ~: Y5 D7 A4 u2 |            // Get the object from the WORKPIECE tag. S5 z9 t; S- K% V
            CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);: O0 G% U$ L4 {4 X6 ^. Q* ]% p

  {& W7 {) U7 R; r, z

  L& G0 E# u7 V7 w6 F) f9 q+ y            CAM::MillGeomBuilder *millGeomBuilder1;
$ O1 U8 l# J( o+ i* ~            millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);
; l' Y. s/ c% a6 x; z* o! g" p, B: w: S
& _+ v& J  c# f: z, n- P
            // Get geometry set list7 n+ N/ Q8 L3 j( q/ b; X# r# J* y2 w6 {
            CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();5 O( n) i2 D2 C0 h2 F
            std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();
- h$ B/ t8 W# [  {! K- u: O; ?. E: ^( M% {* `

  I' a' j2 ?. Q8 b3 [2 a& s+ ]            // get geometry set
+ T5 i- S( s( [) n% k, S            std::vector<CAM::GeometrySet*>::iterator iter;. o( X& q0 z+ ]8 C
            for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )
+ `# ~% ]3 I. u8 q: _5 i            {
# S8 @& v. V2 s/ K4 i$ k! Q0 U                CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);; q+ ~8 a) l+ a4 }: }3 J( k
                ScCollector *scCollector = geomSet->ScCollector();            ' j# f, ~( d% f. v- O: H$ |2 i
                std::vector<SelectionIntentRule*> rules;
& `1 I' v/ t7 T                scCollector->GetRules(rules);
7 n; E. Q0 w' g; i5 a
: f) ]. \2 [) N  i9 e

* i2 J  r# a( Q: G: M                //get selection rule
. V& ^9 X" l3 c6 t                std::vector<SelectionIntentRule*>::iterator ruleIter;
- l6 V4 q  l* O1 |                for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )
0 x/ L& O2 P; ^5 A8 j* \$ ~                {/ D, U- K0 G/ L7 ]' c/ w
                    SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);
2 M7 [, p: M. ^8 x9 t                    NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();
. v9 i( O% w8 O& |) f% {                    //there are different rule types, here just use body, face as sample; S, ]# P, t) u, j4 a
                    switch ( ruleType )
7 d; l( z& [' ~& t6 m" j$ d                    {; Q0 E5 o- k2 ]5 ^& P6 ]
                        case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:% k5 h- Z( A+ a5 Y1 @3 a. V
                        {
3 X: @1 l7 ?& @% P  T; u                            //get bodies
) d( @: C& A- M: X" N% ]1 P+ E                            NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);* X5 N: H. j$ a$ _4 T
                            std::vector<Body*> bodies;
5 x, [& L- H% o# D) Y                            bodyRule->GetData(bodies);
4 z6 B, w+ w7 }( X- `8 [                            std::vector<Body*>::iterator bIter;
- ~" G( t+ P. S5 I                            int index = 1;$ x0 r" u9 ]! ]) P6 M
                            for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )
. i4 s6 q( z; S! v                            {9 B# F/ Z- k6 U' f2 n! E& p
                                Body* body = dynamic_cast<Body*>(*bIter);
3 V- R+ D5 }/ h, ]7 o                                ObjectTag = body->GetTag();" }! W; t+ L$ t+ z# Y8 p
                                sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag);                                ; p1 U% R8 w  E: Z
                                WRITE(mesg);
) {# E. ?& M& b+ U; `+ S                                body->Highlight();
2 `9 M+ o( Y# A# {9 q; E7 j4 Y, F                                index++;
1 b8 H3 U7 m9 F8 Y# s4 k: e( a                            }2 X8 Y; q, N  J  H( J/ A! C8 y- W
                        }
& [: ?( x& ^  P1 {) p& ?0 e9 W                        break;
, P! M7 H. B! f( X8 B+ _$ [& c2 B' C+ q" L" E" L7 D$ P% `
5 E+ ^: |% F; U/ O  B8 n& m
                        case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:+ q4 i( N' E" @$ R6 z. |
                        {
$ {) U  Y" l; h2 K                            //get faces 9 W7 K* t5 B. T( c' ^# r
                            NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);
1 m* W$ v: W- r1 F, b- J7 R' r                            std::vector<Face*> faces;6 U: k' O% n( M
                            faceRule->GetData(faces);
$ L! r2 k" a( f8 k3 T0 R' p# f. s                            std::vector<Face*>::iterator fIter;7 \3 \- @8 p6 r- F+ I( F1 {
                            int index = 1;
( z- i" Y/ \4 D) _4 o& Q3 }                            for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )
  _/ `) i3 L* n# w" J8 i0 o- i+ V                            {
' c' l0 g7 H, \& Y$ f- l, j                                Face* face = dynamic_cast<Face*>(*fIter);2 q. _* h  D2 G+ R  h5 g, D5 w9 z
                                ObjectTag = face->GetTag();8 @$ C/ e/ s. E) @' A7 W& Q
                                sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag);                                
8 K3 c" T" y/ {5 c8 B$ f                                WRITE(mesg);1 t( f/ o% i1 n3 g- w
                                index++;
5 S$ }) U7 N4 S                            }
: Z. B1 s7 z! |+ B, p9 S                        }% q- X! t$ g8 l. w& A) b
                        break;
1 U4 ~4 c/ ?# O+ D6 s( T
* [. z' r4 r5 C9 }4 p/ d% s5 `
/ U5 C* B9 k+ d$ R7 w
                    default:+ G( ?" m! M- [3 l
                        break;- ?' R  H) l! M$ ]) F0 }
                    }
& f& f2 B3 N! }4 H& q" }                }# L# x8 ]5 \9 u7 L( {) Y
            }) d/ I- z9 q) X+ v

& p' l- o8 Y3 ?) C+ g$ m3 o
6 T' K1 [) c8 m$ V1 @

- {5 |- x* K) R, j! D
# y; }8 N# S* N& d

: o1 o' w& p" f

# p  t. @2 ]$ v- z* `* _4 M) ?& @1 P            millGeomBuilder1->Destroy();
( a9 c/ X+ q$ U+ j3 w. V
" ^  J! o. S. J/ |7 {
- [0 I+ h$ p. G- n: I
        } else {6 U8 i9 V4 t1 [, a7 |% V+ E" g
            WRITE("type is not UF_machining_geometry_grp_type");
+ ^* h! X( ?  Z) {            WRITE(" or UF_mill_geom_featr_subtype");
7 p  Y* ~3 X8 }  H        }
. E: ]5 n% X5 i0 o        UF_free(objects);6 M+ k% S' S$ |/ b) i

( a* @: k# O! B* W  O  ~, D
& a# q% U$ i/ U, ^3 c
    } else {
/ Y( }/ Q( J8 Y1 T* B        WRITE("The number of selected objects in ONT must be 1.");
! W6 ]% }+ t' W% f    }% B' x) a' L8 N7 \" K/ p+ L- H5 j

. q' G# e: n# |$ S6 F) J) W+ c

* m0 v# y. X9 I+ I  `}; s' w5 Z) R, ?0 A
% i! n; ^, h- `+ |; T: k" h6 h; ?
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了