動作を確認する
- 詳細
- カテゴリ: マクロの編集(基礎)
- 参照数: 12610
では、編集したマクロの動作確認をしてみます。
完成したコードは以下のような状態です。
' ******************************************************************************
' D:\TEMP\swx0000\Macro1.swb - macro recorded on 00/00/00 by webmaster
' ******************************************************************************
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub main()
Dim swWidth, swHeight, swDepth As Double
Do Until swWidth > 0
sInput = InputBox("幅を入力して下さい。")
If sInput = "" Then
Exit Sub
End If
swWidth = Val(sInput)
If swWidth > 0 And swWidth <= 500000 Then
swWidth = swWidth / 1000
Else
MsgBox "0を超える500000までの数値を入力して下さい。"
End If
Loop
Do Until swHeight > 0
sInput = InputBox("高さを入力して下さい。")
If sInput = "" Then
Exit Sub
End If
swHeight = Val(sInput)
If swHeight > 0 And swHeight <= 500000 Then
swHeight = swHeight / 1000
Else
MsgBox "0を超える500000までの数値を入力して下さい。"
End If
Loop
Do Until swDepth > 0
sInput = InputBox("奥行きを入力して下さい。")
If sInput = "" Then
Exit Sub
End If
swDepth = Val(sInput)
If swDepth > 0 And swDepth <= 500000 Then
swDepth = swDepth / 1000
Else
MsgBox "0を超える500000までの数値を入力して下さい。"
End If
Loop
Set swApp = _
Application.SldWorks
Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2("正面", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
Part.SketchManager.InsertSketch True
Part.ClearSelection2 True
Dim vSkLines As Variant
vSkLines = Part.SketchManager.CreateCornerRectangle(0, 0, 0, swWidth, swHeight, 0)
Part.ClearSelection2 True
Part.SketchManager.InsertSketch True
Part.ShowNamedView2 "*不等角投影", 8
Part.SketchManager.InsertSketch True
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("スケッチ1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
Dim myFeature As Object
Set myFeature = Part.FeatureManager.FeatureExtrusion2(True, False, False, 0, 0, swDepth, 0.01, _
False, False, False, False, 0.01745329251994, 0.01745329251994, False, False, False, False, _
True, True, True, 0, 0, False)
Part.SelectionManager.EnableContourSelection = False
End Sub
早速、[ツール]→[マクロ]→[実行]から、編集したマクロを実行してみて下さい。
InputBoxダイアログが幅・高さ・奥行きの入力を促されますので、適宜入力すれば入力した寸法の押し出しが作成されます。


以上で、マクロの編集は完了です。お疲れ様でした