PDF save macro in current folder

Hello

Despite all the questions already asked about macros for a PDF record on Solidworks (2014 in my case), I can't find anything corresponding to my problem.

I would like a macro that saves the plan as a PDF in the current folder, with the current file name, but having no knowledge of VBA code, impossible for me to modify the code at the line of the path where the PDF will be saved, despite a lot of research on the internet.

I have created a macro by learning that is here, all that remains is to modify this famous line.

In my case, the macro will always save PDFs with the name "1841-22" in the "1841" folder, while for an "1836-12" plan, I would like it in the "1836" folder, all while having a single common macro for all my folders, and not a macro for each folder.

Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = _
Application.SldWorks

Set Part = swApp.ActiveDoc
Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
Part.ViewZoomtofit2
Part.ViewZoomtofit2
Part.ViewZoomtofit2
longstatus = Part.SaveAs3("M:\Design Office\Products\1800-49\1841\1841-22.PDF", 0, 0)
End Sub

 

Thanking you in advance for your help,

 

Kind regards

 

Allan.

 

Hello

See how to recover the file name here:

https://forum.solidworks.com/thread/26814

And this line will have to be changed:

longstatus = Part.SaveAs3("M:\Design Office\Products\1800-49\1841\1841-22.PDF", 0, 0)

We can also draw inspiration from this macro:

https://forum.solidworks.com/servlet/JiveServlet/download/116587-39393/Save%20Part-Assembly%20as%20Parasolid.zip

See also my macros here (I don't know which one includes the file name):

http://www.lynkoa.com/tutos/macro-ouvrir-la-piece-dans-l-assemblage

http://www.lynkoa.com/tutos/3d/macro-enregistrer-sous-avec-solidworks

In fact I made the modification, try this:

Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc

Gets the full path of the current document, including the file name:
PathName = UCase(PArt.GetPathName)


Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
Part.ViewZoomtofit2
Part.ViewZoomtofit2
Part.ViewZoomtofit2
longstatus = Part.SaveAs3(Replace(PathName,"SLDDRW","PDF") , 0, 0)
End Sub

2 Likes

Thank you .PL your modification works perfectly, I tried it on several files and no souçi, thank you for your help!

1 Like

Mr Macro has been rampant again^^

1 Like

If you have MyCADtools, PowerPrint does it very well.

 

uh given the subject, if we want to have the same path, but just the name of the file that changes these possible its? we will have to note or the info?? :)

Hi everyone

After several months of conclusive testing thanks to the macro of .PL (thank you again), I'm coming back to you for a small detail that is starting to bother me.

When a .PDF plan is opened at the workshop for consultation and I need to make a change. on this same plane directly on Solidworks, and I use this PDF macro, Solidworks crashes and closes, because it can't overwrite the PDF file since it's already open.

However, when I try to save the plan .PDF using File-Save sous-.PDF, the message "This file is read-only" appears and allows Solidworks not to crash.

Would it be possible to retrieve a line of code in my macro that would allow me to have this message when the file is already open, and not crash Solidworks?

Thank you in advance for your help,

Kind regards

Allan.

1 Like

@allan.comment : ask a new question on the forum, no one comes to see the old ones.