查看: 3221|回复: 0

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

[复制链接]

4

主题

4

回帖

52

积分

管理员

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

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

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

×

" A. e! b; _+ M, K% S  _$ T- i) Z7 [3 E' Z) Q. B- B

7 }% B6 I7 O4 P7 g% c' w% j创建一个选择feature的功能,当用户选择的是sphere的时候,让用户选择更改球的直径!
% F$ N; |! Y, {3 }8 l! |2 g4 z' l+ u+ [- V  V3 t4 P0 U
Session *theSession = Session::GetSession();6 R5 y0 G( D. z
        UI         *theUI = UI        ::GetUI();! P& g: n9 N8 G3 ~+ R! E
        Part *workPart (theSession->Parts()->Work());
7 L0 Z9 h6 l% L7 t- q" W. c2 H: \7 S% ~$ s# |* f  [3 e
        // initialize the select
+ E0 J  g7 P, J: X$ u% T        std::vector <Selection::MaskTriple> masks(1);. a3 E' A7 J+ p5 ~# V6 `
        Selection::MaskTriple mask;
4 U+ c3 \! k0 ]& J        mask.Type=UF_feature_type;
) J* W/ H# L/ a0 o6 F3 H5 U) N5 f        mask.Subtype =0;
# I; J/ w3 i3 C3 j5 r        mask.SolidBodySubtype=0;/ v: @4 h) q5 ~- P3 v& t. H
        masks.push_back(mask);
& _- a, G8 C# X, ]! Y  Q        //masks[0] = {{UF_feature_type,0,0}};9 t; H9 w) M- U  B) j$ k9 B5 ^
        TaggedObject *object;) k) u+ {& M, \9 s" q( I
        std::stringstream ss;4 @3 L) t- N# y+ A
        Point3d cursor;& ^6 a# H8 ^4 Z7 [% C
        Selection::SelectionScope scope =  Selection::SelectionScopeUseDefault;
, O. [! q  ]1 \( o* r9 e& Q        Selection::SelectionAction action = Selection::SelectionActionClearAndEnableSpecific;7 n3 c8 E# \0 p* ~- C7 ]" {2 j
        Selection::Response res;1 u2 S! G& W& a$ f. C
        Features::Feature * getFeature = NULL;
6 ~4 x4 F9 p8 a, [& X1 k: o* K8 e        res = theUI->SelectionManager()->SelectTaggedObject("select a feature:","feature select",scope,action,false,false,masks,&object,&cursor);6 }( W9 ~9 d5 `
        if(res == Selection::ResponseObjectSelected || res == Selection::ResponseObjectSelectedByName)0 @- Z+ z* \8 r* [. W+ X4 ]( a6 k
                {
& s2 B, G' L# w4 M                        // get the information* z& Y& \2 R* }5 B) C: o" W& ~5 [
                         getFeature = dynamic_cast<Features::Feature *>(object);8 k4 e) a2 a8 J& U

! l$ C4 n/ Z- H5 q# q6 Q8 i          theSession->ListingWindow()->WriteLine("the select feature type is : " +getFeature->FeatureType() + "\n");* o" h! c5 f# f9 ~' ]
$ Y& b: @& f! `
                 if (!strcmp(getFeature->FeatureType().GetUTF8Text(),"SPHERE"))( J* x( p  |5 ~& a! R
                 {
' k" {4 u4 n8 ~% k( Q                         Features::Sphere *getSphere = dynamic_cast<Features::Sphere *>(getFeature);$ O0 m* z. i; {  B9 s. R
                         std::vector<Expression *> exp =  getSphere->GetExpressions();' m1 D, Z3 _4 }  b4 R. O
                         ss << exp.size() <<endl;2 K7 m4 s7 ]1 c1 Q
                         theSession->ListingWindow()->WriteLine("the expression number is : "  + ss.str() );
9 f, i3 g; L6 z- Y2 b( P                         for(unsigned int i =0 ; i< exp.size();i++)
; \; W, L) l$ U+ m                         {   
) P6 S6 y- S3 \7 W5 p* B$ q                                  theSession->ListingWindow()->WriteLine("The expressions are : " + exp[i]->Equation()+"\n");8 r! O& r3 T( C- s3 _3 w" x" e
                         }
( ?& m$ p4 n' V; G; D  `                         Session::UndoMarkId undomark = theSession->SetUndoMark(Session::MarkVisibilityVisible,"change the exp");7 Y) F8 E: S: q: o4 Q4 f2 P
                         exp[0]->SetRightHandSide("400");
( J! Q7 [+ n9 w# v+ Q; V0 Z                         theSession->UpdateManager()->DoUpdate(undomark);9 o3 G! b$ w; F7 S" Q
                         theSession->ListingWindow()->WriteLine("The expressions are : " + exp[0]->Equation()+"\n");$ V; Z2 w4 E: S5 m! Z) s0 H
                 }
" f- C2 {3 i1 g) g. M          }/ @: g& f; I3 Y1 J- P

1 G. [5 B+ C7 ~8 |' d9 ^5 O# a6 v
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复

使用道具 举报

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

本版积分规则

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