Hello,
In SolidWorks, I would like to Add a link file to Design Blinder and get the path (string) of a PDF file added into the design blinder as a link.
Is this possible in VBA? If so, do you know the function?
Hello,
In SolidWorks, I would like to Add a link file to Design Blinder and get the path (string) of a PDF file added into the design blinder as a link.
Is this possible in VBA? If so, do you know the function?
To add files:
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swExt As ModelDocExtension
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swExt = swModel.Extension
' === Sélection du fichier ===
Dim filePath As String
filePath = SelectPDF()
' Si aucun fichier sélectionné ? on sort
If filePath = "" Then
Debug.Print "Aucun fichier sélectionné"
Exit Sub
End If
' === Insertion dans le Design Binder ===
Dim bRes As Boolean
bRes = swExt.InsertAttachment(filePath, True)
If bRes Then
Debug.Print "? PDF ajouté avec lien : " & filePath
Else
Debug.Print "? Échec insertion"
End If
End Sub
' =========================
' Fonction de sélection fichier
' =========================
Function SelectPDF() As String
Dim swApp As SldWorks.SldWorks
Set swApp = Application.SldWorks
Dim fileName As String
fileName = swApp.GetOpenFileName( _
"Choisir un PDF", _
"", _
"PDF Files (*.pdf)|*.pdf", _
0, _
"", _
"")
SelectPDF = fileName
End Function
To Get link:
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModExt As SldWorks.ModelDocExtension
Dim vOleObjs As Variant
Dim i As Integer
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModExt = swModel.Extension
' Récupère tous les objets OLE
vOleObjs = swModExt.GetOLEObjects(swOleObjectOptions_GetAll)
If IsEmpty(vOleObjs) Then
Debug.Print "Aucun objet OLE trouvé"
Exit Sub
End If
' Parcours des objets
For i = 0 To UBound(vOleObjs)
Dim oleObj As Object
Set oleObj = vOleObjs(i)
' Vérifie si c'est un objet lié (pas intégré)
If oleObj.IsLinked Then
Debug.Print "Lien trouvé : " & oleObj.fileName
Else
Debug.Print "Objet intégré (pas de lien externe)"
End If
Next i
End Sub