Hello and welcome;
What exactly do you mean by:
It's not very clear...
And there are some essential pieces of information missing:
The Solidworks Version
The scope of the macro (all Solidworks documents, only parts, parts and assemblies, drawings...?)
What I understand:
In your macro, you extract the value of the custom " Title " property from an open SolidWorks document, and then place that value in the Title field of the document's summary information, checking for no no document or empty property errors.
(Note: I advise you not to use the same property (the Property Name) several times for different variables... (here " Title " for Custom Properties and " Title " for Windows Summary properties (tab: Summary in the information summary of the Solidworks document)
I suggest you adapt your macro so that it works on all the files in a given directory:
It's up to you to modify the value in:
folderPath = "C:\Path\To\Folder"
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim propMgr As CustomPropertyManager
Dim titleValue As String
Dim resolved As String
Dim wasResolved As Boolean
Dim filePath As String
Dim folderPath As String
Sub main()
Set swApp = Application.SldWorks
' Modifier ici pour mettre le chemin du dossier
folderPath = "C:\Chemin\Vers\Le\Dossier\"
filePath = Dir(folderPath & "*.sld*") ' Trouve les fichiers .sldprt, .sldasm, .slddrw
Do While filePath <> ""
' Ouvre le document
Set swModel = swApp.OpenDoc6(folderPath & filePath, _
GetDocType(folderPath & filePath), _
0, "", 0, 0)
If Not swModel Is Nothing Then
Set propMgr = swModel.Extension.CustomPropertyManager("")
wasResolved = propMgr.Get4("Title", False, resolved, titleValue)
If titleValue <> "" Then
swModel.SummaryInfo(swSumInfoTitle) = titleValue
swModel.Save
End If
swApp.CloseDoc swModel.GetTitle
Else
MsgBox "Impossible d'ouvrir : " & filePath
End If
filePath = Dir() ' Passe au fichier suivant
Loop
MsgBox "Traitement terminé."
End Sub
' Fonction utilitaire pour déterminer le type de document selon l'extension
Function GetDocType(fileName As String) As Long
Dim ext As String
ext = LCase$(Mid$(fileName, InStrRev(fileName, ".") + 1))
Select Case ext
Case "sldprt"
GetDocType = 1 ' pièce
Case "sldasm"
GetDocType = 2 ' assemblage
Case "slddrw"
GetDocType = 3 ' mise en plan
Case Else
GetDocType = 0 ' inconnu
End Select
End Function
Otherwise the subject has already been discussed here:
https://forum.mycad.visiativ.com/t/copier-proprietes-personnalisees-vers-les-proprietes-du-fichiers/108809?lang=en
But it's bothering for not much:
=> It is possible to use the Solidworks property manager to duplicate a variable to the Summary info.
https://help.solidworks.com/2022/french/SolidWorks/sldworks/HelpViewerDS.aspx?version=2022&prod=SolidWorks&lang=french&path=sldworks%2Fc_file_properties.htm&id=5fb9c079433c46d7961143b30be81132
=> it's easier with MyCadTools such as Smartproperties or in the processing station with the Integration or batchProperties tools.