Quoting in a macro

In my opinion it comes from your selection of the name of the rating. If you've tried several times, SW increments the sketch numbers, so if it's not called D1@Esquisse1 the content of mydimension is empty.

1 Like

So try this instead:

Dim swApp As Object
Dim Part As SldWorks.ModelDoc2

Dim boolstatus As Boolean
Dim value As Boolean

Sub main()

Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc

value = swApp.GetUserPreferenceToggle(swUserPreferenceToggle_e.swInputDimValOnCreate)
    If value = True Then
      boolstatus = swApp.SetUserPreferenceToggle(swUserPreferenceToggle_e.swInputDimValOnCreate, False)
    End If

boolstatus = Part.Extension.SelectByID2("Plan de face", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
Part.SketchManager.InsertSketch True
Dim skSegment As Object
Set skSegment = Part.SketchManager.CreateLine(0#, 0#, 0#, 0.051925, 0#, 0#)
boolstatus = Part.Extension.SelectByID2("Line1", "SKETCHSEGMENT", 1.97416243507319E-02, -1.20689440993789E-03, 0, False, 0, Nothing, 0)
Dim myDisplayDim As SldWorks.DisplayDimension
Set myDisplayDim = Part.AddDimension2(2.59101957793034E-02, -1.59578260869565E-02, 0)
Dim myDimension As SldWorks.Dimension
Set myDimension = myDisplayDim.GetDimension
myDimension.SystemValue = 0.05
Part.SketchManager.InsertSketch True

boolstatus = swApp.SetUserPreferenceToggle(swUserPreferenceToggle_e.swInputDimValOnCreate, value)

End Sub

 

2 Likes

If not, try macro in a new room!? the sketches and the names of the dimensions will be back to zero!?

1 Like

Yes @Cyril.f, it seems to work!!

I'm analyzing the code, thank you!

It's okay, it's what I wanted.

Thank you all for your help!!

1 Like