I am looking to create a macro for SW 2009 that does the following with the Custom Properties of a part, assembly and drawing:
1. Deletes all the Property Names from the Custom Properties of the active model, except for the following Property Names and it's value, if exists:
- PartNumber
- Description
- Material
- Density
- Weight
- Finish
2. Adds any of the missing Property Names from the list above.
I wrote a macro below that can delete defined property name, but can't figure out how to accomplish (what I described above) all in one macro:
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim retval As String
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
retval = swModel.DeleteCustomInfo2("", "PartNumber")
retval = swModel.DeleteCustomInfo2("", "Description")
swModel.ForceRebuild3 (False)
End Sub
-----------------------------------------------------------------
Macro to add the missing Property Names:
Dim swApp As Object
Dim Part As Object
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Dim MyProp(1, 12) As String
'Property names
MyProp(0, 0) = "PartNumber"
MyProp(0, 1) = "Description"
MyProp(0, 2) = "Material"
MyProp(0, 3) = "Weight"
MyProp(0, 4) = "Density"
MyProp(0, 5) = "Finish"
MyProp(0, 6) = "Manufacturer"
MyProp(0, 7) = "ManufacturerPN"
MyProp(0, 8) = "TOL_X"
MyProp(0, 9) = "TOL_XX"
MyProp(0, 10) = "TOL_XXX"
MyProp(0, 11) = "TOL_ANG"
MyProp(0, 12) = "FRACTIONS"
'Property values
MyProp(1, 0) = ""
MyProp(1, 1) = ""
MyProp(1, 2) = "" & Chr(34) & "SW-Material" & Chr(34)
MyProp(1, 3) = "" & Chr(34) & "SW-Mass" & Chr(34) & Chr(32) & "lbs" & Chr(32)
MyProp(1, 4) = "" & Chr(34) & "SW-Density" & Chr(34) & Chr(32) & "lbs/in³" & Chr(32)
MyProp(1, 5) = ""
MyProp(1, 6) = ""
MyProp(1, 7) = ""
MyProp(1, 8) = ".1"
MyProp(1, 9) = ".02"
MyProp(1, 10) = ".010"
MyProp(1, 11) = "1"
MyProp(1, 12) = "~"
Dim m As Integer
For m = 0 To 12
retval = Part.AddCustomInfo3("", MyProp(0, m), 30, _
MyProp(1, m))
Next m
End Sub
---------------------------------------------
Any help will be greatly apprecaited.
Thanks in advance
Raul
SolidworksApi macros