21, Feb, 2019

Create a cube in Solidworks VBA – Solidworks Automation

solidworks automation

The code for creating a simple cube in Solidworks with VBA (macros)

Edit X and Y and Z values for customization

Private Sub CommandButton1_Click()

Dim swApp As Object

Dim Part As Object

Dim boolstatus As Boolean

Dim longstatus As Long, longwarnings As Long

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc

Dim myModelView As Object

Set myModelView = Part.ActiveView

myModelView.FrameState = swWindowState_e.swWindowMaximized

boolstatus = Part.Extension.SelectByID2(“Front Plane”, “PLANE”, 0, 0, 0, False, 0, Nothing, 0)

Part.SketchManager.InsertSketch True

Part.ClearSelection2 True

Dim vSkLines As Variant

vSkLines = Part.SketchManager.CreateCenterRectangle(0, 0, 0, 0.05761373872934, -0.04818230819002, 0)

Part.ClearSelection2 True

Part.SketchManager.InsertSketch True

Part.ShowNamedView2 “*Trimetric”, 8

Part.ClearSelection2 True

boolstatus = Part.Extension.SelectByID2(“Sketch1”, “SKETCH”, 0, 0, 0, False, 0, Nothing, 0)

Dim myFeature As Object

Set myFeature = Part.FeatureManager.FeatureExtrusion2(True, False, False, 0, 0, 0.1, 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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>