I created a macro that allows me to save a step file with the name of the configuration of the part to save. It works very well but I want to do the same thing with a plan saved in pdf but it doesn't work.
Happy to see you on the forum and to welcome you. I hope that we can help you solve some problems, but also that we can benefit from your knowledge and experience.
Given the holidays, you may have to wait a little longer to have the complete answer to your request
Hello While waiting for the macro experts to show up, have you searched the database (search bar at the top)? There are dozens of topics regarding your needs. That might answer your question.
Above all, there is a lack of information: how is the drawing done? One sheet per configuration? A single drawing and you want to change the configuration of the drawing model configuration by configuration and export the MEP with the name of the configuration? For a MEP it's not as simple as exporting a 3D model. You will therefore have to explain your wish more clearly, or propose a file for testing.
I made a single drawing that changes according to the selected configuration, I think it's complicated to create a loop to save a pdf file for each of the configurations so first I just want to save the active configuration. After if anyone knows how to make a loop would be great!
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swExportPDFData As SldWorks.ExportPdfData
Dim strFilename As String
Dim status As Boolean
Dim errors As Long, warnings As Long
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
'Save
status = swModel.Save3(swSaveAsOptions_e.swSaveAsOptions_Silent, errors, warnings)
'Export to PDF if it is a drawing
If (swModel.GetType = swDocDRAWING) Then
'Ici la variable strFilename à modifier pour récupérer le nom de la configuration active de la MEP
strFilename = swModel.GetPathName
strFilename = Left(strFilename, Len(strFilename) - 6) & "pdf"
Set swExportPDFData = swApp.GetExportFileData(1)
swModel.Extension.SaveAs strFilename, 0, 0, swExportPDFData, 0, 0
End If
End Sub
Then it remains to loop on each config and loop on each view of the MEP and to change the configuration reference at each view for the new desired config.
I combined the two macros you gave me but I can't get the desired result. My macro debugs the line "Set swDraw = swModel" and tells me that Swdraw = Nothing. I don't understand why? Here's my modified macro.
Sub main()
Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim swExportPDFData As SldWorks.ExportPdfData Dim strFilename As String Dim status As Boolean Dim errors As Long, warnings As Long Dim swDraw As SldWorks.DrawingDoc Dim swView As SldWorks.View Dim bRet As Boolean Dim swconfig As String
Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc Set swDraw = swModel
Debug.Print "File = " & swModel.GetPathName
' First drawing view is actually the first sheet, ' so skip getting model name and configuration from ' the sheet Set swView = swDraw.GetFirstView ' Get first drawing view in first sheet Set swView = swView.GetNextView Do While Not swView Is Nothing Debug.Print " View = " + swView.Name Debug.Print " Model = " + swView.GetReferencedModelName Debug.Print " Config = " + swView.ReferencedConfiguration
' Récupérez le nom de la configuration active de la vue en cours de traitement
swconfig = swView.ReferencedConfiguration
Set swView = swView.GetNextView Loop 'Save status = swModel.Save3(swSaveAsOptions_e.swSaveAsOptions_Silent, errors, warnings)
'Export to PDF if it is a drawing If (swModel.GetType = swDocDRAWING) Then • Generate the name of the PDF file using the name of the active configuration strFilename = swModel.GetPathName strFilename = Left(strFilename, Len(strFilename) - 6) & swconfig & ".pdf" Set swExportPDFData = swApp.GetExportFileData(1) swModel.Extension.SaveAs strFilename, 0, 0, swExportPDFData, 0, 0 End If
End Sub
If anyone knows where the problem is, I'd be delighted!
PS: I've been starting in Macro since last week, I don't have all the basics yet
No problem with the line indicated if a drawing document is open, as indicated by Cyril.f. To make the macro functional, I made only one modification: In terms of saving in PDF format, you must remove the spaces in the file name extension: ".pdf" instead of ".pdf"... Solidworks uses this extension to recognize the expected format, here pdf.
Indeed, everything is fine! I had a room and an open plan maybe for that... All I have to do is make the loop, but I don't know if it's possible because the scale has to be adjusted according to the size of the room
Otherwise I found this macro that creates each drawing from an MEP:
This can help you move forward but for scaling it's more complicated:
If you manage to combine all this into a macro, it means that you will have made good progress in your progress. On the other hand, it starts to this very complicated.