After some research and attempts, here is what I compiled:
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim Filepath As String
Dim fileName As String
Dim Revision As String
Dim exportData As SldWorks.ExportPdfData
Dim lErrors As Long
Dim lWarnings As Long
Dim confName As String
Dim revNmb As String
Dim val As String
Dim resolved As Boolean
Dim swview As SldWorks.View
Dim swRefModel As ModelDoc2
Dim swRefAssy As AssemblyDoc
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim ValOut As String
Dim numéro As String
Dim description As String
Sub Main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If swModel Is Nothing Then
MsgBox "Tu as pensé à ouvrir ta mise en plan?", vbCritical
End
End If
If swModel.GetType <> swDocDRAWING Then
MsgBox "Et si tu ouvrais ta mise en plan avant?", vbCritical
End
End If
Set swDraw = swModel
If swDraw.GetPathName = "" Then
swDraw.Save
End If
If swModel.GetType = swDocDRAWING Then ' Pour savoir si le document est un plan
Set swDraw = swApp.ActiveDoc
Set swview = swDraw.GetFirstView 'selectionne le fond de plan
Set swview = swview.GetNextView 'selectionne la premier vue
Set swRefModel = swview.ReferencedDocument
Set swCustPropMgr = swRefModel.Extension.CustomPropertyManager("")
swCustPropMgr.Get4 "Ville", True, ValOut, "Ville", False 'récupère la valeur de la propriété "Ville"
swCustPropMgr.Get5 "Rue/Quartier", True, ValOut, "Rue/Quartier", False 'récupère la valeur de la propriété "Rue/Quartier"
swCustPropMgr.Get2 "indice", True, ValOut, "indice", False 'récupère la valeur de la propriété "indice"
Dim dateNow As String
dateNow = Replace(Date, "/", ".")
Filepath = "D:\Téléchargements\Plan PDF"
Filepath = Filepath + "\"
fileName = ValOut & " " & "-" & " " & ValOut & " " & "-" & " " & "Ind." & " " & ValOut & " " & "-" & " " & dateNow
swDraw.SaveAs (Filepath + fileName + ".PDF")
Exit Sub
End If
End Sub
Let me be clear, I only understood a small part of all this but it's functional except for a part.
I've looked at several property recovery topics but I don't understand how it works:
swCustPropMgr.Get4 "Ville", True, ValOut, "Ville", False 'récupère la valeur de la propriété "Ville"
swCustPropMgr.Get5 "Rue/Quartier", True, ValOut, "Rue/Quartier", False 'récupère la valeur de la propriété "Rue/Quartier"
swCustPropMgr.Get2 "indice", True, ValOut, "indice", False 'récupère la valeur de la propriété "indice"
the Get4 or Get5... I don't see how to say:
The value assigned to "City" is what is in the next box
and then, to be able to transcribe it in the name because for the moment, apart from the date, the names of the properties are not displayed. Here is the result I get: " - - Ind. - 04.02.2019.PDF"
Also, to understand a little more, what is the purpose of all the lines below "Option Explicit" of the style:
Dim swApp As SldWorks.SldWorks
Thanks in advance