AnsweredAssumed Answered

How to add a dimension to a Sketch?

Question asked by Diego Saenz on Apr 18, 2018
Latest reply on Sep 17, 2018 by David Mandl

I recorded this simple macro which creates 2 lines and adds a dimension to one of them, yet I cannot run it. Each time I try to run the macro I get "Run-time error '91': Object variable or With block variable not set".
What's happening?

 

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

Dim COSMOSWORKSObj As Object

Dim CWAddinCallBackObj As Object

Set CWAddinCallBackObj = swApp.GetAddInObject("CosmosWorks.CosmosWorks")

Set COSMOSWORKSObj = CWAddinCallBackObj.COSMOSWORKS

Part.ClearSelection2 True

Dim skSegment As Object

Set skSegment = Part.SketchManager.CreateLine(-0.062071, 0.031491, 0#, 0.044724, 0.020114, 0#)

Set skSegment = Part.SketchManager.CreateLine(0.044724, 0.020114, 0#, 0.072671, -0.053698, 0#)

Part.SetPickMode

Part.ClearSelection2 True

boolstatus = Part.Extension.SelectByID2("Line1", "SKETCHSEGMENT", -1.37844698816069E-02, 1.06805172404046E-02, 1.76911028892737E-05, False, 0, Nothing, 0)

Dim myDisplayDim As Object

Set myDisplayDim = Part.AddDimension2(0, 0.083967766732826, 0.163377435133782)

Part.ClearSelection2 True

Dim myDimension As Object

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

myDimension.SystemValue = 0.107

Part.ClearSelection2 True

Part.SketchManager.InsertSketch True

StudyManagerObj = Nothing

ActiveDocObj = Nothing

Set CWAddinCallBackObj = Nothing

Set COSMOSWORKSObj = Nothing

End Sub

 

 

The error appears in the line in red

Outcomes