AnsweredAssumed Answered

Change decimal places

Question asked by Antonio Cavka on Jul 6, 2016
Latest reply on Jul 6, 2016 by Antonio Cavka

Hi,

 

I have a macro from Deepak Gupta that changes mass properties from grams to kilograms.

Can someone modify that macro and set a function that will change decimal numbers and set them  to check how many decimals are written and then set them to  2 decimals?

 

Like: 1,142358   to   1,14

 

Here is that old macro:

 

 

' Mass_Section Properties (Mass) ---------------------------------06/08/10

 

 

' ******************************************************************************

' Macro will change the Mass units for Mass/Section Properties from Grams to Kilograms

' or vice versa

' ------------------------------------------------------------------------------

' Written by: Deepak Gupta (http://gupta9665.wordpress.com/)

' ------------------------------------------------------------------------------

 

 

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

 

 

' Set the Unit system to Custom

boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitSystem, 0, swUnitSystem_Custom)

 

 

' Get/Check Mass/Section Properties - Mass - Unit, if Grams

 

 

If (Part.Extension.GetUserPreferenceInteger(swUnitsMassPropMass, 0) = 2) Then

 

 

' Change to Kilograms

 

 

boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropMass, 0, 3) '

 

 

Else

 

 

' Else keep or set to Grams

boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropMass, 0, 2)

 

 

End If

 

 

End Sub

Outcomes