Here's one way to handle all parts in one folder:
Sub main()
Dim swApp As SldWorks.SldWorks Dim swPart As ModelDoc2
Dim sPath As String Dim sFileSW As String Dim sFileTitle As String Dim sMsg As String Dim retval As Boolean Dim config As Variant Dim i As Variant
Const swDocPart = 1 Const swCustomInfoText = 30 Const swSaveAsOptions_Silent = &H1 Const swGenericSaveError = &H1 Const swFileSaveWarning_RebuildError = &H1
sMsg = "Working folder with \ at the end" sPath = InputBox(sMsg, "Folder", "C:\Temp\") If sPath = "" Then Exit Sub
Set swApp = CreateObject("SldWorks.Application")
sFileSW = Dir(sPath & "*.sldprt")
Do While sFileSW "" 'open model Set swPart = swApp.OpenDoc(sPath & sFileSW, swDocPart)
'Do something for the models '-----------------------
'read all configurations from the model config = swPart.GetConfigurationNames For i = 0 To UBound(config)
'replace the attribute value 'first remove the old one retval = swPart.DeleteCustomInfo2(config(i), "test")
'then add a new one 'retval = swPart.AddCustomInfo3(config(i), "test", swCustomInfoText, "Attr_value")
'handle next configuration Next i
'------------------------
'save
retval = swPart.Save3(swSaveAsOptions_Silent, swGenericSaveError, swFileSaveWarning_RebuildError)
'close saved part sFileTitle = swPart.GetTitle swApp.CloseDoc sFileTitle
'next file sFileSW = Dir Loop
'finished swApp.SendMsgToUser "Done..."
End Sub
It should be quite easy to combine this with the example code from the API help...