I very often need to use and update parts created on SolidWorks for a long time.
Whenever I need to modify one of these parts or recreate a plane of it I have to assign a material to it (usually always the same one), create the custom Material property, create the Mass property and go to the document properties to modify the mass unit to change it to kg.
To avoid repeating these same actions over and over again, I would like to know if it will be possible to create a macro that would do all this.
I tried to record a macro while doing all of this, but when I want to use it, it just opens up the custom properties menu for me and nothing else happens.
As I don't know much about Macro, I hope someone will be able to help me.
See if you find what you're looking for and try to modify to your liking.
Otherwise without any knowledge of macro there are the Visiativ tools (MyCad-Integration) which does what you ask without any knowledge in macro and in batch (apply on a folder or an assembly and all the children:
In my opinion there are simpler than the links given above:
Dim swApp As SldWorks.SldWorks
Dim Part As ModelDoc2
Dim CustPropMgr As CustomPropertyManager
Dim bRet As Boolean
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
If Not Part Is Nothing Then
If Part.GetType() = swDocumentTypes_e.swDocPART Then
bRet = Part.SetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swUnitSystem, swUnitSystem_e.swUnitSystem_Custom)
bRet = Part.SetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swUnitsMassPropMass, swUnitsMassPropMass_e.swUnitsMassPropMass_Kilograms)
Part.SetMaterialPropertyName2 "NomDeMaConfig", "C:\xxxxxxxx\MaBaseDeMateriaux.sldmat", "NomDeMonMateriau"
Set CustPropMgr = Part.Extension.CustomPropertyManager("")
bRet = CustPropMgr.Add3("Matiere", swCustomInfoType_e.swCustomInfoText, """SW-Material""", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd)
bRet = CustPropMgr.Add3("Masse", swCustomInfoType_e.swCustomInfoText, """SW-Masse""", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd)
Part.ForceRebuild3 True
End If
End If
End Sub
Of course, on the line with the "SetMaterialPropertyName2" function you replace the values in quotation marks as you wish.