|
分享在他網的回題小程式,適合想學sw API的初學者參考!
9 s( H- K: p. u" |" q- ' ******************************************************************************* H: e F5 ^, {4 x
- ' macro recorded on 05/12/18 by scliang( k: l8 T% F+ Q4 u* I' U# l% J0 H
- ' 功能:草圖圓周複製後拉伸
2 ^# I& o: r" q - ' 操作: 開新零件,執行 main; `0 d% [3 ]3 x1 b2 x
- '1 f$ P1 v. D( C7 ]5 K
- ' ******************************************************************************
! ?* C4 t" L3 J( Y - Option Explicit! O$ y. d* E8 M$ Y. w
- 6 p/ s" d, D9 s3 o$ S7 [
- Dim swApp As SldWorks.SldWorks+ x# e+ c0 L' j. V
- Dim swModel As SldWorks.ModelDoc2
* {* T/ z, L3 t, r- B: q# ^! t$ x - Dim swSketchMgr As SldWorks.SketchManager
5 U; P; g& w; j, y% x - Dim swSketchSegment As SldWorks.SketchSegment
! t# A9 m& Q: I: f' | - Dim boolstatus As Boolean
0 z- F% G9 h) c, c3 [! M% K - Dim Part As Object) b( f, Q1 u7 ^
- Dim myFeature As Object5 h# K2 |. d! x5 s0 N' Y
- Dim pi, ArcRadius, ArcAngle, PatternSpacing As Double
/ r- Y- n' _! b - Dim n As Integer
# Z$ I q6 U- I8 P) f
7 j7 x8 ~/ h5 ]$ N1 P4 h: W- Sub main()
6 ]5 ]9 B; N& {$ q2 K- E3 J - 2 U' L0 C3 `9 I- Z5 \
- Set swApp = Application.SldWorks
! h2 h5 T! Y6 {$ p; u1 A - Set Part = swApp.ActiveDoc
) V8 k- s1 g+ r/ v) y+ O# i5 j - ' Create part document
6 y0 v7 _4 @2 c' v- M3 {0 Z ` - Set swModel = swApp.ActiveDoc
' k$ N* S ]3 ?3 L: P& j - Set swSketchMgr = swModel.SketchManager" D" f. e1 Z2 B4 ~( L
- pi = Atn(1) * 4 '圓周率
% s8 Z0 r- ?) C7 ?0 O& f0 Z - ArcRadius = 0.05 '圓弧半徑1 K0 s/ e3 `1 h) |: L" s1 w
- ArcAngle = 300 * pi / 180 '圓周中心之圓弧角
5 v% m0 \3 |4 n0 P( q - n = 5 '複製數$ @; L3 F% s2 q" q- Q( ^
- PatternSpacing = 40 * pi / 180 '複製之間隔弧度
4 E) j' U9 R" ?$ P; N* ?$ G, Q - ' Sketch a circle
& w' y0 }0 a0 p$ k - 'boolstatus = Part.Extension.SelectByID2("前基準面", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
$ B" k/ q1 n/ f# c - swModel.ShowNamedView2 "*Front", 1
, C: S0 j) q4 e/ v - Set swSketchSegment = swSketchMgr.CreateCircle(0.01, 0.06, 0#, 0.01, 0.07, 0#) '畫圓* P7 w$ a9 t, b. `+ N- d- q
- 'value = instance.CreateCircularSketchStepAndRepeat(ArcRadius, ArcAngle, PatternNum, PatternSpacing, PatternRotate, _
& @ [: j g5 L$ } - DeleteInstances)圓弧半徑、圓弧角、複製數、複製間距(+ 間隔弧度正轉,- 間隔弧度逆轉)、圖案旋轉、刪除實例
" d* W3 v) ^0 M4 b* p - boolstatus = swSketchMgr.CreateCircularSketchStepAndRepeat(ArcRadius, ArcAngle, n, PatternSpacing, False, True, True, True, True) '圓周複製
B4 ~6 m/ H: l# _3 T - 'instance.FeatureExtrusion2(Sd, Flip, Dir(反轉方向), T1, T2, D1, D2, Dchk1, Dchk2, Ddir1, Ddir2, Dang1, Dang2, OffsetReverse1, OffsetReverse2, Merge)
- A2 B, p# X+ {! K `( V - Set myFeature = Part.FeatureManager.FeatureExtrusion2(True, False, False, 0, 0, 0.03, 0, False, False, False, False, _9 v: P3 ?. O6 z
- 0, 0, False, False, False, False, True, True, True, 0, 0, False) '拉伸 30mm
$ ] i |6 U$ M, M" g" F0 Q$ \ - # T4 J: B' y6 P" X& T" j
- End Sub
( C) h v' v$ C2 I
复制代码
( g* F* h* e# ]( B: U
% H8 P& |9 w# n, O1 B, C, z0 X( M
' _ ^( y5 r/ [$ t
1 \% U: Y' ]/ p* X B0 o/ H6 N6 r. N- q) D# u8 w
5 w! B0 G1 P7 \( J$ q# g1 Q. N |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
评分
-
查看全部评分
|