I'm currently modifying a macro (pdf_des_comosants_de_lassemblage.swp) that I found on the forum so that it can generate the DWG of the mep and the SAT of the parts making up the assembly. (I don't know if this is possible, but is it possible for the macro to do the same thing for all the assemblies that make up the head assembly?) I also want these documents to be saved in a " PDF", " DWG " and " SAT " folder which are located in a " CAD " folder, which is itself located in the same path as the assembly.
I'm unfortunately not super good with VBA so I'm turning to you hoping you could help me with this!
Could you edit (copy) your macro here, rather than providing it as a download? (using the tags...) I'm not a big fan of macros to download directly.
Secondly, we lack the context to help you: Do your Drawings have the same name as your 3D files and are they in the same directory? Will it be necessary to add a notion of index on the name of the PDF and/or DWG files? When you talk about your sub-assemblies, are they also in the same repertoire as the one at the top? An example of your directory hierarchy would be nice.
Sub ShowAllOpenFiles()
Dim swDoc As SldWorks.ModelDoc2
Dim swAllDocs As EnumDocuments2
Dim FirstDoc As SldWorks.ModelDoc2
Dim dummy As Boolean
Dim NumDocsReturned As Long
Dim DocCount As Long
Dim i As Long
Dim sMsg As String
Dim swApp As SldWorks.SldWorks
Dim bDocWasVisible As Boolean
Dim OpenWarnings As Long
Dim OpenErrors As Long
Dim DwgPath As String
Dim myDwgDoc As SldWorks.ModelDoc2
Dim drwPathName As String
Dim pdfPathName As String
Dim pdfFolderName As String
Dim swExportPDFData As SldWorks.ExportPdfData
Dim lErrors As Long
Dim lWarnings As Long
Dim boolstatus As Boolean
Set swApp = Application.SldWorks
Set swAllDocs = swApp.EnumDocuments2
Set FirstDoc = swApp.ActiveDoc
DocCount = 0
swAllDocs.Reset
swAllDocs.Next 1, swDoc, NumDocsReturned
While NumDocsReturned <> 0
bDocWasVisible = swDoc.Visible
'swApp.ActivateDoc swDoc.GetPathName'
DwgPath = swDoc.GetPathName
If (LCase(Right(DwgPath, 3)) <> "drw") And (DwgPath <> "") Then
DwgPath = Left(DwgPath, Len(DwgPath) - 3) & "drw"
Set myDwgDoc = swApp.OpenDoc6(DwgPath, swDocDRAWING, swOpenDocOptions_Silent, "", OpenErrors, OpenWarnings)
If Not myDwgDoc Is Nothing Then
swApp.ActivateDoc myDwgDoc.GetPathName
pdfFolderName = "C:\pdf files\"
Dim fso As Scripting.FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
If (Not fso.FolderExists(pdfFolderName)) Then
MkDir pdfFolderName
'MsgBox (pdfFolderName + " does not exist")
'Exit Sub
End If
Dim Part As ModelDoc2
Set Part = swApp.ActiveDoc()
'You have a drawing active
drwPathName = Part.GetPathName()
If ("" = drwPathName) Then
' GetPathName() was empty
MsgBox ("This drawing has not been saved yet")
Exit Sub
End If
pdfPathName = fso.BuildPath(pdfFolderName, fso.GetBaseName(drwPathName) + ".pdf")
Debug.Print pdfPathName
Set swExportPDFData = swApp.GetExportFileData(1)
swExportPDFData.ViewPdfAfterSaving = False
Part.Extension.SaveAs pdfPathName, 0, 0, swExportPDFData, lErrors, lWarnings
'MsgBox ("PDF file was created")
swApp.QuitDoc (Part.GetTitle)
Set myDwgDoc = Nothing
End If
End If
swAllDocs.Next 1, swDoc, NumDocsReturned
DocCount = DocCount + 1
Wend
swApp.ActivateDoc FirstDoc.GetPathName
End Sub
All MEPs have the same name as the part/assembly. There is a notion of clue in the properties that I would like to appear after the name of the part for the PDF, DWG & SAT.
Structure of solidworks file names:
Name-Title-Description
PDF,DWG & SAT Name Structure:
Name-Clue-Title-Description.
Hierarchy:
In the folder:
Assembly1.SLDASM Aseemblage1.SLDDRW " CAD " file
In the " CAD " folder:
PDF file " DWG " file " SAT " file Part1.SLDPRT Part1.SLDDRW Part2.SLDPRT Part2.SLDDRW Assembly2.SLDASM Assembly2.SLDDRW …
Does your notion of " index " exist on your 3Ds? (PDM?) If this is not the case, it will not be easy to repatriate this notion to SAT formats (at least without cheating with the MEP info...) …
No I don't have PDM, I fill in the notion of index in my personal properties and the index is displayed on my mep. Wouldn't it be possible to make the macro retrieve the index in the properties and then at the time of saving it is highlighted as: "Name-Index-Title-Description" as for PDFs and DWGs?