Unit conversion with the SOLIDWORKS API

I was trying to write code to create a sketch it took units in meters as default. In my Solidworks application, I use custom units & I was trying the code in the below to get units as I required but it’s not working can anyone guide me on this?

Dim LengthConversionFactor As Double
  Dim AngleConversionFactor As Double
  Select Case swDoc.GetUnits(0)
    Case swMETER
      LengthConversionFactor = 1
      AngleConversionFactor = 1
    Case swMM
      LengthConversionFactor = 1 / 1000
      AngleConversionFactor = 1 * 0.01745329
    Case swINCHES
      LengthConversionFactor = 1 * 0.0254
      AngleConversionFactor = 1 * 0.01745329
    Case swFEET
      LengthConversionFactor = 1 * (0.0254 * 12)
      AngleConversionFactor = 1 * 0.01745329
  End Select

I cleaned up your post title a little. Please take some time in the future to post your question properly.

1 Like

If you add some debugging output, what does the following line of code print to your output window?

Debug.Print "GetUnits: " & swDoc.GetUnits(0)

Testing this on my end, this works as expected (0 for mm, 3 for inches, etc.)

1 Like

It would be good for you to share complete macro codes instead of just snippet. With this we can check if the issue is with some other lines of the macro.