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

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

[复制链接]

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

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

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

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

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

x

, V5 V' S, z; U+ ]$ INXOpen C++ CAM二次开发:获取workpiece的所有几何Tag值& T* G5 {6 ?% j, _* M; s

- f$ C# |; F2 g6 v. H  ^$ d1 V& T; y
static void do_it(void)
' b* ]' a4 U; b" H" k: b+ w$ I! ~{
; e5 |, G0 G8 n: J1 x/ c+ K    logical is_initialized;
% T# S) W8 D, N) |    int object_count;# b5 C: G8 r4 d3 p9 j/ d' n
    int type;
9 D) ]! @( z1 X: q4 n+ C: a    int subtype;
8 S7 ^% U1 C* t& N2 A0 h2 X    tag_t *objects;
0 x8 B. t; V$ u( C  U5 g
- R- H8 U* [; O1 f9 W# [
( r- J6 K' {% i5 U& o

  Z  x. M. w5 J0 i  v

/ n3 v) ]; J2 n" `7 t' Q    char mesg[133];
% }+ [0 y& M5 p1 j" }* w# N' w. e: {) W4 ~# I! Z) l# Q& U  x6 f

) x0 u, w6 Y7 g( A' c3 s    // Get the work part
- r( v1 |5 v# t% ?5 H, u. z2 d/ j    Session *theSession = Session::GetSession();0 z0 o4 Y/ b% }' \5 K  ?2 z
    Part *workPart(theSession->Parts()->Work());
* ?/ ^% R5 [+ U6 ]; [; h& }7 T    Part *displayPart(theSession->Parts()->Display());$ q+ A9 w/ K) v- G9 b, E
/ [0 q8 m/ M) L# X

# Z0 l( F. N. ]
' F0 z$ K7 c& |, x+ x. D: l9 t
/ {, S" S2 l+ L4 c# Y7 J
    if (UF_CALL(UF_CAM_is_session_initialized(&is_initialized)) || (is_initialized == FALSE)) return;$ m% w6 G# t3 T, L# S

, U9 E8 h( C+ H, o! `
- o) V0 C' W7 }- t8 r" \6 c; V4 R: C( U5 W
    /* Get selected WORKPIECE object in ONT */
! N" D& Q  C' C. X) f9 k9 G4 @8 k" a* ~6 [    UF_CALL(UF_UI_ONT_ask_selected_nodes( &object_count, &objects ));2 S1 O7 n% `! E
  ?# A0 s8 ^0 T% I% }
: ^% T- q/ G) X" s& x
  z$ O9 W9 X6 W% z; c
. Y9 |  O' {* R8 ]& c
    if (object_count == 1) {
6 y) e! G& D" ^2 m/ x        UF_CALL(UF_OBJ_ask_type_and_subtype (objects[0],&type,&subtype));0 j/ y5 c+ r7 P9 K. Z; `

5 C5 K9 q7 `3 Z+ Q  o( N; O! v% r
, {* f  L0 g7 j9 B5 y( @& ?
) J5 B8 p  G; D7 G: Q: K
5 K; Q4 c4 n0 d
        if ((type == UF_machining_geometry_grp_type) && (subtype == UF_mill_geom_featr_subtype) ) {
* |& `5 X7 T. f. T4 [8 n
( z" s# z7 Q& S- B: x  D. g& v5 B

7 }; }: C0 b/ L) Z+ c3 w7 S            tag_t ObjectTag = NULL_TAG;' b: v; k' I2 D2 ^& G5 d

0 g& m2 e8 m6 X- d+ w
0 s$ }5 ~, M. K( x
            // Get the object from the WORKPIECE tag* Q, M7 a/ f, L+ h
            CAM::FeatureGeometry *WP = (CAM::FeatureGeometry *)NXObjectManager::Get(objects[0]);" D) _! V- Z' ^1 o$ r9 N+ q8 a
( L! y: o& u  L
9 K* B! z$ b- k) ?! n3 x' I
            CAM::MillGeomBuilder *millGeomBuilder1;
! w) N6 [) ~7 T. I' t            millGeomBuilder1 = workPart->CAMSetup()->CAMGroupCollection()->CreateMillGeomBuilder(WP);
, N) \- o" X  b, B9 I* s& U4 N
( w: D5 J& ~5 G  H
% I4 `; v# @+ [- m" S0 {
            // Get geometry set list- ]' Q' G$ I% o3 l$ A" P8 @9 U% R
            CAM::GeometrySetList *pGeomSetList = millGeomBuilder1->PartGeometry()->GeometryList();
+ k8 f. I  v# e+ L+ T9 R            std::vector<CAM::GeometrySet*> geomSetVec = pGeomSetList->GeTContents();
' o# _' E' Y3 S) u0 |! {4 i1 E  y7 D5 S" U: {3 B1 H  S
7 G/ q7 l! g/ ~' I( u
            // get geometry set
. Q5 M* e: Z( q( |            std::vector<CAM::GeometrySet*>::iterator iter;
: \) v7 u4 H/ f4 Y( Z" _% Q2 @! P) V            for ( iter=geomSetVec.begin(); iter != geomSetVec.end(); iter++ )6 F$ Z  Q/ o" w0 ?) F
            {) ?& I# C/ c% P# N3 i
                CAM::GeometrySet* geomSet = dynamic_cast<CAM::GeometrySet*>(*iter);
, K5 a' }* m' Z( C: d) a4 }                ScCollector *scCollector = geomSet->ScCollector();              n0 M; {3 e/ ~
                std::vector<SelectionIntentRule*> rules;
% ~3 {" N6 y3 Y3 a, f                scCollector->GetRules(rules);
, D; ^' c& U6 H9 D# Y; a
& F9 B; x% ]& C$ Y

7 [+ I- H  {/ o' J                //get selection rule
! ~( o: N, ^0 B8 m8 S) b3 v                std::vector<SelectionIntentRule*>::iterator ruleIter;  C7 B) n! e" b/ `3 Y7 q
                for ( ruleIter=rules.begin(); ruleIter != rules.end(); ruleIter++ )
+ f% f4 j) z# x3 B( J$ Z9 S1 P                {
% p( {- V3 G" b0 V& h                    SelectionIntentRule* selRule = dynamic_cast<SelectionIntentRule*>(*ruleIter);$ \9 D% i3 f9 U; O5 N! L
                    NXOpen::SelectionIntentRule::RuleType ruleType = selRule->Type();& L: W/ l. T6 J; }, j$ D
                    //there are different rule types, here just use body, face as sample8 z$ D. r+ |1 s' ?
                    switch ( ruleType )1 L& @+ S" G3 l2 T. I3 \
                    {
7 C5 W- V2 y% i3 j4 }1 h( Y                        case NXOpen::SelectionIntentRule::RuleTypeBodyDumb:
" Q7 r  m& {6 c" Q# b. e4 T                        {
- Q" O) S) w7 y0 n2 w0 {3 D% @; g7 b                            //get bodies
" H6 [1 f0 {& ]1 u( Z) x                            NXOpen::BodyDumbRule *bodyRule = dynamic_cast<BodyDumbRule*>(selRule);9 d" F$ h+ n* q' x( ?4 o
                            std::vector<Body*> bodies;
- ~, i% R; U$ }8 q- I8 X4 _7 j                            bodyRule->GetData(bodies);9 u! V8 P5 U2 T3 Y& p
                            std::vector<Body*>::iterator bIter;
6 v$ t+ c, J2 t- J. y7 q, v+ c                            int index = 1;% B& e' n7 M/ }6 ?: m
                            for (bIter=bodies.begin(); bIter!=bodies.end(); bIter++ )
1 s, I4 K' x% g/ B4 I                            {
+ J: c: O+ s7 U                                Body* body = dynamic_cast<Body*>(*bIter);0 u0 B# R9 o8 ]  ^4 u1 U4 x' ^
                                ObjectTag = body->GetTag();
* i9 s0 ]' Z- e                                sprintf(mesg,"the geometry object type is body, the index is %d and the tag is %d\n",index, ObjectTag);                                
# B* U3 k$ {1 r+ j, O+ ~: F                                WRITE(mesg);
8 C0 s2 @! e& D3 v& \% W                                body->Highlight();
( P9 @. D/ l! f8 C                                index++;
, z6 L6 ^( L3 X3 z" M  D: J( b                            }
/ ?9 u- e4 y) @2 ?" |7 o2 c" u                        }1 Q' k- A8 Q$ T# O. I
                        break;* N! v1 K3 |! y! z0 a

% M" z8 J5 l  t+ R

0 A5 d+ g6 ~/ l* e2 p                        case NXOpen::SelectionIntentRule::RuleTypeFaceDumb:. Y$ i9 a4 r) t+ s% h) J' F+ F
                        {
# J1 d5 _. p4 Y: E: {: `                            //get faces 5 T% p9 U. \8 W7 `( S
                            NXOpen::FaceDumbRule *faceRule = dynamic_cast<FaceDumbRule*>(selRule);4 y3 D+ i8 `* V) o& r$ }) h
                            std::vector<Face*> faces;: D0 @! o4 C9 E. H. {
                            faceRule->GetData(faces);
/ [0 O  \& n; i2 l                            std::vector<Face*>::iterator fIter;
9 K, a* ]' `9 f8 \+ B2 h# G                            int index = 1;- W1 B2 V) W/ {. X) W+ y7 Q
                            for (fIter=faces.begin(); fIter!=faces.end(); fIter++ )
; X8 G) A! T, a3 v                            {
! r7 Z5 G+ L5 M9 [; M& R/ g                                Face* face = dynamic_cast<Face*>(*fIter);
6 E+ K0 H. Y& _                                ObjectTag = face->GetTag();
* @: y5 |7 N2 ^! ?9 |$ w! H  v5 W& x                                sprintf(mesg,"the geometry object type is face, the index is %d and the tag is %d\n",index, ObjectTag);                                
- G0 A. Z; y* e                                WRITE(mesg);
8 B: f: a! c) n' x1 F" N* `                                index++;
" @1 Q+ L) a  z- \  y: a# t8 k, L0 q2 J                            }
% N" k; S6 e8 K/ q$ P$ Y                        }
( q: `5 t7 Z7 W( p" E2 b                        break;* A4 f6 U& j  }2 H' F6 A0 j
' w  l$ y6 ~* ]3 O7 G% }% Z; E/ u

$ U. c; Y9 `) V, o8 `$ m- [                    default:
8 v5 n8 l) p; j* S3 w* ^                        break;8 l) P  j3 y: H1 M1 s- f4 r  V8 ~' i
                    }
9 W: z" C" H* C  K, }" H. U                }6 u$ u* I: d! d# n0 |, R1 F
            }
6 q( _, [# A8 f7 L7 f: w) A7 w  C" S2 r3 ~! d; E1 |) m1 c+ {
  ?  |/ @( M9 {) d5 B7 P. u
6 t/ _0 v& d; B# x' x7 `' r" H6 B" ]
( M3 n# Z$ L1 L" w# R3 O& q. ^: S( U; R
9 Z7 G5 d" d/ E; y& O8 R
: }, N3 g$ j7 [0 _& P
            millGeomBuilder1->Destroy();
# f; A. c- n- M: b( J1 U# \, [- D# T4 w
7 P7 w1 p2 c2 [" w1 n
        } else {
. p9 U) s5 w" E- H1 a            WRITE("type is not UF_machining_geometry_grp_type");
/ v9 E+ b/ n, u7 d            WRITE(" or UF_mill_geom_featr_subtype");" D; c2 i8 G) a1 n. G4 U# c, I  _9 J
        }
8 [; f6 g" e  l# z        UF_free(objects);
: K7 K  j/ |9 p( i7 F0 V
5 s$ K+ F/ x5 s$ a3 f# D
0 L. F: R6 s: v/ t
    } else {/ d: e2 G( W4 ~/ W' W, e
        WRITE("The number of selected objects in ONT must be 1.");
) ?, c; c6 Q- `+ _$ w    }  X3 h4 }, P4 N! E0 m8 {

. z3 N1 a2 _5 }* ?+ m

! I- A$ ?8 b) V9 q7 ^  H}
& |, K9 w" R7 K% D* t
: R! l1 P; C! V5 B4 p1 b, f
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了