We have a lot of different parts with a lot of different weights. Ranging from a few grams to several tonnes. Now we want to have the weights for light parts shown with 3 decimals and for heavy parts with no decimals, and in between with one decimal.We want to do this by changing the Document Properties -> Units. As you see this will take a lot of time to do for every part. Therefore we want to have a macro for this.
Now I copy-pasted a code together to change this setting which is nice, but now I want to add a condition based on the weight of the part.
Who can help me to 'get' the value of the weight?
This is what I have now, as you see I have already prepared the conditions after '-signs:
'Changge: [Options] - [Document Properties] - [Units] - Mass to kg and for light parts to 3 decimal places
Dim swModel As SldWorks.ModelDoc2
Dim nErrors As Long
Dim nWarnings As Long
Dim swApp As Object
Dim Part As Object
Dim DocPropSetting As Boolean
Dim DecPlaces As Integer
Dim Mass As Integer
On Error Resume Next
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
' Check to see if a model is loaded.
If swModel Is Nothing Then
MsgBox "There is no active model."
If swModel.GetType <> swDocDRAWING Then
DocPropSetting = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropMass, 0, swUnitsMassPropMass_e.swUnitsMassPropMass_Kilograms)
' Mass = [get evaluated value of weight]
' if mass < 1 kg then
DecPlaces = 3 'adjust this value to the wished amount of decimal places
' ElseIf mass > 999 kg then
' DecPlaces = 0 'adjust this value to the wished amount of decimal places
' DecPlaces = 1 'adjust this value to the wished amount of decimal places
' End If
DocPropSetting = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropDecimalPlaces, 0, DecPlaces)
Thanks in advance!