查看: 3171|回复: 0

[资料分享] NX二次开发培训源码分享: 通过选择指定特征,修改特征...

[复制链接]

4

主题

3

回帖

44

积分

管理员

积分
44
发表于 2015-1-9 09:20:48 | 显示全部楼层 |阅读模式

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

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

×
9 z$ \: I: q6 v  D$ L! u! K+ B
6 _% S( c; s/ u' T2 _5 V( q
  f' f) J# E9 E2 J" m, Y9 Y
创建一个选择feature的功能,当用户选择的是sphere的时候,让用户选择更改球的直径!( x# B7 Q$ o. r

  O7 K# r) L  S4 |Session *theSession = Session::GetSession();+ ]& v/ w/ m7 k. u
        UI         *theUI = UI        ::GetUI();
. Q9 @6 F6 W; z4 Q        Part *workPart (theSession->Parts()->Work());0 w  i5 m* z% B
! q3 ~0 L" R1 D. v
        // initialize the select 9 F) }8 O  N+ |
        std::vector <Selection::MaskTriple> masks(1);
/ W' R4 I. Y$ y% `' D        Selection::MaskTriple mask;+ W( l+ U8 J8 W0 r; |
        mask.Type=UF_feature_type;2 d% L' d6 L3 r) {3 R; s
        mask.Subtype =0;, ~1 O3 h9 m: t
        mask.SolidBodySubtype=0;; B' V) L( v  h/ V
        masks.push_back(mask);
" g: O+ a& q# y# n        //masks[0] = {{UF_feature_type,0,0}};2 A- O5 S; O% Y3 _4 i' q$ ]
        TaggedObject *object;
) `  L/ ~  S: N! e# Z! X  U        std::stringstream ss;# T- i. m6 `/ I9 Z2 ^6 Y
        Point3d cursor;9 O3 y( Y( G  o) Y+ ?9 E
        Selection::SelectionScope scope =  Selection::SelectionScopeUseDefault;
: }; M4 l8 A- b. I; f5 ~# w4 _        Selection::SelectionAction action = Selection::SelectionActionClearAndEnableSpecific;/ ]1 x7 r5 e& }7 y
        Selection::Response res;
  ]$ e# d5 I: Q2 P* s# V        Features::Feature * getFeature = NULL;8 a# ^4 U- M: M! i) \2 `
        res = theUI->SelectionManager()->SelectTaggedObject("select a feature:","feature select",scope,action,false,false,masks,&object,&cursor);6 W9 b$ E1 f8 X  Y; I. a
        if(res == Selection::ResponseObjectSelected || res == Selection::ResponseObjectSelectedByName)
. C* R3 [* Y5 P* E! N1 Y6 R0 g% O+ \/ W                {
3 D& x! Q- y7 T; W% q  {1 f4 [                        // get the information" y6 x0 [) D2 D
                         getFeature = dynamic_cast<Features::Feature *>(object);
, B+ ]) r$ u- E9 z) G* g+ ^  P( e, e- |4 F/ p
          theSession->ListingWindow()->WriteLine("the select feature type is : " +getFeature->FeatureType() + "\n");
! u: {/ ?; ]) s. j3 _& O, [! N: U: `% ^5 g& Z" E
                 if (!strcmp(getFeature->FeatureType().GetUTF8Text(),"SPHERE"))" X1 Q$ M1 K" F, [7 Z
                 {
# \/ w, {7 \% v  O+ O; \' d                         Features::Sphere *getSphere = dynamic_cast<Features::Sphere *>(getFeature);
2 i5 ?& T8 F* B                         std::vector<Expression *> exp =  getSphere->GetExpressions();) _; B( U+ y. K/ s
                         ss << exp.size() <<endl;& F8 G6 [0 h$ ~# q6 b
                         theSession->ListingWindow()->WriteLine("the expression number is : "  + ss.str() );
2 N7 K2 s+ v. P5 |- ]% i# b% U                         for(unsigned int i =0 ; i< exp.size();i++)
. Q- {' c# a7 h. L% `! R! H1 ~0 Q                         {   . n# [$ {4 @$ F% e; }! l
                                  theSession->ListingWindow()->WriteLine("The expressions are : " + exp[i]->Equation()+"\n");
5 s* W0 Q( A; |: m" w# x8 e                         }
3 k( x& [( M. ~. c# A                         Session::UndoMarkId undomark = theSession->SetUndoMark(Session::MarkVisibilityVisible,"change the exp");
7 n! J9 z8 U+ R; w; l                         exp[0]->SetRightHandSide("400");
& F* p1 {. J, G" K                         theSession->UpdateManager()->DoUpdate(undomark);
8 M0 @- t6 v. S( k/ k( o                         theSession->ListingWindow()->WriteLine("The expressions are : " + exp[0]->Equation()+"\n");
( |. p1 ~8 m! X3 m% z5 a5 U                 }
! W! ~& G4 H4 y          }
/ @& j  R. ]" S' i) J- X% J3 T5 d6 S9 \4 t9 ^4 P  T

9 }; E1 ?# r: u) z4 o$ \9 X, W% G/ F
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

在本版发帖
关注公众号
QQ客服返回顶部