|
分享在他網的回題小程式,適合想學sw API的初學者參考!3 ^" G+ |% x+ i
- ' ******************************************************************************
E3 x, F" k" R6 m5 t - ' macro recorded on 05/12/18 by scliang3 `( h+ F! p+ n" d
- ' 功能:草圖圓周複製後拉伸+ N0 l9 X3 ^& ?, p3 Y6 m
- ' 操作: 開新零件,執行 main# y* u. n2 j4 ]
- '
0 Y3 T& c6 z$ B/ a& r* n! I - ' ******************************************************************************8 u& b {' Y1 `7 o* T
- Option Explicit
9 t0 M" I$ o% e5 N9 e3 y. a
) }2 x" ^3 f- z- Dim swApp As SldWorks.SldWorks
% } B2 A7 o- d - Dim swModel As SldWorks.ModelDoc2# [; L6 n; d7 _0 W9 X
- Dim swSketchMgr As SldWorks.SketchManager
, {* G2 v7 @# j" j6 Z* l6 z - Dim swSketchSegment As SldWorks.SketchSegment
4 l# c: t5 S! `+ q B - Dim boolstatus As Boolean% D+ W! V/ v: ?
- Dim Part As Object* @% r/ g4 t( P8 i6 Y
- Dim myFeature As Object
- u( G8 ^: E" X - Dim pi, ArcRadius, ArcAngle, PatternSpacing As Double
3 T' w m7 Y9 e - Dim n As Integer
3 }- \8 o* ?! k7 A6 | - & q9 d: U: Z m1 w1 I6 n# J
- Sub main()# \ y% c' g% I) i% u/ O! w% ^4 B
5 S* A: H6 A: f! N: X- Set swApp = Application.SldWorks1 E c" {# K5 t. x
- Set Part = swApp.ActiveDoc
& k6 ?* w T7 B9 m - ' Create part document) U9 W0 O8 Y3 C0 _
- Set swModel = swApp.ActiveDoc, q* r. q6 N# N# T: r9 H7 }
- Set swSketchMgr = swModel.SketchManager
8 ]& G. n y- x R - pi = Atn(1) * 4 '圓周率9 _8 @3 D5 h6 h3 I, y
- ArcRadius = 0.05 '圓弧半徑
" w, ^/ }2 d; ]% r2 F! S - ArcAngle = 300 * pi / 180 '圓周中心之圓弧角* ~/ r! W% w9 R B
- n = 5 '複製數
/ ]6 J& a6 F- G! D* T$ {( p - PatternSpacing = 40 * pi / 180 '複製之間隔弧度
3 ~+ c3 J% @0 d; h8 ~, Y. C) C% ] - ' Sketch a circle$ M$ _& w3 w# ^7 D8 b
- 'boolstatus = Part.Extension.SelectByID2("前基準面", "PLANE", 0, 0, 0, False, 0, Nothing, 0)9 O$ ^7 j1 f4 D* S/ n4 I* N" M
- swModel.ShowNamedView2 "*Front", 17 A3 q( ]+ B( W, R* b7 m9 A3 L
- Set swSketchSegment = swSketchMgr.CreateCircle(0.01, 0.06, 0#, 0.01, 0.07, 0#) '畫圓, g+ l* Y4 e0 T% ]" q" C
- 'value = instance.CreateCircularSketchStepAndRepeat(ArcRadius, ArcAngle, PatternNum, PatternSpacing, PatternRotate, _8 {3 `4 w: s4 \* i
- DeleteInstances)圓弧半徑、圓弧角、複製數、複製間距(+ 間隔弧度正轉,- 間隔弧度逆轉)、圖案旋轉、刪除實例5 g' R3 z q$ S
- boolstatus = swSketchMgr.CreateCircularSketchStepAndRepeat(ArcRadius, ArcAngle, n, PatternSpacing, False, True, True, True, True) '圓周複製8 g! u O, B1 g. W' k& [8 G
- 'instance.FeatureExtrusion2(Sd, Flip, Dir(反轉方向), T1, T2, D1, D2, Dchk1, Dchk2, Ddir1, Ddir2, Dang1, Dang2, OffsetReverse1, OffsetReverse2, Merge)
6 D8 ]- ~3 m+ b" ^ - Set myFeature = Part.FeatureManager.FeatureExtrusion2(True, False, False, 0, 0, 0.03, 0, False, False, False, False, _2 j! z" W! E0 K7 o
- 0, 0, False, False, False, False, True, True, True, 0, 0, False) '拉伸 30mm9 b0 O6 [, B3 n
, `/ a+ Y; i" @+ K1 q- End Sub
- q6 C6 C2 I- U! b: T4 i7 J
复制代码 ; r9 C, Y5 V" d1 e) D. F0 U
$ y8 y* ]* W N3 q8 M( {
I% \' f3 N& o" @$ X1 z
% ^8 I# F: }+ Y' s. v% _$ ~" ?
) d9 X# [1 c+ Z( m7 ]4 T
: Z/ `: N u! y2 E1 T |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
评分
-
查看全部评分
|