Apply for a Macro: bulk change all weight units in part and assembly:
I have a folder full of partsand assemblys, i want to change their models' weight units to Kg or g, and 0.0, 0.00 or 0.000.
Who can share this Macro for me?
Apply for a Macro: bulk change all weight units in part and assembly:
I have a folder full of partsand assemblys, i want to change their models' weight units to Kg or g, and 0.0, 0.00 or 0.000.
Who can share this Macro for me?
U can use TASK and run this macro on all parts or ass at once, they go on 2 decimals
' 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)
' Iza zareza zaoruzuje na stotu decimalu
boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropDecimalPlaces, swUserPreferenceOption_e.swDetailingNoOptionSpecified, 2)
End If
End Sub
Thank you for sharing, i modifiy it and share with all.
It could works well, here are the codes and swp file.
' Mass_Section_Properties (Mass) ---------------------------------------------21/08/2016 ' **************************************************************************************** ' Macro will change the Mass units for Mass/Section Properties from all others to Grams; ' You can use TASK and run this macro on all parts or ass at once, they go on 1 decimals; ' You can change the units and decimals by your self according to the parameters table; ' Written by: Deepak Gupta ( http://gupta9665.wordpress.com/ ) ' Modified by: Jeff Lee ( Specially thanks to Deepak Gupta ) ' **************************************************************************************** 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 from (MKS, CGS, MMGS, IPS) to Custom boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitSystem, 0, swUnitSystem_Custom) ' Get and Check the Mass_Section_Properties - Mass - Unit, if it is not Grams ' Mass units Member Description(Value) ' swUnitsMassPropMass_Grams 2 ' swUnitsMassPropMass_Kilograms 3 ' swUnitsMassPropMass_Milligrams 1 ' swUnitsMassPropMass_Pounds 4 If (Part.Extension.GetUserPreferenceInteger(swUnitsMassPropMass, 0) <> 2) Then ' Change to Grams boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropMass, 0, 2) ' 'Else // Please ignore this code, it is the original code from Deepak Gupta ' Else keep or set to Grams // Please ignore this code, it is the original code from Deepak Gupta ' You can choose the decimal place format: ' boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropMass, 0, 2) ' Iza zareza zaoruzuje na stotu decimalu ( Behind the point set the hundredth decimal place, ' Integer value could be set to (0, 1, 2, 3, 4, 5, 6, 7, 8 ) boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropDecimalPlaces, swUserPreferenceOption_e.swDetailingNoOptionSpecified, 1) End If End Sub
Thank you for sharing, i modifiy it and share with all.
It could works well, here are the codes and swp file.