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

Catia二次开发源码分享:创建草图 Sketch,约束,曲线等

  [复制链接]

2018-2-22 13:25:32 3321 0

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

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

x
有两种方式可以创建草图:
/ \/ |! X. H" k& a1.通过参考平面创建8 ~0 M* n9 v" t2 S! @0 ^
//获得参考平面8 |) ~0 I) P' ?+ x* H
CATLISTV(CATISpecObject_var) spRefPlanes = spPart->GetReferencePlanes();
5 v5 I4 n" r3 n* F+ o+ p5 e, k//初始化草图工厂
- o" [1 h% ?3 h) O  J+ aCATISkeTChFactory_var spSketchFactory(spContainer);, |/ M% V' l' K( L0 e4 ~4 N
//在XY plane 上创建草图
6 ]) _9 @, h6 v. xCATISketch_var spSketch = spSketchFactory->CreateSketch(spRefPlanes[1]));7 C$ v- N3 ^& T2 Q/ P7 g( W
2.通过原点和两个矢量方向" p6 S2 L5 F% X0 }% z+ h
该方法通过定义一个原点和两个方向 pH、pV 进行创建。
: |# A/ E; b  `3 i; Y4 ^% T定义原点和方向:6 W) D- h2 D& |4 V! J4 }- q# {
double pOrigin[3]={0,0,10};
2 r- y6 `& |2 r+ Ydouble pH[3]={1,0,0};
" Z5 V: U1 K/ N# hdouble pV[3]={0,1,0};
5 _3 r% y, ~. ?+ @1 }( v4 dCATISketchFactory_var spSketchFactory(spContainer);
. k5 E/ {% e6 S. s! D  @7 s$ ICATISketch_var spSketch = spSketchFactory->CreateSketch(pOrigin, pH, pV);
* P1 ]' |. `) x; [# w+ k! @( m
+ m% f2 ~2 d! U0 o: n# J& |7 o# v" [0 j+ K/ Q
sp2DFactory(spSketch);0 x" F, g1 [( @9 ^6 f7 W  i6 r% ?
//下面创建点
5 t; `, y7 s6 j! @7 vCATI2DPoint_var spPt_bottom_left, spPt_bottom_right, spPt_top_right, spPt_top_left;% h* N1 ^+ E! B
double pt_bottom_left[2] = {10, 10};
6 [4 z# \/ i8 A: ~" @3 S7 Fdouble pt_bottom_right[2] = {50, 10};
1 A8 q! |, T: y- cdouble pt_top_right[2] = {50, 50};, ?$ O5 b( z. k
double pt_top_left[2] = {10, 50};( F+ D1 r: s$ V" b
spPt_bottom_left = sketch2DFactory->CreatePoint(pt_bottom_left);
6 C9 {$ b; H: G  P5 ]; j, rspPt_bottom_right = sketch2DFactory->CreatePoint(pt_bottom_right);
& q/ R+ U" D% @* Q. n7 GspPt_top_right = sketch2DFactory->CreatePoint(pt_top_right);; {9 l3 p9 o3 x8 g; o) K5 R5 Q
spPt_top_left = sketch2DFactory->CreatePoint(pt_top_left);. M$ X7 t( U7 z& z- c5 T3 O
//开始创建线2 h- s7 p+ n2 B7 o
CATI2DLine_var spLine1, spLine2, spLine3, spLine4;
$ d' E0 O. }+ `/ F* xspLine1 = sketch2DFactory->CreateLine(pt_bottom_left,pt_bottom_right);) e# k* ^, X) _( m6 ?' |
spLine2 = sketch2DFactory->CreateLine(pt_bottom_right,pt_top_right);
+ E  i+ r. o( |. MspLine3 = sketch2DFactory->CreateLine(pt_top_right,pt_top_left);; T- d4 t! o9 X# Z' }- p$ r
spLine4 = sketch2DFactory->CreateLine(pt_top_left,pt_bottom_left);3 B: ?. L: V- I9 }  ~
//将线的首尾连接起来0 R) |( U& w/ a) w3 l/ \: W
: }/ n# P, t: j& I1 U  k! I
CATI2DCurve_var spCurve1 (spLine1);7 g! }. M9 k# _0 q% h
CATI2DCurve_var spCurve2 (spLine2);; _6 T, u7 w. _8 s. s
CATI2DCurve_var spCurve3 (spLine3);' f, }2 }3 s1 g) T' }9 N
CATI2DCurve_var spCurve4 (spLine4);
3 j2 U3 W! w+ A# v2 L- K- w4 hspCurve1->SetStartPoint(spPt_bottom_left);
# \# @1 G4 I0 Z9 q' U2 z- M( QspCurve1->SetEndPoint(spPt_bottom_right);, W1 [! A  ?7 D$ l6 d
spCurve2->SetStartPoint(spPt_bottom_right);: ^9 @6 C8 B  f" t; T% R& Z* ?
spCurve2->SetEndPoint(spPt_top_right);
2 ]" D0 B' P& c3 u0 K9 ~, C5 SspCurve3->SetStartPoint(spPt_top_right);
; r! ~* N+ _3 _8 @7 n$ @7 BspCurve3->SetEndPoint(spPt_top_left);
8 K( Y( z) o/ z$ `spCurve4->SetStartPoint(spPt_top_left);) _5 A; d* z0 a5 h5 Q9 |2 l. s
spCurve4->SetEndPoint(spPt_bottom_left);3 j6 C8 z+ [! O( O8 Q
//然后退出草图:2 M" q1 O7 x; s4 \
spSketch->CloseEdition();1 A; r6 f' B6 G0 \
: ~; C; R  R6 n& s& z, E
# P( g+ h( R* @
8 e  @6 p3 k* S" |/ b1 {
创建草图约束! M4 @, H% @) h& M, |: P
CATI2DConstraintFactory_var spConstraint2DFactory(spSketch);
6 K! |+ k$ U/ x$ ?3 @9 |//定义spLine1 为水平约束9 q0 i0 f7 U4 w2 C3 ?
spConstraint2DFactory->CreateConstraint( spLine1, NULL, NULL, NULL, NULL, NULL,9 h$ D) C4 m  a% t3 T, Q: y9 \
NULL, Cst2DType_Horizontal, 0, 0 );( q2 c) D9 S. Y) M, D
//定义spLine2 为垂直约束
- R, h& a" X2 E  b# ?3 _( Q, rspConstraint2DFactory->CreateConstraint( spLine2, NULL, NULL, NULL, NULL, NULL,& V% a! Z' ~6 o: E* Q
NULL, Cst2DType_Vertical, 0, 0 );) `$ x2 {% M, {+ }1 h: F
//定义spLine3 为水平约束' F; s, f2 s( N9 }6 m
spConstraint2DFactory->CreateConstraint( spLine3, NULL, NULL, NULL, NULL, NULL,
6 A/ V! {$ `# T. q: B! k: tNULL, Cst2DType_Horizontal, 0, 0 );+ J/ m, m: X& {. v7 r/ e" S
//定义spLine4 为垂直约束# H* f/ ]  @- `: r8 J: b2 {  K
spConstraint2DFactory->CreateConstraint( spLine4, NULL, NULL, NULL, NULL, NULL,& l; O7 A/ h2 w' q1 r
NULL, Cst2DType_Vertical, 0, 0 );
: C" I2 `, @8 l/ k//定义spLine2 的长度约束' q, p9 c0 p0 s# M
spConstraint2DFactory->CreateConstraint( spLine2, NULL, NULL, NULL, NULL, NULL,: e( ~/ k9 V. ?! T/ B& U
NULL, Cst2DType_Length, 0, 0 );: p; b% ?8 c+ w
* K" X' c3 [9 v( R- f
//定义spLine2 与spLine4 的距离约束4 F( u5 s2 x- m& t9 |  k! ~
spConstraint2DFactory->CreateConstraint( spLine2, NULL, spLine4, NULL, NULL, NULL,
& s- U. }3 N( }  u3 F9 i3 I3 Z  ONULL, Cst2DType_Distance, 0, 0 );
) d6 S9 D$ i4 \" Z//定义spPt_bottom_left 与X 轴的距离约束
+ H5 T, g, I. Z2 lCATI2DAxis_var spSupport = NULL_var;
0 i% V; k! y( [. U5 O5 AspSketch->GetAbsolute2DAxis(spSupport);7 g7 Z( V0 [: x' r! s
spConstraint2DFactory->CreateConstraint( spPt_bottom_left, NULL,/ E% P+ `. x1 A5 X7 D* I$ Q& r
spSupport->GetHDirection(), NULL, NULL, NULL, NULL,Cst2DType_Distance, 0, 0 );( ^3 D' _& w. {3 l+ g
//定义spPt_bottom_left 与Y 轴的距离约束
  n5 t6 \$ V% ^5 ~spConstraint2DFactory->CreateConstraint( spPt_bottom_left, NULL,$ H; E: v1 |. g+ |; k
spSupport->GetVDirection(), NULL, NULL, NULL, NULL,Cst2DType_Distance, 0, 0 );2 {) |# U" w$ i* \/ b
, Q% h1 p0 O8 J! r* R" t
: R  G; u$ t1 X3 j  I
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了