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

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

[复制链接]

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

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

admin 楼主

2018-8-23 08:32:50

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

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

x

$ \6 g5 c6 n3 T/ `9 f: |$ e  MNXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值: H$ ]) W8 p. G" x

3 y- n! P0 `) {: ?( W+ F! w
. D* w+ c3 t+ H7 Estatic void do_it(void)( a* K, C" D* e% \0 h3 g" d& [
{
# \$ G: K- a. g9 d, C) F+ s" V1 W5 H1 u, p    logical is_initialized;& ?: ^+ l6 C& b
    int object_count;. }8 F$ t2 k+ O: n! Z" }& x
    int type;- W# E- C3 ~+ Q! T. S5 P* S+ Q
    int subtype;$ o$ ~' c$ ^% L/ s* o
    tag_t *objects;- B) I" {( F5 w. l: H8 A
4 ?% O& i/ _- d* G) T1 E
% X- F$ S; l% i8 ]7 T0 Q
1 B9 O9 J% B. l1 r6 p) ]8 l+ t! i" f
# I: M, ]( C# m0 L
    char mesg[133];
& o* o1 ^0 U" q9 \1 T* g  h% S8 l- l0 s# G+ w& q. {- X! \0 X

9 U* ]# t* H% b; q5 D! M& E, V6 T    // Get the work part+ x, J4 A4 o/ }3 r
    Session *theSession = Session::GetSession();
+ L& e1 u0 ?5 y6 ~; z+ ^    Part *workPart(theSession->Parts()->Work());0 M% \; h3 d/ M$ _# L8 u: o* d$ O
    Part *displayPart(theSession->Parts()->Display());' Q7 Z) T1 n2 u' A
4 Y' l& P- e% [# _6 q
" C1 ~# M( B3 N8 M4 h. v
! k2 i/ l+ e9 f8 o3 h% P
, A( a' p- X) ~) F8 M" G& m2 k
    if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;- G/ v1 A: f# h2 l2 I2 _

0 W" d! ?6 H3 G; r0 B
3 u3 R' b# `( ]0 X2 V8 H3 V
    /* Get selected WORKPIECE object in ONT */
& O( l7 P% x2 u) @9 P' Z: g    UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));
* U  f. |+ s2 q7 [# a+ H' K
; n8 n: o( ~: w/ F
& m: ^5 Y9 ]- ]9 K3 i/ _; v1 w

/ L, a' ~: }( N6 N+ L1 X- k* [
' e6 s# ~- ^2 I9 M% s; o
    if (object_count == 1) {7 {3 l8 ~# K4 U2 g4 i
        UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));
* i: I$ r: A3 ]
/ j/ r% D! ?; u) T$ ?' f

( B' w/ X/ w& e+ }* @
0 t, v( r; i' f9 P7 i; U  Q/ w& N) |

) g7 U" D( e. |2 i& @8 S7 N7 s3 G        if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {
" N3 Y( l. ~% p- X" k. M- ~* I) o1 N) Y0 t! g2 p

/ v. y+ e# B9 L            tag_t ObjectTag = NULL_TAG;- s9 h# w& Y& Q6 ?

, `! {5 s- N' g8 U$ B' s
/ A* u: c6 q8 U  L9 y
            // Get the object from the WORKPIECE tag
# `9 Y- R0 ?. l2 t1 w. S! |            CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);: a+ g8 B7 T( \* ~" W

5 E% s4 s# \! _5 h
, ^4 m( i  N; i: R+ o
            CAM::MillGeomBuilder *millGeomBuilder1;
: u5 e  _1 W6 Z" y, ]2 u$ n            millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);
% O$ n+ n- n7 L6 P3 B0 A
7 |& V) n+ J" y' }8 E

8 c# F5 u& A# ^/ i            // Get geometry set list
  N0 V7 A2 l' n, P/ v" `3 w            CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();- B& t2 s. K( D2 ?  g
            std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();) U2 K7 ^# S: a  l
& l! P2 H/ m1 L8 {# }
3 g* P) L  W$ \
            // get geometry set
4 J! L; V' v4 ?$ x1 i2 R/ O! |            std::vector<CAM::GeometrySet*>::iterator iter;
* e2 D( f: y- ]% c  {            for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )
5 J- n0 V) O) \5 m! v            {6 p6 A' _! ^3 [/ ]7 S+ x+ ^) p# _9 `
                CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);5 g* o* o+ M) j8 Z& v) |0 }7 c
                ScCollector *scCollector = geomSet->ScCollector();            
5 |* y7 T& H4 [                std::vector<SelectionIntentRule*> rules;1 H- a3 Z, K; ~
                scCollector->GetRules(rules);
# b0 V: M% t1 O/ r+ y% E
" G! x; G) t: [2 S1 o
9 Q- E. g( `( e; s2 N0 S5 Q( c
                //get selection rule) V% f& n5 s' x/ [/ _* N
                std::vector<SelectionIntentRule*>::iterator ruleIter;/ d0 h" J* K8 {1 B& ?9 j: y
                for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )  m3 P: v  {3 X2 _
                {
7 U9 P$ m1 w# s. S                    SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);
* @; M3 x# ?' I3 J& H0 z% O                    NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();
# Z3 a; M7 }: F$ g8 ]                    //there are different rule types, here just use body, face as sample
( F" c  y) m% y8 E                    switch ( ruleType )& b  i1 p$ [8 o. Q1 O: T2 r3 X0 y
                    {
  L) u+ g4 M2 h                        case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:
+ U; H3 d0 G$ a: i- p! d                        {7 T! h7 B' o6 R
                            //get bodies   k$ U- p6 e/ D
                            NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);; n' D6 F4 e9 R+ B& b
                            std::vector<Body*> bodies;
3 n2 e7 W# ~( n. c. [                            bodyRule->GetData(bodies);3 }8 N4 T0 N, N. g2 L" r9 d; J
                            std::vector<Body*>::iterator bIter;9 k/ i* ]1 g% Y4 {2 U4 n6 K
                            int index = 1;
( N' T% w& X/ C                            for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )
9 b9 w  U' y" E4 N8 t$ ~7 E/ E                            {) v5 I4 l& L- r0 K
                                Body* body = dynamic_cast<Body*>(*bIter);
( [7 G  Z7 r1 h( i! k                                ObjectTag = body->GetTag();
; y1 n+ Q+ o$ j5 d0 ^- ^' k5 _# \                                sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag);                                " _1 T/ w( F8 }. E4 v3 ~
                                WRITE(mesg);. ^5 W# L% P; ?, }- K# G
                                body->Highlight();
' z5 b9 N5 F! f9 `  C4 K                                index++;
0 h' d. ]2 Z  C4 o' B  g! @                            }
6 k: b" v( x$ R. W2 c                        }3 G3 e# D+ ~% A7 C7 q  g! m0 \
                        break;
4 B' L8 u! D. f. w* s
$ {1 D3 M5 c) E9 s
- [6 z" {! l+ A$ u' m
                        case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:
: T7 _$ I  `" t0 \/ l3 M- r) ]                        {
8 n9 P# ~$ Z/ d4 B8 `) Y% R                            //get faces 2 G+ e, D: V# D8 k0 m! N" m8 _
                            NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);+ l  Q5 s- k! j( [
                            std::vector<Face*> faces;
% p3 `, T% e3 ?1 Y- ~. S' @                            faceRule->GetData(faces);
) z& ]7 u8 q" ~                            std::vector<Face*>::iterator fIter;+ q# E" i8 u! ?$ D
                            int index = 1;: c) L4 ^5 S) N' x/ [, `& b4 o4 Y
                            for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )
" i% c2 {  }. E6 I- V' J6 v" x                            {, X5 E8 Z+ S' I0 F8 x( L0 a9 Q
                                Face* face = dynamic_cast<Face*>(*fIter);/ ]4 J1 Y( h, l- n: X0 O
                                ObjectTag = face->GetTag();$ a( {" V  J- E
                                sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag);                                
9 ^4 T8 f7 E7 y  p% Z4 A" t                                WRITE(mesg);7 V! }% S& H) `# U  N
                                index++;
+ ], m  n& @8 m# l% I# y1 p                            }
/ q3 t4 H+ Q1 j6 s1 j6 t  @1 i                        }
9 M. v0 K, U1 E% R                        break;/ x' ?+ `) D( y5 D) ^
7 d  l0 ?+ Z. F4 \% M* j
% i+ G$ _) I% e8 e1 G* y
                    default:
0 R& ]' }8 @7 I! t3 [                        break;
; S" p1 v9 Z- R2 \& c! {! u                    }
! O) V3 r3 ?: R  [                }
( Z0 f1 \8 V) z" }' [6 J            }
1 h' u( C0 C8 Q4 T! O* _$ H  U% H2 l( z+ `+ h+ O& s% l$ V, C

7 U$ }6 p" ~, \0 ^" K, d- y
, v7 d1 C1 r6 y

# S8 I  f5 l  Y. V, W  U  E8 w/ a) r3 `" t# c
3 d0 K! i/ N8 |
            millGeomBuilder1->Destroy();: ?" {/ E5 L' Q2 X" k/ S' ~

& g1 O$ B- I& x4 W, S, ~
8 T8 U% ~4 R+ c6 h* S& s4 F
        } else {
' E' d. p! {8 S+ @/ O5 b4 h            WRITE("type is not UF_machining_geometry_grp_type");
4 V2 B1 a, J# O( A% O            WRITE(" or UF_mill_geom_featr_subtype");
9 f8 p3 g0 P8 ~5 u/ i' K* T        }) {8 N1 q% @' c5 m/ Q* P
        UF_free(objects);: |  o) Q7 ?& A; _. E+ l
0 D1 m+ U1 |6 F
1 A3 X! k+ C+ C" M& L
    } else {
2 I+ e: t' r# S7 s, _        WRITE("The number of selected objects in ONT must be 1.");
5 v. t1 \2 {! I4 Y6 a0 h: r    }$ I: Z$ q% [( ?* @
( T, `1 u/ D% j5 f) l/ {
  Z$ l, H8 Z+ a- k. U' N
}
! L- q. K9 M) I7 r0 m
1 p  M+ i$ [0 A0 N+ s
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了