1 Reply Latest reply on May 10, 2017 12:02 PM by Patrik MacHalec

    How to pass a parameter of an instance as a variable?

    Giuseppe Tescione

      Hi everyone, this is my first post... I would really appreciate any help.

      Sorry if the question is trivial, I am just starting learning API and after many hours on google I could not find a clear answer to this...

       

      I am wiritng a macro to automatize a series of commands in solidworks, I am now stuck with 2 similar issues:

      I want to scale all the selected elements of a sketch by a scale factor and later I want to extrude a closed contour into a solid by a certain depth. I want the scale factor and the depth to be variable imported from an external file or prompted by the user... I am failing this miserably.

       

      My code works if I hardcode the values:

       

      Part.Extension.ScaleOrCopy(False, 0, 0, 0, 0, 0.75)

      ...

      Part.FeatureManager.FeatureExtrusion2(False, False, False, 0, 0, 1.2, 1.2, False, False, False, False, 0, 0, False, False, False, False, True, True, True, 0, 0, False)

       

      but it does not when I declare and pass the parameters as variables:

       

      Dim ScaleFactor As Long

      ScaleFactor = 0.75

      Part.Extension.ScaleOrCopy(False, 0, 0, 0, 0, ScaleFactor)

      ...

      Dim Depth As Long

      Depth = 1.2

      Part.FeatureManager.FeatureExtrusion2(False, False, False, 0, 0, Depth, Depth, False, False, False, False, 0, 0, False, False, False, False, True, True, True, 0, 0, False)

       

      what am I not getting?

       

      Thanks!