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

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

[复制链接]

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

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

admin 楼主

2018-8-23 08:32:50

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

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

x

: }" Z7 h8 d  Y  B5 x6 ]  i7 M; XNXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值% }5 F5 V8 E% {5 ]

& {! ?& b  V5 z) D$ J& g% @( K' V! Z9 }' V
static void do_it(void)
! V9 p( p2 T$ t) b{
4 r0 d: k2 o! R1 \    logical is_initialized;( W7 A; j" b) A) }: k) ]( @
    int object_count;
6 @7 Q- |# v# E5 `1 l* U; T    int type;
: c. [! ~: c6 N8 e    int subtype;; S2 P, o$ k& _5 T4 o% {' x
    tag_t *objects;9 |" E, h3 K3 \* k1 \

4 p4 u$ f, @: w' F1 l

* P# |+ g8 k$ I5 {( @  J& ], P/ N5 R6 _2 u. E. o

7 m% ]# X8 ~7 _6 Y    char mesg[133];
: Z7 ^5 A' Z( h" r% i. M. }' j7 R) Y5 w* D4 w5 ~* o- g5 x
, V8 Z0 j1 |! v) K) }" k
    // Get the work part
5 A0 Y2 E# P* z  ]8 T    Session *theSession = Session::GetSession();
0 V9 v  Y& e) v    Part *workPart(theSession->Parts()->Work());: t# }( E4 w3 H2 ~8 ?) @
    Part *displayPart(theSession->Parts()->Display());
- y& a. j7 ?+ u; I5 x! V
: ?, i$ K2 G* a
+ e) X' k$ o: R) P4 _, V

% A' w. _3 S# T$ K
) a& M: q' o# F% c9 r
    if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;
8 |! P9 K: @+ @
% T' @# \$ Y9 k. ~
9 a' }1 A0 w: D1 L
    /* Get selected WORKPIECE object in ONT */5 k5 D( ^: Q; r" q% D
    UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));
6 t1 m4 p4 N. P7 r" l  u& Z# T
; V; Y4 {0 M; C7 N( S* ^+ m
8 q) ?4 ~# M! C
3 ]; a2 m- G2 L% a) R3 ?
! s" [: z( y: ]
    if (object_count == 1) {! a  n/ N! E7 `9 V$ b/ C9 H
        UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));' P% t. s9 i$ E& k: ?$ _" k5 s) [
. x# B9 M) {$ X5 K% z8 L

+ G6 g; q3 F' q* {9 X  n$ ~7 o  p' d( t/ F. t& F
6 O4 R  d1 n# a$ Y3 a+ a
        if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {
- b( \& q9 G) d) K1 D; F
8 @! _( j$ S* a7 L9 n

- v0 B4 a! a: p% M            tag_t ObjectTag = NULL_TAG;
. ?4 p* l. |9 ]6 d8 f
9 s2 v% i. s2 }% v! h
2 W4 O  v2 s9 O6 g3 M5 X
            // Get the object from the WORKPIECE tag4 G# V4 e0 P6 }: Z8 e- [4 H: q
            CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);; m* w; R: N( q

+ H% s8 S0 g8 a0 o* H
6 S+ H, ]; B, z0 i6 k2 U) O4 _
            CAM::MillGeomBuilder *millGeomBuilder1;" j) J5 X6 |4 s
            millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);# v+ p  @& u0 ~8 m  ]( r5 q

6 B2 [# T# N$ l) p6 J

) Q/ B3 Z0 `) c. |( n) ?; p; M1 ?            // Get geometry set list- j8 C8 }; K" i5 P9 ~9 M; {
            CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();
+ @- p4 G' W/ U" F8 \0 R5 V9 Q) g            std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();
7 m, r: X7 [% d) W# z2 b* W+ O% |
9 W7 E% q  p6 G
* Y+ Q7 j$ a. b
            // get geometry set
( N* w2 A' \: k  ?2 X, T            std::vector<CAM::GeometrySet*>::iterator iter;
: ~7 c1 D. @4 v; D* @            for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )) ^8 U2 M3 e& q$ x* O/ H# M
            {
- m  p8 }! {, Z7 [) ~2 M8 J3 M2 z                CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);
! s, u4 @! B) J5 R8 x5 t) `! j* W                ScCollector *scCollector = geomSet->ScCollector();            
: m  H  C+ M4 w" Y0 P. f9 u                std::vector<SelectionIntentRule*> rules;
3 W( S0 p; q) |7 T                scCollector->GetRules(rules);
" x( q/ r' x0 @+ l" U1 U, V
$ n3 }; j) x% P; Z1 A7 @8 ^

6 H( K5 z# F4 t  [2 w( x* Z                //get selection rule
) z  C/ J3 @1 s                std::vector<SelectionIntentRule*>::iterator ruleIter;
( j5 E7 z. j3 v% H* p                for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )3 H% Z5 _- v$ L' @, l& V
                {
: I( c2 h( {" ~6 e; j+ @  g                    SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);: m+ x; {! L9 q- T. h
                    NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();
  T1 _! [5 {/ V' \, S4 I$ F                    //there are different rule types, here just use body, face as sample
# t) K4 _! y# a: [6 D0 f                    switch ( ruleType )
8 a7 C7 E) `) {! ^+ c8 r                    {
* B# j$ e( ]: b& V. N" j' U) g                        case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:! L4 u, r* F0 o& S/ c  ]
                        {% n1 {9 a" U0 s' I0 p
                            //get bodies 1 ~- W" `0 k# Z" f( ~! {- G
                            NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);
7 C' m5 W; G, ~5 P, T                            std::vector<Body*> bodies;- R4 K# Z  H2 t( A4 f; l; j
                            bodyRule->GetData(bodies);; I; I- Y+ C- U  ]5 G
                            std::vector<Body*>::iterator bIter;& `$ r9 s! A* o* k# ~6 S
                            int index = 1;
: ^) a8 c5 _4 C# U* K5 o                            for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )
6 Y4 U7 y1 d* X- i2 o& z" J                            {( U: d5 B5 J  G: f0 b3 P
                                Body* body = dynamic_cast<Body*>(*bIter);( V3 _* {- K, h2 f! X3 s
                                ObjectTag = body->GetTag();& t  J0 b/ ]: Y: L1 v+ N
                                sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag);                                
7 ?4 @* C) c! t' L8 P( q" T+ T                                WRITE(mesg);
- D4 @5 F  s& M" x$ }                                body->Highlight();
' Q: b$ N: X9 p* y                                index++;! W4 o; N% u3 a' @, B3 C
                            }* |) O1 z) v: A
                        }
0 q- f% Y, F) E) `6 k                        break;& u6 W; D& u, C

% J. R0 j6 O; ~4 e, x- _2 m" h/ R
9 ~! Y; ~' Z3 N) R0 _8 v* W
                        case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:
0 }5 C! p9 r6 [4 T                        {7 z, B4 r8 ~* i/ n" W( ~/ W
                            //get faces
, G; Z! G. X1 r2 k7 }4 F* x                            NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);
" n6 J; N- [; i' L                            std::vector<Face*> faces;
$ o9 P" T1 @9 g# @% G: y9 ]8 c3 c* ]% @                            faceRule->GetData(faces);4 C( k2 `) ^: P0 n* u+ C
                            std::vector<Face*>::iterator fIter;
  w( b1 |! m' p, n  x8 y5 j: q                            int index = 1;
- [5 v0 K, F5 G. Y, g0 c* {% `4 T                            for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )
: s, `  n0 M* o* c/ K& {8 _                            {7 r- _) [& c: M' ^. ]; I
                                Face* face = dynamic_cast<Face*>(*fIter);" w  H1 f; G  f$ l  a, G
                                ObjectTag = face->GetTag();  n8 q/ e9 F+ V, C% q
                                sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag);                                / Y- }: H: o  u5 z
                                WRITE(mesg);6 x8 g6 [$ W1 O( \+ h
                                index++;- K, G) Q2 B6 @* H2 _7 @
                            }4 t4 j- P; c& ]4 K2 |) ]% t
                        }3 j6 f& Z  D1 p7 |" c
                        break;. U1 {; Z: V2 \- y

: ~) \& T7 \  n' n* G7 Y
6 A$ }6 C: g# n/ {4 j
                    default:
% F+ [' U+ S% L2 }- \" i) y                        break;
9 x, Q# Z8 H# [                    }! f# i8 G: M& k$ A4 \: g
                }
. k6 E" Z6 c3 c0 [            }
0 {0 P8 K1 |1 M/ Z  ?5 l' J9 Q
1 @3 `7 }2 t; X2 k2 T* H% e
: G) z2 X; X; e2 @# E* f0 J/ q
  t" _# M2 _1 s- t& B0 b. D
+ O5 p8 _* ]$ m4 y* M6 c

0 p2 p0 D& q. t

6 m8 G6 R5 a; ~1 {7 q( K) u. O4 N            millGeomBuilder1->Destroy();' f6 R$ {. L2 V

! \  k" h( m* t1 @

+ z3 s3 y9 F7 _1 f8 U1 g        } else {
7 R7 `" G; h0 l! F. _            WRITE("type is not UF_machining_geometry_grp_type");4 p/ b1 n4 @( Y, p' l& L
            WRITE(" or UF_mill_geom_featr_subtype");
$ Y4 D0 y8 e. F2 |& H/ \& L; D+ C! x7 Z        }
2 s9 k+ k$ S; V        UF_free(objects);- c+ K8 P, B3 }+ W, g$ s

; h/ o: ^) @/ R7 r/ I
1 A/ t& y9 v3 M  m' R, X
    } else {
1 _& K- H. l2 S        WRITE("The number of selected objects in ONT must be 1.");
4 p0 d: [+ ^# J/ l% W# K# L    }6 X. J0 M7 @2 C  b6 C- U
) N. z% h& F5 J
. q5 A" p6 _' _( }* u
}  V9 b$ _$ j; v6 l0 a

5 |$ u4 B$ v5 O" o$ X$ j1 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二次开发专题模块培训报名开始啦

    我知道了