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

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

[复制链接]

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

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

积分
82170
QQ
发表于 2018-8-23 08:32:50 | 显示全部楼层 |阅读模式

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

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

x
2 W6 Q! R, I/ h% x& ]6 ]! E
NXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值: k( f5 @; l8 H: B% X9 V
- z$ i6 Y, t* [7 Y

, i4 l8 }: p: x+ p. Lstatic void do_it(void)
7 \% O" `3 g# {2 w! e% f{
! I9 r! N1 E& W$ T1 a& {  B( u! b    logical is_initialized;
5 u/ K  Y) X5 Z    int object_count;
. s0 R0 U: }' H3 s    int type;7 U; v* H* `# O
    int subtype;
/ E$ F6 V" r7 f    tag_t *objects;
/ U& f' A3 j: ~4 M( H4 I
* g" ?0 m: T! F5 ?& _$ W1 }
/ ^) \) h2 i% `: _3 H
3 q7 s9 E0 X3 \) c; \, z  L

1 K. [1 H) X. N    char mesg[133];" C& Y5 r6 l) B% }' P
6 ]) u. c7 D' I. J& H5 _
# N9 j: K) F2 p7 j( `+ z0 c
    // Get the work part
- t; a' p# V! M* ?( q( H8 R# F9 j    Session *theSession = Session::GetSession();
- @+ P3 E4 f3 D  i7 V0 Z8 e$ q    Part *workPart(theSession->Parts()->Work());
6 f; i1 R. q  \; c) V    Part *displayPart(theSession->Parts()->Display());# D, u+ e- N8 L5 [7 Z/ T) k

0 i/ }% [% C; L, {% O

; I/ D" ~5 T) `; v! r' N+ C1 `/ |- M4 x) G  U# N
- D; ?2 N  D' r8 e9 }( f/ G7 S" X
    if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;
7 X- h, `* i) S- H! R# @9 y7 c, N; ~( s+ L$ [5 ]
$ W, L; o2 q- h3 b# N4 R6 j: W
    /* Get selected WORKPIECE object in ONT */4 v, L3 B; R/ a5 [7 P# ?
    UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));
: o+ v% _7 N% D" ]: z
' G7 I5 D( X6 r
$ N% v' O6 s, f

0 n! n4 n7 z1 P! m" ^
0 f; M1 r; a* g- P, L: s
    if (object_count == 1) {3 u3 e0 f( J( L; c& t) j  e
        UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));. q7 e( H- z) O
6 G0 f9 ]" w3 U) A1 s
% g. A2 {7 }7 f8 k) c: d

( B! c( T7 q- \; H" D

( `6 o0 f1 G9 X# D) D. T2 q        if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {: ^+ O- v' ^- v; @

& G2 w1 E& x  J, U* ]* r) x4 g
( u9 ^* \1 R! o7 k4 ~
            tag_t ObjectTag = NULL_TAG;
# ^! M# p1 @( K9 E6 h- `& j$ R4 j7 |8 ?+ c0 {3 O

4 J; Q/ i1 p/ I0 W            // Get the object from the WORKPIECE tag
0 W6 T. \% Z5 U3 k% W/ b            CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);+ K+ c4 \. G: B2 T* H
# d$ j$ u7 J' ~4 z+ P( C7 G1 F

; P' W/ \/ d1 j: q: X3 ?9 N3 G: [            CAM::MillGeomBuilder *millGeomBuilder1;0 u3 R& ^" @& N5 f
            millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);+ e' [! U/ \+ d

) y2 B% W& F% Y4 m% U0 X' G) [. F) {
- N$ i3 B6 t7 g/ }* x; l6 g
            // Get geometry set list; z5 l) j7 G2 m% b! Y
            CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();
! e4 F5 `- |+ V2 t            std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();
( c6 u- n! q% `! h. H* ~. o' a5 e, r0 `% i' Q7 ?0 V1 E

  r4 ~( Z8 D8 O' m            // get geometry set
) a! e9 X2 T; p8 v5 ]7 c. Z' g            std::vector<CAM::GeometrySet*>::iterator iter;
8 M* e0 Z' L1 E( C            for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )
/ ]+ Z1 f8 D( [9 E+ ]            {% `6 o5 V& n. I2 Q
                CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);
  f9 Z4 y0 c& U7 N- q, I$ R                ScCollector *scCollector = geomSet->ScCollector();            
, _: ?# j. B- X- t( ]; X                std::vector<SelectionIntentRule*> rules;0 n6 E: ~/ _* Q% |# [" b4 U
                scCollector->GetRules(rules);* A5 r9 W1 w4 x7 `
* D7 J1 L3 ]1 d/ S  ^9 b
2 C( W; X* {1 c' r
                //get selection rule
  I4 B' @! s; Z' b' \                std::vector<SelectionIntentRule*>::iterator ruleIter;
% l( X7 I9 @( Z9 M0 T, k                for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )
1 s7 ?6 \9 J, m8 v6 Y  h2 L1 d                {1 u- y% [! v- F. i3 U+ ~; K
                    SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);
' H/ P7 w6 a' {! z4 V                    NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();
7 v: M. r9 x6 Q' q0 Z4 a  g                    //there are different rule types, here just use body, face as sample& N3 m2 K3 O5 p
                    switch ( ruleType )- p0 Q6 l7 m5 y. J
                    {. r6 M  h/ ?" B* W
                        case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:
# U3 Y) l8 I) x$ Z& X( \                        {2 g& B8 m- n0 ]3 _* z+ A
                            //get bodies
0 U7 Q; W! ^  @% Y8 C6 ~' f                            NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);
; p; J3 i# f7 s9 |" j                            std::vector<Body*> bodies;' t; W, A, Z, U6 Y5 O
                            bodyRule->GetData(bodies);; j1 v! G, Q- V4 f+ x0 t
                            std::vector<Body*>::iterator bIter;
4 v8 |/ l8 K2 C+ @                            int index = 1;* W) E) ?* q/ Y% c
                            for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )
5 u) w6 w. U6 }: s$ j                            {0 T- x) i/ ~% d' ~& D
                                Body* body = dynamic_cast<Body*>(*bIter);$ o- ?- I" r# ^5 I
                                ObjectTag = body->GetTag();- I5 E8 k9 l  L- P
                                sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag);                                ; ]1 u% n9 g7 X1 Y
                                WRITE(mesg);
# a+ w' t+ t* c4 o                                body->Highlight();
$ |9 m: j$ G* w  L) N. x5 t8 A" X                                index++;
8 Q' r' F. k$ {  O) S                            }& ?# S; A5 J6 Q
                        }
! [0 l5 `7 q8 ^; A* w* Z' v                        break;! R& F. z5 `% o9 i9 D8 @
) n( K* s2 q  x% a  h& V  i

+ U4 f0 a6 ]' t8 T8 K6 o                        case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:( _, s! e+ i7 x; ~: R8 ~
                        {
$ M" H0 v* I6 Z& `                            //get faces 6 O. i8 n5 w. Z' R5 {
                            NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);6 }" D$ f) M) l. n# j
                            std::vector<Face*> faces;
8 [* l$ O* {/ \+ s% L+ u, |8 S                            faceRule->GetData(faces);7 \( s( S' x0 p% C( B
                            std::vector<Face*>::iterator fIter;
7 z% A" O  M9 a! S                            int index = 1;
5 C4 w) t3 f1 y  b% `                            for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )
; g7 S! f* ^1 O( \                            {
1 k/ g) }2 A# v8 z3 y5 L                                Face* face = dynamic_cast<Face*>(*fIter);+ T- r+ K& y5 T+ _0 }* I; Z
                                ObjectTag = face->GetTag();8 p3 _5 R* \. n4 s
                                sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag);                                3 k8 |' b% F2 C% \! D- |; f
                                WRITE(mesg);
( O4 o5 h! c0 H, }& u. |                                index++;
8 }1 i& s( i- u; n$ G* z  C+ r                            }
+ C; n1 y) K0 f1 a/ y1 Q                        }
  D8 U5 b8 L' X! l; P4 K6 m                        break;
6 t) ^5 Z' c: Y/ N; Q/ V$ f3 v7 r$ n& P* a4 v7 Y

/ M  l' C; A/ C* G                    default:4 s. n3 {5 d- M' A+ \1 S- r1 B
                        break;5 m" c0 M9 w9 `1 V, j! V
                    }
3 N( H) j/ b" R% D2 q                }
4 Y7 v/ l9 N2 K5 u4 v            }# R; y% R& k: X- U: B

6 Y! J7 \0 r2 P' H
$ ?( ~: [/ G1 }( s# X" a+ N. v
. o! t9 y% v; }( R( B

, a- B9 `; o5 p8 g# j* w" m7 n( ~; P: G

5 s- D+ G2 p% z4 \            millGeomBuilder1->Destroy();
4 w: `% t* ?6 V9 m
# R- N+ k1 e* o0 s- w( y

( {; y- G3 K, j        } else {
; _' _6 ^, o/ x# U5 v            WRITE("type is not UF_machining_geometry_grp_type");! u, a# O# V* r4 p" r6 W3 s
            WRITE(" or UF_mill_geom_featr_subtype");
/ a/ `2 d; w5 D% Y8 H        }3 n1 t8 `  v; h$ _
        UF_free(objects);
6 I* R8 t7 i0 I% V2 U3 S/ Z, _1 x, k2 G* {' A, l
. L0 g( D2 Y3 \1 k6 f
    } else {; u6 S/ z1 u* v& U" y8 U% O
        WRITE("The number of selected objects in ONT must be 1.");
( A& o4 g$ A7 `, M! N! |# u    }
9 i, w) @+ l3 p8 ^( }; V" O* x$ [+ `8 x( Q& w# Y. G6 V* T! l

- v& k! N: v* I% Q- g}3 r8 j, M& u! Z1 n
) I% ?- X1 U9 X  R& M9 u) A
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了