ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
CSCoen Sleiderink08/01/2013

Hello,

I'm a student who is trying to write some code using macro's for an assignment. But i'm stuck with this run-time error 91. I've tryed a lot of things but none seem te solve the problem.

Below you can see a part of te code i wrote. And where i get the error. The bold line of code is where the error occurs. It is highlighted yellow on my screen.

Option Explicit

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim part As Object

Dim swFeatMgr As SldWorks.FeatureManager

Private Sub cmdBuild_Click()

    Set swApp = Application.SldWorks

    Set swModel = swApp.NewPart

    swModel.SetAddToDB True

    swModel.SetUserPreferenceIntegerValue swUnitsLinear, swMM

    'MATERIAAL

    If chkSteel.Value = True Then

        swModel.SetUserPreferenceDoubleValue SwConst.swMaterialPropertyDensity, 7800

        swModel.SetUserPreferenceStringValue SwConst.swMaterialPropertyCrosshatchPattern, "ISO (Steel)"

    End If

    'PROFIEL

If optExtrude.Value = True Then

    txtAngle.Enabled = False

    txtRadius.Enabled = False

    Dim varHeight As Double

    Dim varWidth As Double

    varHeight = CDbl(txtHeight.Text) / 1000

    varWidth = CDbl(txtWidth.Text) / 1000

    Set part = swApp.ActiveDoc

    part.SketchManager.InsertSketch True

    Dim skSegment As Object

    Set skSegment = part.SketchManager.CreateLine(0#, 0.045159, 0#, 0#, 0#, 0#)

    Set skSegment = part.SketchManager.CreateLine(0#, 0#, 0#, 0.044261, 0#, 0#)

    part.SetPickMode

    Dim myDisplayDim As Object

    Set myDisplayDim = part.AddDimension2(-0.02183164339539, 2.33269614361702E-02, 0)

    Dim myDimension As Object

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

    myDimension.SystemValue = varHeight / 1000

    Set myDisplayDim = part.AddDimension2(2.21307070035461E-02, -1.76447528812057E-02, 0)

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

    myDimension.SystemValue = varWidth / 1000

    part.SetPickMode

Can anyone help me with this problem?