ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
XZXiaodong Zhang06/02/2015

Hi,

I am pretty new to Solidworks API. I recorded a macro program using macro tools while I was creating an extruded boss. I used smart dimensions in the sketch steps. When I run the API program, it gave me the run-time error 91. Can any one help me solve this problem? Any suggestion is appreciated. Here is the automatically created code in macro:

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

boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", -8.52419389497072E-03, 0.12320010397201, 9.98222865168827E-02, False, 0, Nothing, 0)

Part.SketchManager.InsertSketch True

Part.ClearSelection2 True

Dim vSkLines As Variant

vSkLines = Part.SketchManager.CreateCenterRectangle(2.30630980853676E-02, 0.01630633106817, 0, 3.11712185060046E-02, 8.37839110132493E-03, 0)

Part.ClearSelection2 True

boolstatus = Part.Extension.SelectByID2("Point1", "SKETCHPOINT", 2.30630980853676E-02, 0.01630633106817, 0, False, 0, Nothing, 0)

boolstatus = Part.Extension.SelectByID2("Point1@Origin", "EXTSKETCHPOINT", 0, 0, 0, True, 0, Nothing, 0)

Dim myDisplayDim As Object

Set myDisplayDim = Part.AddDimension2(2.66667071612062E-02, -1.19820001771636E-02, 0)

Part.ClearSelection2 True

Dim myDimension As Object

Set myDimension = Part.Parameter("D1@Sketch1")

myDimension.SystemValue = 0.01802775637732

boolstatus = Part.Extension.SelectByID2("Line1", "SKETCHSEGMENT", 1.54101314312007E-02, 1.53526309407857E-02, 0, False, 0, Nothing, 0)

Set myDisplayDim = Part.AddDimension2(1.46051245653917E-02, 1.96076672314904E-02, 0)

boolstatus = Part.Extension.SelectByID2("D1@Sketch1@Part11.SLDPRT", "DIMENSION", 0, 0, 0, False, 0, Nothing, 0)

Part.ClearSelection2 True

Set myDimension = Part.Parameter("D2@Sketch1")

myDimension.SystemValue = 0.01

boolstatus = Part.Extension.SelectByID2("Line4", "SKETCHSEGMENT", 2.02401726260546E-02, 1.19026015158901E-02, 0, False, 0, Nothing, 0)

Set myDisplayDim = Part.AddDimension2(2.57602197058877E-02, 1.07525917075915E-02, 0)

boolstatus = Part.Extension.SelectByID2("D2@Sketch1@Part11.SLDPRT", "DIMENSION", 0, 0, 0, False, 0, Nothing, 0)

Part.ClearSelection2 True

Set myDimension = Part.Parameter("D3@Sketch1")

myDimension.SystemValue = 0.01

Part.ClearSelection2 True

Part.SketchManager.InsertSketch True

Part.ShowNamedView2 "*Trimetric", 8

Part.SketchManager.InsertSketch True

Part.ClearSelection2 True

boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False, 4, Nothing, 0)

Dim myFeature As Object

Set myFeature = Part.FeatureManager.FeatureExtrusion2(True, False, False, 6, 0, 0.01, 0.01, False, False, False, False, 1.74532925199433E-02, 1.74532925199433E-02, False, False, False, False, True, True, True, 0, 0, False)

Part.SelectionManager.EnableContourSelection = False

End Sub