|
分享在他網的回題小程式,適合想學sw API的初學者參考!
+ u, W! @0 R. c t1 {! W/ N- ' ******************************************************************************
! G3 ?, l5 K; B' w. v. u' V - ' macro recorded on 05/12/18 by scliang
! \5 e5 v( c e/ H* V2 B9 q - ' 功能:草圖圓周複製後拉伸0 K6 o# j, S+ ~! Y/ ]
- ' 操作: 開新零件,執行 main
( T: B: L5 C: q9 u; E - ', Z9 W/ |' ?, Q
- ' ******************************************************************************" L* g3 b$ g9 n' P+ `% w6 ]
- Option Explicit
* m+ T, P: |% x" N- u7 ^ - 1 ~6 s7 V6 h; Z* a, K0 v
- Dim swApp As SldWorks.SldWorks' d: f( w' i2 q v, W
- Dim swModel As SldWorks.ModelDoc2
7 Z' O( Q3 @+ Z$ ?1 S+ o: Y& C - Dim swSketchMgr As SldWorks.SketchManager
+ S( o* t1 T. S1 t - Dim swSketchSegment As SldWorks.SketchSegment3 w, `- @8 d* D# q4 `" ~
- Dim boolstatus As Boolean. y. j0 G% z6 |1 q
- Dim Part As Object* _) q( ^2 W( i" x5 f
- Dim myFeature As Object% L' p; F" j S; _
- Dim pi, ArcRadius, ArcAngle, PatternSpacing As Double
5 ?$ c" x& H" S: o# ? - Dim n As Integer3 I5 D6 \4 p+ U8 G8 G% E
- # V; \% B: B" i
- Sub main()
3 `$ M5 N; }+ `2 O: b2 ] - 7 n# l- Y+ g( P6 A$ a# {4 c
- Set swApp = Application.SldWorks
4 N H2 M3 k% H - Set Part = swApp.ActiveDoc
1 K, K1 U, R. X D$ N6 {4 ~+ ^0 M7 e - ' Create part document( I( S( w5 v# T6 S$ Z9 w* }
- Set swModel = swApp.ActiveDoc
2 _0 Z: L" b1 n* I9 } - Set swSketchMgr = swModel.SketchManager; I3 L- s/ n+ ^- l( X! y, h
- pi = Atn(1) * 4 '圓周率0 f- z d4 N7 f2 \$ p8 \
- ArcRadius = 0.05 '圓弧半徑% ^) B5 V& I4 V: f" L( K3 t
- ArcAngle = 300 * pi / 180 '圓周中心之圓弧角
! P. s4 p! N' R$ ^" s# m - n = 5 '複製數% M8 `4 {. w. H% X% E9 m( U! w1 m8 n
- PatternSpacing = 40 * pi / 180 '複製之間隔弧度
0 q. m( Z& v( S1 N* [( o; M4 P% | - ' Sketch a circle
( i# I) P0 N3 T - 'boolstatus = Part.Extension.SelectByID2("前基準面", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
) z" B; Z$ \7 Y - swModel.ShowNamedView2 "*Front", 1
- f- b, U& R/ q& u - Set swSketchSegment = swSketchMgr.CreateCircle(0.01, 0.06, 0#, 0.01, 0.07, 0#) '畫圓
4 Y1 h5 L* z- l6 d* Z! U6 `( G - 'value = instance.CreateCircularSketchStepAndRepeat(ArcRadius, ArcAngle, PatternNum, PatternSpacing, PatternRotate, _$ {/ I& |4 { `, A5 K9 g
- DeleteInstances)圓弧半徑、圓弧角、複製數、複製間距(+ 間隔弧度正轉,- 間隔弧度逆轉)、圖案旋轉、刪除實例
M6 S; d2 B$ ?. D7 x# ~( ^! i - boolstatus = swSketchMgr.CreateCircularSketchStepAndRepeat(ArcRadius, ArcAngle, n, PatternSpacing, False, True, True, True, True) '圓周複製
/ \. R0 g3 v( M+ ~ - 'instance.FeatureExtrusion2(Sd, Flip, Dir(反轉方向), T1, T2, D1, D2, Dchk1, Dchk2, Ddir1, Ddir2, Dang1, Dang2, OffsetReverse1, OffsetReverse2, Merge)
) o/ f1 |- v+ j. Y% P - Set myFeature = Part.FeatureManager.FeatureExtrusion2(True, False, False, 0, 0, 0.03, 0, False, False, False, False, _
' M! Z/ z8 @; [% H3 L: ? - 0, 0, False, False, False, False, True, True, True, 0, 0, False) '拉伸 30mm0 N( J4 ~6 J$ p& \
0 B+ H, ~ D) {# v- V- End Sub
) ~* i+ b; O8 y8 T! Y
复制代码 . `- \& \: K) k$ G
3 q. b& H, G; G8 u: ^
% K. J7 w( b' B2 J: t7 y( T! z
) r) I8 C w, W) K. p4 t# B# e; N
- d3 e: A/ x* i4 e# L K% |) [
7 O$ D8 J4 E9 P( \9 p# ~" u# ~) g |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
评分
-
查看全部评分
|