3 Replies Latest reply on Sep 5, 2016 9:38 AM by Amen Allah Jlili

    Automatic Scale Can Not Performe

    Ali Al-Abbasi

      Hello,

      Good day,

       

      I am trying to create a macro that can help me with my work. The macro is to create a truss frame within a given length. I recorded my steps and I saved the macro. Then, I created a new part and played the marco normally. After some steps, the macro stopped. I debugged the error, it shows me that the Automatic Scale Can Not Performe. I re-run the macro with the debug. Noticed that the macro stops after entering the line dimension.

       

      Does anyone of you guys experience this issue.

       

      Thanks for help in advance..

       

      Ali

        • Re: Automatic Scale Can Not Performe
          Amen Allah Jlili

          Do you mind sharing your code?

            • Re: Automatic Scale Can Not Performe
              Ali Al-Abbasi

              Hello Amen,

               

              No I do not mind at all.

               

              Here is part of the code below:

               

              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 myModelView As Object

              Set myModelView = Part.ActiveView

              myModelView.FrameState = swWindowState_e.swWindowMaximized

              boolstatus = Part.Extension.SelectByID2("Top Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0)

              Part.SketchManager.InsertSketch True

              Part.ClearSelection2 True

              Dim skSegment As Object

              Set skSegment = Part.SketchManager.CreateLine(-0.150897, 0#, 0#, 0.150897, 0#, 0#)

              Part.SetPickMode

              Part.ClearSelection2 True

              boolstatus = Part.Extension.SelectByID2("Line1", "SKETCHSEGMENT", -8.05292374418929E-02, 0, -3.81053174015267E-04, False, 0, Nothing, 0)

              Dim myDisplayDim As Object

              Set myDisplayDim = Part.AddDimension2(-5.05530544193586E-02, 0, 1.79094991787175E-02)

              Part.ClearSelection2 True

              Dim myDimension As Object

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

              myDimension.SystemValue = 0.3 (the macro stops here...)

              Part.ClearSelection2 True

              Set skSegment = Part.SketchManager.CreateLine(-0.15, 0.068561, 0#, 0.15, 0.068561, 0#)

              Part.SetPickMode

              Part.ClearSelection2 True

                • Re: Automatic Scale Can Not Performe
                  Amen Allah Jlili

                  Hello back Ali!

                   

                  I fixed your code below:

                  Dim swApp As Object
                  Dim Part As Object
                  Dim boolstatus As Boolean
                  Dim longstatus As Long, longwarnings As Long
                  Sub main()
                  Dim feat As Feature
                  Dim skSegment As SketchSegment
                  Set swApp = _
                  Application.SldWorks
                  
                  Set Part = swApp.ActiveDoc
                  Dim myModelView As Object
                  Set myModelView = Part.ActiveView
                  myModelView.FrameState = swWindowState_e.swWindowMaximized
                  boolstatus = Part.Extension.SelectByID2("Top Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
                  Part.SketchManager.InsertSketch True
                  Part.ClearSelection2 True
                  Set skSegment = Part.SketchManager.CreateLine(-0.150897, 0#, 0#, 0.150897, 0#, 0#)
                  Part.SetPickMode
                  Part.ClearSelection2 True
                  boolstatus = Part.Extension.SelectByID2("Line1", "SKETCHSEGMENT", -8.05292374418929E-02, 0, -3.81053174015267E-04, False, 0, Nothing, 0)
                  Dim myDisplayDim As Object
                  swApp.SetUserPreferenceToggle swConst.swInputDimValOnCreate, False
                  Set myDisplayDim = Part.AddDimension2(-5.05530544193586E-02, 0, 1.79094991787175E-02)
                  Part.ClearSelection2 True
                  Dim myDimension As Object
                  Dim swSketch As sketch
                  Set swSketch = skSegment.GetSketch
                  Set feat = swSketch
                  Set myDimension = Part.Parameter("D1@" + feat.Name)
                  myDimension.SystemValue = 0.3
                  Part.ClearSelection2 True
                  Set skSegment = Part.SketchManager.CreateLine(-0.15, 0.068561, 0#, 0.15, 0.068561, 0#)
                  Part.SetPickMode
                  Part.ClearSelection2 True
                  End Sub
                  

                   

                   

                  Here's the reason why it wasn't working:

                   

                  When you recorded the macro, Solidworks grabbed the dimension name for that specific attempt of drawing the line and thus the name of the dimension was D1@Sketch1. The problem happens the next time you try to use the macro as SolidWorks will create a new sketch augmenting its count number to Sketch2. When SolidWorks tries to find the D1@Sketch1, it fails. Setting the dimension object has to dynamically take into account of the changing sketch name!

                   

                  Here's a video where I explain the good and bad of using the macro recorder: Recording SolidWorks Macros - YouTube !