|
经典图书 學VBA宏的基本教材
' ******************************************************************************
' macro recorded on 05/26/13 by scliang
'
' 操作說明
'
' 1. 開SW檔,選前基準面(右或上皆可),進入草圖編輯,執行本程式.
' 2. 在 Option tips 對話表按 "Yes" 鍵,作"滿天星",在 X座標-50,Y座標-50到X座標50,Y座標50 ,之範圍內隨機作畫鍵入數量的 "點".
' 3. 在 Option tips 對話表按 "No" 鍵,作畫太極圖.
'
' ******************************************************************************
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Dim skPoint As Object
pi = 3.141592654
continue:
boolstatus = Part.Extension.SketchBoxSelect("-0.06", "-0.06", "0.000000", "0.06", "0.06", "0.000000") '
Part.EditDelete
c = MsgBox("Yes-->The stars in the sky,No-->Tai Chi picture", vbYesNoCancel, "Option tipe") '選擇"滿天星"或是"太極圖"
Select Case c
Case 6
point_number = InputBox("Key in the number", "Key in the number of tips", 100) '鍵入作圖點的數量
For i = 1 To point_number
X = Int((Rnd() * 50 + 1) - (Rnd() * 50 + 1)) / 1000
Y = Int((Rnd() * 50 + 1) - (Rnd() * 50 + 1)) / 1000
Set skPoint = Part.SketchManager.CreatePoint(X, Y, 0#) '點作圖
Next
Case 7
For j = 0 To 360 Step 2
X = (j / 6 - 30) / 1000
Y = 12 * Sin(j * pi / 180) / 1000
Set skPoint = Part.SketchManager.CreatePoint(X, Y, 0#)
X = 30 * Cos(j * pi / 180) / 1000
Y = 30 * Sin(j * pi / 180) / 1000
Set skPoint = Part.SketchManager.CreatePoint(X, Y, 0#)
Next j
End Select
Msg = "Do you want to continue ?" ' 定義訊息。
Style = vbYesNo ' 定義按鈕。
Title = "MsgBox Demonstration" ' 定義標題。
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then GoTo continue ' 若使用者按下 [是],就繼續執行。
End Sub
Point.rar
(9.81 KB, 下载次数: 82)
[2012版]VBA宏 |
|