Solidworks VBA Axlestand automation

494 views Asked by At

For a project I need to automate the designing of an Axlestand.

For this I want to make the length and diameter of one part variable. Now I found out how to make the diameter variable, as this is just a value in the sketch, but I can't seem to get it to work to automate the extrusion depth (which is the length of the part).

So my question is;

How can I make the length of this part variable? The length is equal to the extrusion depth.

The code which I used to make the diameter variable is this :

Set swApp = _
Application.SldWorks
Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2("Driepoot-1@Assem1", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
Part.EditPart
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Sketch1@Driepoot-1@Assem1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
Part.EditSketch
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Arc1", "SKETCHSEGMENT", 2.74859513030536E-02, -3.06463363579324E-02, 6.16380172114107E-02, False, 0, Nothing, 0)
Set myDisplayDim = Part.AddDimension2(5.72509941423576E-02, 0, -5.63921816082802E-03)
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("D1@Sketch1@Driepoot-1@Assem1", "DIMENSION", 0.051312269187431, -3.32967190067487E-02, 5.26236966313736E-02, False, 0, Nothing, 0)
Set myDimension = Part.Parameter("D1@[email protected]")
myDimension.SystemValue = <Insert Diameter here>
Part.ClearSelection2 True
Part.SketchManager.InsertSketch True
Part.EditAssembly

Hope someone can answer my question! :)

Tim

1

There are 1 answers

0
Andrey.Dankevich On BEST ANSWER

Extrusion depth is a dimension. Usually, named as "dimension_name@feature_name", e.g. "D1@Boss-Extrude1". So you can change the value as in your example:

Dim myDimension As Object
Set myDimension = Part.Parameter("D1@Boss-Extrude1")
myDimension.SystemValue = val
boolstatus = Part.EditRebuild3()

UPD Changed formatting.