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

[交作业] 通过UI结合代码生成倒圆角功能,有成就感!

  [复制链接]

2015-11-23 16:33:40 3944 3

秋爱 发表于 2015-8-15 09:15:43 |阅读模式

秋爱 楼主

2015-8-15 09:15:43

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

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

x

# @0 a5 X- v" _. nvoid selectedge::initialize_cb()! d7 t: n$ [- N: S, x7 [# ~
{
, Z' N9 W8 Q; `8 b5 ^8 Y$ g5 y    try- S' A: h9 J2 Z9 z" {
    {

9 k  `5 l& Q8 v1 J  b5 |        group1 = dynamic_cast<NXOpen::BlockStyler::Group*>(theDialog->TopBlock()->FindBlock("group1"));
  J4 J3 v% G8 J& I        edge_select0 = dynamic_cast<NXOpen::BlockStyler::CurveCollector*>(theDialog->TopBlock()-             >FindBlock("edge_select0"));. y+ E) Y" y& B7 C, f
        expression0 = dynamic_cast<NXOpen::BlockStyler::ExpressionBlock*>(theDialog->TopBlock()-       >FindBlock("expression0"));}) @( F, R9 J/ A
    caTCh(exception& ex)$ v' r) E" R1 _3 D' ]8 r
    {7 M) s1 S' [9 ~1 b! }, N9 H
        //---- Enter your exception handling code here -----2 o$ d1 |$ P" E( v4 C6 {1 x
        selectedge::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox:dialogTypeError, ex.what());
9 f, i* ~6 Z! ^    }
" [& R7 |- F+ p9 F8 h4 ~, F  r% @}8 D& v2 P0 ~5 }% p- {
) J) U* f1 W2 O  P
int selectedge::apply_cb()
+ K5 y+ k% d* m{. ]" d. G2 ~" D; j
    int errorCode = 0;& w# \6 k+ F9 I( b0 F) p6 }" N9 _
    try
6 N9 S" u+ A1 n; T: O: i% H    {
, ~, s/ v7 u) G6 m+ z        //---- Enter your callback code here -----4 e& w- c4 B9 Z5 r) B- E

+ f; s6 H7 p' `$ r) n# t" \
9 N/ A4 b0 ]" B

& U. y) K* o  v: R                Session *theSession = Session::GetSession();
; T: e0 l" u: ]; X+ k                Part *workPart(theSession->Parts()->Work());4 P; _$ s6 i- l. z$ {$ g! u% U
                Part *displayPart(theSession->Parts()->Display());
, ^; U" `) ~7 c8 `( y0 }$ w( A% c6 A3 \$ M% ?% c6 Q
) r$ D7 {- b" l- N9 z6 n( q: j
                Features::Feature *nullFeatures_Feature(NULL);
$ k+ M) F  R' W  w9 y2 l                Features::EdgeBlendBuilder *edgeBlendBuilder1;$ E* j0 S* X1 ~) Z: Q5 f% M$ z) L# ~
                edgeBlendBuilder1 = workPart->Features()->CreateEdgeBlendBuilder(nullFeatures_Feature);
2 q  U  x4 _1 u; @' b) n: F
( `& g9 G7 J; x' K

; l# j: Q$ k7 D; V: s5 S, R9 f% d                ScCollector *scCollector1;( C) w' p: Z, a9 f! f" k6 y
                scCollector1 = workPart->ScCollectors()->CreateCollector();
5 F2 r( e" t3 t' U- e; F6 U4 |( Q9 n2 T7 n! G- I

3 o' I0 G! Q; U: a3 e; ^                std::vector<Edge *> seedEdges;
1 e! ]/ I0 f- W0 l7 K. W, \               
& v1 k/ p3 t0 x$ a2 d& k* O7 e# \# c                std::vector<TaggedObject*>selectob = edge_select0->GetSelectedObjects();       //获取选择的对象6 h) b) B/ A3 K# D5 |
                for (int i=0;i<selectob.size();i++)4 S* C- w, p. J9 f0 }2 Y
                {* V$ T. f" o  i4 B$ a
                        seedEdges.push_back(dynamic_cast<Edge*>(selectob));* J4 I% y+ k1 y# L6 K) D
  }
$ ~6 ~/ J+ O+ e* f1 {' H0 N9 t1 F- ?! @; }- l& Y0 o
  double dia = expression0->Value();            //获取表达式的值4 `" Y% f: [# x4 u$ ~% k% F
                stringstream DIA;
8 y1 M4 T# }1 I! S                DIA << dia;
/ m" r# k/ g% P6 W+ k0 v
; t! t& @& R& c6 e, B8 X4 L
  H, b# i; R- B* @- i3 b
                EdgeMultipleSeedTangentRule *edgeMultipleSeedTangentRule1;3 S* l% b( Q  P* k1 N& q
                edgeMultipleSeedTangentRule1 = workPart->ScRuleFactory()->CreateRuleEdgeMultipleSeedTangent(seedEdges, 0.05, true);
) _: q' W' y* l2 u+ X8 h6 q3 Q( b( X( {3 l1 [4 K# w/ J* R
# {' `5 G5 B/ m+ a8 O0 O; T
                std::vector<SelectionIntentRule *> rules1(1);( t; ^' C' w! N: ]  e- }1 t
                rules1[0] = edgeMultipleSeedTangentRule1;. Z5 _2 K& o$ s) Q6 N0 i
                scCollector1->ReplaceRules(rules1, false);5 |* [& ^: h) O, }
/ A; o  m% f. _8 J& T. r

* o$ L) s' K& d                edgeBlendBuilder1->SetTolerance(0.001);
7 s4 R$ b: H, k. z  H& }2 e) I
* ]% R2 d* J5 F; B, }+ M

& X% z* Q: `% n! M2 O4 W                edgeBlendBuilder1->SetAllInstancesOption(false);
; A1 i* L  c* Z# ]" E- l% |. |: E. j; g0 n. C
' i& |* w3 F; K5 h5 p3 t
                edgeBlendBuilder1->SetRemoveSelfIntersection(true);
) F' H3 M( c# e7 P& O
+ G) X$ |3 E9 K$ m$ P4 X
' |' S5 {4 E& [4 ?9 n/ A% C
                edgeBlendBuilder1->SetPatchComplexGeometryAreas(true);
* [7 w2 o: t6 j3 W3 q$ ^0 y, N7 g4 X' h* U
% _  u- W4 J; |( u. m$ ?7 R! n
                edgeBlendBuilder1->SetLimitFailingAreas(true);
1 _* X  P8 `  e2 u
- ]$ `, \: ]' D( @( H

2 x3 @& M; k5 M$ c* F. }                edgeBlendBuilder1->SetConvexConcaveY(false);
' k2 o; r! h6 q/ v# p3 k1 j+ B9 D
: P0 R# K' _, B) ~  o
                edgeBlendBuilder1->SetRollOverSmoothEdge(true);* u  n; S- x8 O1 M4 D* D* C1 g

. F, V" ~4 F" W, p* V. `

$ w! K' S6 |+ g) R7 Z; {$ P                edgeBlendBuilder1->SetRollOntoEdge(true);) O+ m( N9 q2 p1 J

* X" _; Y0 R$ r+ n, W

* u! O4 k! U. J# ^: s! }2 e                edgeBlendBuilder1->SetMoveSharpEdge(true);
% Z. u% B! s: ?
! s  i4 a' l$ \4 ~3 }1 H" X- w
3 P' v5 x7 x" t4 ^; N: J  Q
                edgeBlendBuilder1->SetTrimmingOption(false);8 M1 s/ a6 t" |; N( s: A1 m

# n; \6 g; [7 O! v7 w; H0 y5 W' b
2 a) C3 D  N5 S7 C2 @& [& D" d: L
                edgeBlendBuilder1->SetOverlapOption(Features::EdgeBlendBuilder::OverlapAnyConvexityRollOver);. `& I$ t% B- M5 C" Y7 {
, I8 M0 L' O7 B$ d/ G/ e
/ a  W9 i, _( t* ?3 N# [; Y8 `
                edgeBlendBuilder1->SetBlendOrder(Features::EdgeBlendBuilder::OrderOfBlendingConvexFirst);
1 L4 T$ k, ^' _: z+ q4 X8 C) ]" d+ |% l' d- d" H1 n: G
  {/ k: D+ H3 T0 u, U% t* Y2 C
                edgeBlendBuilder1->SetSetbackOption(Features::EdgeBlendBuilder::SetbackSeparateFromCorner);6 v8 t, _. [$ p+ w+ a
8 a* Y- Q2 Q/ w: O! s- m, D& s4 B; V& F

/ W: Z2 l4 U" e                int csIndex1;
0 O, N% ^1 f7 O0 s# \# ^& V6 V8 |                csIndex1 = edgeBlendBuilder1->AddChainset(scCollector1, DIA.str());
* F# K2 P" w/ u; v- R  Y
. W- M- y  t! L0 {. M" C: z* I: ~( u' D
! [& r1 v1 Q. v+ w, L. B
                Features::Feature *feature1;
1 |+ j, ~! M+ m- F2 ~                feature1 = edgeBlendBuilder1->CommitFeature();
+ U0 H: m, F; }. @+ S" A3 Z$ c& v0 A) I& v) L2 ]
6 z% o8 q9 U& F+ C* i8 X
                edgeBlendBuilder1->Destroy();
* W+ {6 m& U" w( H
1 `# w9 c% z0 T9 ~3 ]9 \4 Q    }
& U. E$ G0 V! D+ k. X% P) ]    catch(exception& ex)
) F6 ]$ ~- Z. ]$ ~    {1 ^5 w; ~' O* l4 a! i
        //---- Enter your exception handling code here -----
$ B1 R# \8 q/ F( b% |        errorCode = 1;! d: m+ C. m. E3 @3 z
        selectedge::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());0 r$ Z/ D3 w: e
    }3 b8 s( M& m+ _
    return errorCode;- W6 O% q9 u' J; a0 r4 `
}

, S2 `% m, f7 d  P% V5 f
7 e) ~" G% P6 q: h( ?2 ^' E6 U" u
说明:因为字数有限制,这里只贴出关键代码。
$ d: t1 Y& i' L- E* R8 \+ y1 h  W, T8 F5 w

6 \2 E2 e% x; F+ Z
& r: r! t/ D: k4 S  Q# l# j
QQ图片20150814180022.png

评分

参与人数 1PLM币 +5 收起 理由
admin + 5

查看全部评分

上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复

使用道具 举报

全部回复3

heromo 发表于 2015-11-4 11:12:18 PLM之家手机频道

heromo 板凳

2015-11-4 11:12:18

如果我选择是一个实体,怎么自动将所有的边倒圆角呢?
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复 支持 反对

使用道具 举报

秋爱 发表于 2015-11-23 16:33:40

秋爱 地板

2015-11-23 16:33:40

遍历加判断
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复 支持 反对

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了