Get Assembly Mass

Good Morning,


I have got the following macro which i have put together based on research from the forums to get the mass of a part and assembly and to write it to a custom property once a simple calculation has been done on the mass.

Option Explicit<br>Dim cpm As CustomPropertyManager<br>Public Enum swMassPropertiesStatus_e<br> swMassPropertiesStatus_OK = 0<br> swMassPropertiesStatus_UnknownError = 1<br> swMassPropertiesStatus_NoBody = 2<br>End Enum<br>Public Enum swUserPreferenceToggle_e<br> swUpdateMassPropsDuringSave = 30<br>End Enum<br>Sub main()<br>Dim swApp As SldWorks.SldWorks<br> Dim swModel As SldWorks.ModelDoc2<br> Dim swModelExt As SldWorks.ModelDocExtension<br> Dim swAssy As SldWorks.AssemblyDoc<br> Dim swSelMgr As SldWorks.SelectionMgr<br> Dim swComp As SldWorks.Component2<br> Dim nStatus As Long<br> Dim vMassProp As Variant<br><br> Set swApp = CreateObject("SldWorks.Application")<br> Set swModel = swApp.ActiveDoc<br> Set swModelExt = swModel.Extension<br>vMassProp = swModelExt.GetMassProperties(1, nStatus)<br><br> If swModel.GetType = swDocASSEMBLY Or swModel.GetType = swDocPART Then<br> If Not IsEmpty(vMassProp) Then<br> Dim strMass As String<br> If vMassProp(5) < 1000 Then<br> strMass = Round(vMassProp(5), 0) & "g"<br><br> Set cpm = swModel.Extension.CustomPropertyManager("")<br> cpm.Delete "Weight"<br> cpm.Add2 "Weight", swCustomInfoText, strMass<br><br> MsgBox ("Weight Added")<br> Else<br> strMass = Round((vMassProp(5) / 1000), 1) & "kg"<br><br> Set cpm = swModel.Extension.CustomPropertyManager("")<br> cpm.Delete "Weight"<br> cpm.Add2 "Weight", swCustomInfoText, strMass<br><br> MsgBox ("Weight Added")<br> End If<br> End If<br> End If<br>End Sub‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍<span class="line-numbers-rows"><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span></span>

This is working perfectly for a part and the code does run in an assembly however if i have an assembly who's mass is 62364.07grams the macro is writing 62g to the properties.  When i look at the document properties of the assembly the Mass Unit is set to grams and not kgs. Can someone please help advise where things may be going wrong.

Thanks in advanced

Luke

SolidworksApi/macros