PLM之家PLMHome

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

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

  [复制链接]
admin 发表于 2018-2-22 13:25:32 |阅读模式

admin 楼主

2018-2-22 13:25:32

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

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

x
有两种方式可以创建草图:7 |: \5 {. B% r( L2 i, m! Y
1.通过参考平面创建
% f# S4 i' X) r  c9 P4 }. S//获得参考平面
) i8 h- |, [$ S* T1 [# dCATLISTV(CATISpecObject_var) spRefPlanes = spPart->GetReferencePlanes();5 x! {# t; v$ b5 v; _
//初始化草图工厂
9 [- _0 W* Y2 D# WCATISkeTChFactory_var spSketchFactory(spContainer);
7 l0 _9 M8 c& N7 _7 |. ]7 z//在XY plane 上创建草图2 T# n$ ?% a- Y
CATISketch_var spSketch = spSketchFactory->CreateSketch(spRefPlanes[1]));
& k3 o, [6 p/ A$ R. r4 b* s* Q$ c2.通过原点和两个矢量方向
2 x0 J6 ]2 R* q( ]$ P该方法通过定义一个原点和两个方向 pH、pV 进行创建。- M! R& w! y' n. P
定义原点和方向:
( }4 J2 l9 `/ o5 w1 u! @. q( ^double pOrigin[3]={0,0,10};
. {% @) q; h& }% z; w& D0 Rdouble pH[3]={1,0,0};
# z. O7 Y2 Z/ \% hdouble pV[3]={0,1,0};8 j$ T) M7 }2 m$ H/ E( j$ C. m
CATISketchFactory_var spSketchFactory(spContainer);0 m& g; [8 X: Y; O# u5 z
CATISketch_var spSketch = spSketchFactory->CreateSketch(pOrigin, pH, pV);
8 v( d2 k. N; P# M4 P" v) h
1 y+ _; w) W4 R; K3 D! e0 e1 S
8 ~( G; N) O9 f8 p. Dsp2DFactory(spSketch);5 [6 p3 |" k8 v3 f4 v* P0 k6 T. h
//下面创建点+ w/ O2 B* |4 c; ?% s3 I
CATI2DPoint_var spPt_bottom_left, spPt_bottom_right, spPt_top_right, spPt_top_left;+ Y; Y* W* a7 P6 H# X! e
double pt_bottom_left[2] = {10, 10};' e1 i3 {! r* M( ^, [( ^
double pt_bottom_right[2] = {50, 10};. F- F9 p( }1 g1 y/ N. V, H3 Q
double pt_top_right[2] = {50, 50};
8 h, L- N; c8 _2 X/ K" cdouble pt_top_left[2] = {10, 50};
6 z' m2 L/ ^$ Z; l+ ^6 S7 }4 mspPt_bottom_left = sketch2DFactory->CreatePoint(pt_bottom_left);$ \7 p) Q" k- G9 R
spPt_bottom_right = sketch2DFactory->CreatePoint(pt_bottom_right);
* q' l7 Q8 m8 p/ p' _8 }. \& |spPt_top_right = sketch2DFactory->CreatePoint(pt_top_right);8 r- Y6 X! q# ^* C- a9 l# A
spPt_top_left = sketch2DFactory->CreatePoint(pt_top_left);
' _3 i$ s/ ?( [0 a, T% M# q3 d0 p//开始创建线
( y, g" ^- [5 n, r6 u, A5 ~; l6 lCATI2DLine_var spLine1, spLine2, spLine3, spLine4;
( k2 Z6 ]! N$ Z" ^1 U( zspLine1 = sketch2DFactory->CreateLine(pt_bottom_left,pt_bottom_right);/ l% }* s% o! A, U4 v
spLine2 = sketch2DFactory->CreateLine(pt_bottom_right,pt_top_right);
/ O* b, L2 F' nspLine3 = sketch2DFactory->CreateLine(pt_top_right,pt_top_left);
9 f, X% v: s' q7 `- L* W7 DspLine4 = sketch2DFactory->CreateLine(pt_top_left,pt_bottom_left);. X8 [3 q5 j, p6 m6 E/ U
//将线的首尾连接起来, [" \4 d* }+ Q  n, g  F

1 C, o/ I/ o& PCATI2DCurve_var spCurve1 (spLine1);
$ b+ o# C; o- `2 vCATI2DCurve_var spCurve2 (spLine2);5 T# [  c3 \7 o5 {' p% i( r) Z1 L
CATI2DCurve_var spCurve3 (spLine3);
- j8 k; _" F1 S, M5 k& p. PCATI2DCurve_var spCurve4 (spLine4);
" O! X+ g4 e7 `  @- VspCurve1->SetStartPoint(spPt_bottom_left);
0 }5 g2 e2 y; j6 V; h, D# @" {) ZspCurve1->SetEndPoint(spPt_bottom_right);) \3 ^. r# \5 b, O- W3 |0 l
spCurve2->SetStartPoint(spPt_bottom_right);0 x: P  j6 W" n" f% \9 z
spCurve2->SetEndPoint(spPt_top_right);
+ U! |$ L- G" K8 i5 L; O) O* j9 zspCurve3->SetStartPoint(spPt_top_right);
. M; b0 O7 j: H/ UspCurve3->SetEndPoint(spPt_top_left);6 X' _0 F! ]% g2 H
spCurve4->SetStartPoint(spPt_top_left);
& {$ |# I' l5 h0 u1 d, espCurve4->SetEndPoint(spPt_bottom_left);! T( Q& x2 s* g# m- \
//然后退出草图:
1 a# T; D5 b2 `spSketch->CloseEdition();
( g, b+ P, S8 L3 F4 L, ~
( x& _9 j" w' q& t1 y% Z
9 b8 g, }: J5 j0 S3 R" ]
2 B' V4 x: t, g6 ?. [创建草图约束
8 r- V% k" L; r' Z+ p; oCATI2DConstraintFactory_var spConstraint2DFactory(spSketch);/ e, S+ H; r; R4 [, Q, \$ v
//定义spLine1 为水平约束
1 Z' |- P4 P1 S; D9 G. `; C7 c+ aspConstraint2DFactory->CreateConstraint( spLine1, NULL, NULL, NULL, NULL, NULL,
: ~: C3 @( T! ^/ x" jNULL, Cst2DType_Horizontal, 0, 0 );
" H3 V! _; h+ N4 b8 q/ Z  s//定义spLine2 为垂直约束( e% U, L7 E0 k2 C' x
spConstraint2DFactory->CreateConstraint( spLine2, NULL, NULL, NULL, NULL, NULL,1 S( C$ g1 B8 A4 l3 t
NULL, Cst2DType_Vertical, 0, 0 );
  J5 |6 l- j+ g7 O( p& V5 J//定义spLine3 为水平约束* j# @) N2 y; N3 k' U
spConstraint2DFactory->CreateConstraint( spLine3, NULL, NULL, NULL, NULL, NULL,
* r' G. H: [$ O; \; J2 YNULL, Cst2DType_Horizontal, 0, 0 );
9 P& @$ U' Q3 a* m6 @//定义spLine4 为垂直约束
, @$ }" b, P) R/ z7 B( g$ [) xspConstraint2DFactory->CreateConstraint( spLine4, NULL, NULL, NULL, NULL, NULL,
" p+ i6 `" R; t$ KNULL, Cst2DType_Vertical, 0, 0 );
# z" T- M! U( ]0 C0 H% x//定义spLine2 的长度约束( H2 A# q- m, S* E3 |* E) {
spConstraint2DFactory->CreateConstraint( spLine2, NULL, NULL, NULL, NULL, NULL,
+ U, D! y6 {4 R7 G: xNULL, Cst2DType_Length, 0, 0 );* q; U; ^7 X' b0 S8 |  E) l

& k1 X8 h$ c( {. d. V6 Y9 ~//定义spLine2 与spLine4 的距离约束# X: M% B: S+ \# P$ [- K
spConstraint2DFactory->CreateConstraint( spLine2, NULL, spLine4, NULL, NULL, NULL,5 x8 v6 H3 i9 B0 ?
NULL, Cst2DType_Distance, 0, 0 );/ J( n5 Q. P& R7 _& U% k
//定义spPt_bottom_left 与X 轴的距离约束
- c: p" ^( R* A: |! E7 aCATI2DAxis_var spSupport = NULL_var;
' y. o+ k7 P2 E. e( |5 m* x0 LspSketch->GetAbsolute2DAxis(spSupport);' w# k0 s; y' |! t) d' h
spConstraint2DFactory->CreateConstraint( spPt_bottom_left, NULL,- _/ ~$ v/ S. i
spSupport->GetHDirection(), NULL, NULL, NULL, NULL,Cst2DType_Distance, 0, 0 );. L3 N, r, I( b: T
//定义spPt_bottom_left 与Y 轴的距离约束
& l% [. i+ d: i8 E5 FspConstraint2DFactory->CreateConstraint( spPt_bottom_left, NULL,5 _6 H1 z, O! z! ?; o5 j
spSupport->GetVDirection(), NULL, NULL, NULL, NULL,Cst2DType_Distance, 0, 0 );
! {( V) m# h/ ^3 x$ F1 _
, S3 M/ Y+ @6 G, D+ Y* v8 I- U: t6 b' S+ g* Y# T
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

关闭

站长推荐上一条 /1 下一条

  • 发布新帖
  • 在线客服1
  • 在线客服2
  • 微信
  • 客户端
  • 返回顶部
  • x
    火热推荐

    PLM之家(plmhome.com)提供专业的实施开发培训

    NX二次开发基础培训 | 已 80 学员 参加

    NX二次开发高级培训 | 最高性价比

    CAA二次开发 | 值的一试

    Teamcenter用户基础入门 | 虚拟机赠送

    限时优惠,原价3000,现价888

    哥已知晓