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

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

  [复制链接]

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

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

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

x
有两种方式可以创建草图:
4 v  Y+ p7 ?' c6 w* O1.通过参考平面创建0 ?' A, O5 \" R6 v" n0 D
//获得参考平面" \6 ~1 I$ m& Y9 o* ~0 b
CATLISTV(CATISpecObject_var) spRefPlanes = spPart->GetReferencePlanes();
4 {1 e, q2 v7 H; @! S  S, ~//初始化草图工厂$ h4 O) P. ^) M: Y+ F' |
CATISkeTChFactory_var spSketchFactory(spContainer);: A9 q  \2 u' n% G( w4 ?5 y
//在XY plane 上创建草图
% Z0 I7 T7 Z5 l; \. J: PCATISketch_var spSketch = spSketchFactory->CreateSketch(spRefPlanes[1]));
+ w: n; u; t0 D; J+ _7 d2.通过原点和两个矢量方向5 }" ~3 F3 a1 g  D7 Q5 [
该方法通过定义一个原点和两个方向 pH、pV 进行创建。
7 E7 u6 ?2 r5 e6 ~' P定义原点和方向:
* J0 n. Z0 \: X& Ndouble pOrigin[3]={0,0,10};0 C% m0 U& X% p  \9 d& n* V
double pH[3]={1,0,0};% i% _+ a9 H- ~" U0 l5 k
double pV[3]={0,1,0};
5 w8 `/ X6 r8 G" i7 A% GCATISketchFactory_var spSketchFactory(spContainer);2 W$ X9 o3 A4 d
CATISketch_var spSketch = spSketchFactory->CreateSketch(pOrigin, pH, pV);
% {' r1 D; k1 c: ]5 y# z5 C: ~* a/ T7 G
6 p0 M, G+ ^- c- w& F
sp2DFactory(spSketch);+ E8 x  Y6 M$ q3 B6 O
//下面创建点7 P" M' ]' D% n7 P  {+ z. o" G
CATI2DPoint_var spPt_bottom_left, spPt_bottom_right, spPt_top_right, spPt_top_left;. \$ W4 T7 g: t1 ^" ^1 F
double pt_bottom_left[2] = {10, 10};
9 _% F9 h% B) I  C& i3 g0 xdouble pt_bottom_right[2] = {50, 10};
8 Z. i4 q4 U% B8 o+ h) S& L+ S, edouble pt_top_right[2] = {50, 50};
: b9 C. ^8 g6 u  qdouble pt_top_left[2] = {10, 50};
$ A+ G' k9 U. r- \spPt_bottom_left = sketch2DFactory->CreatePoint(pt_bottom_left);: ~' j& f& |1 m" K; [% `
spPt_bottom_right = sketch2DFactory->CreatePoint(pt_bottom_right);  H$ @7 e0 E$ \" `
spPt_top_right = sketch2DFactory->CreatePoint(pt_top_right);
. x8 s1 w/ Y4 HspPt_top_left = sketch2DFactory->CreatePoint(pt_top_left);
2 u" V" _- k4 w0 i+ m5 I+ H, M# z//开始创建线
  Q6 s; ?1 R+ M9 z: VCATI2DLine_var spLine1, spLine2, spLine3, spLine4;$ K, |; ?8 \! y" V* u
spLine1 = sketch2DFactory->CreateLine(pt_bottom_left,pt_bottom_right);" A) W6 Y7 W, j" F  V
spLine2 = sketch2DFactory->CreateLine(pt_bottom_right,pt_top_right);7 G' w- p5 L7 G& c9 ]- a$ s' l8 ?
spLine3 = sketch2DFactory->CreateLine(pt_top_right,pt_top_left);8 Z  B6 g) H7 m
spLine4 = sketch2DFactory->CreateLine(pt_top_left,pt_bottom_left);- v+ J+ M0 B! H0 c* o0 C5 `8 {' }
//将线的首尾连接起来
. n" t" {% ]4 G0 f7 Z1 M- I2 \# R) I7 B3 c
CATI2DCurve_var spCurve1 (spLine1);: N& a, T+ i: I8 f. P3 t) T
CATI2DCurve_var spCurve2 (spLine2);
1 d- D1 \3 g$ \CATI2DCurve_var spCurve3 (spLine3);/ {* \, V. D0 m% e) z7 @: a" ?0 m
CATI2DCurve_var spCurve4 (spLine4);
/ f( }% X5 X" |* UspCurve1->SetStartPoint(spPt_bottom_left);; J0 Y: M$ W9 Z3 U7 l
spCurve1->SetEndPoint(spPt_bottom_right);3 M! n( c7 d# s' [$ }# P3 F
spCurve2->SetStartPoint(spPt_bottom_right);% q, O+ h0 p0 i, v4 r3 J
spCurve2->SetEndPoint(spPt_top_right);
7 A, V8 o% C: {  _' E- vspCurve3->SetStartPoint(spPt_top_right);
% d! H0 L$ \, t5 G' w& dspCurve3->SetEndPoint(spPt_top_left);; I8 q- n% `, N) N; M1 D( D
spCurve4->SetStartPoint(spPt_top_left);9 l! F8 m4 F2 \+ j! e6 t
spCurve4->SetEndPoint(spPt_bottom_left);
& T! C  u+ L+ X1 X4 J//然后退出草图:! m0 M3 ?5 ?6 G# V0 ^
spSketch->CloseEdition();3 S1 E1 `* f/ ~  I

- H; @; ]5 w5 }+ L6 r* X6 Y7 W& c7 J6 `

4 f3 }# p9 F- }$ w+ _5 V创建草图约束8 g7 M8 f! c9 L+ s5 b% Q) R
CATI2DConstraintFactory_var spConstraint2DFactory(spSketch);8 {; M4 A9 y4 H/ {$ h
//定义spLine1 为水平约束
3 B  J' I" ?/ y& y) CspConstraint2DFactory->CreateConstraint( spLine1, NULL, NULL, NULL, NULL, NULL,9 u+ b8 g/ K( M( r% @  p5 @
NULL, Cst2DType_Horizontal, 0, 0 );8 r' c: L" K" s% s/ n7 O1 m
//定义spLine2 为垂直约束
6 @1 {- E1 v* v1 T' Q0 E9 ospConstraint2DFactory->CreateConstraint( spLine2, NULL, NULL, NULL, NULL, NULL,
1 }) |& M, |, B% C. W5 A5 uNULL, Cst2DType_Vertical, 0, 0 );
3 M4 H8 r! L6 l, s//定义spLine3 为水平约束
! R  [6 B# k. X/ {9 c( H+ r4 n5 FspConstraint2DFactory->CreateConstraint( spLine3, NULL, NULL, NULL, NULL, NULL,
. e6 r. S6 w; k$ A, c' p2 KNULL, Cst2DType_Horizontal, 0, 0 );6 q! G  G$ K4 p  [( [
//定义spLine4 为垂直约束) x) V7 E  I* P9 ^- w; {
spConstraint2DFactory->CreateConstraint( spLine4, NULL, NULL, NULL, NULL, NULL,2 w: }! T4 c! J5 B
NULL, Cst2DType_Vertical, 0, 0 );
# Q# G# r! c4 v, _! }4 d6 c+ L/ o//定义spLine2 的长度约束2 N* x/ f! |% j5 y  y
spConstraint2DFactory->CreateConstraint( spLine2, NULL, NULL, NULL, NULL, NULL,. b# ~5 ^2 l) Q6 R7 R2 P
NULL, Cst2DType_Length, 0, 0 );
. d7 T1 `7 i8 t  q1 S# e0 l4 O( L  `: f% f! a3 d  ], O8 T2 r; L
//定义spLine2 与spLine4 的距离约束" U7 t! h; C' F8 ?3 V
spConstraint2DFactory->CreateConstraint( spLine2, NULL, spLine4, NULL, NULL, NULL,
7 u" T8 W0 `, A" H) c& E5 U' P& E; DNULL, Cst2DType_Distance, 0, 0 );3 ~# C( B8 x: Q! T! M
//定义spPt_bottom_left 与X 轴的距离约束
9 {$ J/ N2 a& y  N" }) T5 ECATI2DAxis_var spSupport = NULL_var;7 h: t% i4 a# M/ u) r6 H
spSketch->GetAbsolute2DAxis(spSupport);
9 m* }4 O8 @  _: G5 WspConstraint2DFactory->CreateConstraint( spPt_bottom_left, NULL,
0 S$ s4 p( p) ZspSupport->GetHDirection(), NULL, NULL, NULL, NULL,Cst2DType_Distance, 0, 0 );
  C7 T' R! |  r# U0 n1 w//定义spPt_bottom_left 与Y 轴的距离约束
+ I4 M. @/ i7 d& Y2 Y& \3 \spConstraint2DFactory->CreateConstraint( spPt_bottom_left, NULL,
- J* }' ~# ^5 g$ T1 f0 z& ]spSupport->GetVDirection(), NULL, NULL, NULL, NULL,Cst2DType_Distance, 0, 0 );
$ P  v# s% h) A4 M3 q! S5 h8 f+ V, ^) r8 x6 \. g
3 J8 \" G1 B: K, k! m/ 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二次开发专题模块培训报名开始啦

    我知道了