|
分享在他網的回題小程式,適合想學sw API的初學者參考! # u. z* x& P) W9 U. I
- ' ******************************************************************************
4 q+ a: ~5 F% m
- ' macro recorded on 05/12/18 by scliang5 J' H+ v3 s# W2 }
- ' 功能:草圖圓周複製後拉伸; N/ }8 G* K" |2 s& ?
- ' 操作: 開新零件,執行 main
! b& ]6 u- [, ?& y7 _) i b
- '9 j. s7 o5 U( M" g
- ' ******************************************************************************" J( w* M% t; _& f; f4 Q) k( _
- Option Explicit$ t* ~- D0 T0 Z
6 Q+ M" Y/ X f M+ `
- Dim swApp As SldWorks.SldWorks
6 D0 c% C$ x) I- n a M
- Dim swModel As SldWorks.ModelDoc26 c" a0 T' c$ |9 r% ?1 c
- Dim swSketchMgr As SldWorks.SketchManager
, Z* `2 f# M! E& s/ u. V% e& z C
- Dim swSketchSegment As SldWorks.SketchSegment
0 \7 a8 t" G; u: ^3 A: S0 I/ P. t1 g4 @, A
- Dim boolstatus As Boolean9 J6 H: {( _6 S% ^. E5 z
- Dim Part As Object: r* @$ c3 T% q5 Y5 z
- Dim myFeature As Object
8 R" n) }/ B& w: m6 N' I/ \
- Dim pi, ArcRadius, ArcAngle, PatternSpacing As Double
3 I9 n; q8 r) A4 f0 ~
- Dim n As Integer
. w% u3 @/ n& ^$ {* ^
- # f" B( q$ H( e. t6 S
- Sub main()% n$ B) B/ E. r6 M6 c# Z+ ]6 O5 R6 |" j
- * o6 e& I* r$ s2 q) k, _
- Set swApp = Application.SldWorks
1 Z$ ^2 M$ g7 `
- Set Part = swApp.ActiveDoc
# y: q# N7 ~0 c. ?. x8 k; h
- ' Create part document3 I( H. g7 V* n) ?2 g! b
- Set swModel = swApp.ActiveDoc- J! ?% p4 @% R3 P! b9 X3 m
- Set swSketchMgr = swModel.SketchManager
! q5 Y( Q/ l- U6 K* o; ^
- pi = Atn(1) * 4 '圓周率# Q. v8 j2 `$ Q" H8 _7 ~' w! z
- ArcRadius = 0.05 '圓弧半徑3 e; s; o/ c: |7 @
- ArcAngle = 300 * pi / 180 '圓周中心之圓弧角
0 D/ j) T* O0 N4 l3 M
- n = 5 '複製數
( r, O. j; C( d f+ t! q
- PatternSpacing = 40 * pi / 180 '複製之間隔弧度
# Q5 U8 ]' g2 H' C8 \4 n
- ' Sketch a circle
# h0 O4 a9 x, m1 Y U# H
- 'boolstatus = Part.Extension.SelectByID2("前基準面", "PLANE", 0, 0, 0, False, 0, Nothing, 0). n+ q+ p {) f7 r( S- [3 B3 Y
- swModel.ShowNamedView2 "*Front", 1
' z- k, o% Y; x7 f5 t
- Set swSketchSegment = swSketchMgr.CreateCircle(0.01, 0.06, 0#, 0.01, 0.07, 0#) '畫圓3 n8 C5 o. q# r; U$ [$ D2 l
- 'value = instance.CreateCircularSketchStepAndRepeat(ArcRadius, ArcAngle, PatternNum, PatternSpacing, PatternRotate, _
/ @) U7 s# |/ N) l9 K
- DeleteInstances)圓弧半徑、圓弧角、複製數、複製間距(+ 間隔弧度正轉,- 間隔弧度逆轉)、圖案旋轉、刪除實例4 r: o+ g& Z* m3 T
- boolstatus = swSketchMgr.CreateCircularSketchStepAndRepeat(ArcRadius, ArcAngle, n, PatternSpacing, False, True, True, True, True) '圓周複製
2 B8 a7 k! J5 _1 E
- 'instance.FeatureExtrusion2(Sd, Flip, Dir(反轉方向), T1, T2, D1, D2, Dchk1, Dchk2, Ddir1, Ddir2, Dang1, Dang2, OffsetReverse1, OffsetReverse2, Merge)
6 ]& a' m6 J/ N" _% p0 k
- Set myFeature = Part.FeatureManager.FeatureExtrusion2(True, False, False, 0, 0, 0.03, 0, False, False, False, False, _
! ~1 t6 u' Z: T* n, j' J
- 0, 0, False, False, False, False, True, True, True, 0, 0, False) '拉伸 30mm& L }" q) \( A) N+ L9 O
! K3 ?1 ^ a2 R ~4 |
- End Sub& V$ H1 Q/ ]+ G+ z
复制代码
2 z8 n8 C5 `$ A5 }# L% s' y ! _, z' {$ u: r& Y; s2 e( N4 P2 n 1 j/ n) W7 i, R3 p0 K 3 J# m3 W7 ]; ^2 |5 i5 Y8 e" E u0 J% R# h% T+ [ - A: Q$ y3 O7 `/ i
|
本帖子中包含更多资源
您需要登录才可以下载或查看,没有帐号?注册会员
x
评分
-
查看全部评分
|