Hi there,
I have been looking everywhere but strangely haven't found a way to create a pdf of a dwg from excel.
The idea would be to print specific sheets of a given dwg without having to open it and using the last plot/page setup properties.
If you know of any ways to achieve that I would be glad if you could point me in the right direction.
Note that I am using Autocad 2014 LT and Excel's VBA.
Many thanks for your help.
Well not far yes!
I want to use VBA in excel to control autocad in order to:
1 open a dwg file in the background (that part is easy!)
2 export a sheet as pdf (still in the background)
3 close the file
It must be doable I have done similar things on other sofware but for some reason finding any kind documentation on this topic for Acad seems near impossible.
Any help would be greately appreciated!
Yes sure the only thing is that the pdf creation is just one part of a more complex vba program.
The excel spreadsheet is used as an issue control tool where, when a file is ready to be issued to the customer the current file is moved to an "Issue" folder replacing the previous issue which is moved to an "Historical" folder. (The project history is also tracked within the excel spreadsheet).
Since both dwg and pdf are sent to the customer I need to automate the pdf creation within this excel sheet.
Hope it makes sense!
You might want to ask over in one of the customization forums, but as far as I know, it's possible with AutoCAD, but not AutoCAD LT.
So for anyone who's interested in this, the following seems to work ok with the exeption of bringing up the "save changes" window at the end:
Private Sub printpdf()
Dim dwgfileAs Range
Dim App As Object
Dim Doc As Object
Dim pdffile As String
Dim result As String
Set App = CreateObject("AutoCAD.Application")
Set dwgfile= Cells(1, 1)
pdffile = Cells(2, 1)
App.Visible = False
Set Doc = App.Documents.Open(dwgfile)
Doc.ActiveLayout.ConfigName = "DWG To PDF.pc3"
result = Doc.Plot.PlotToFile(pdffile)
App.Quit
End Sub
Et voilà!
That's right.
Youjust need to add the reference to the Acad library. (in the VBA editor just go tool - reference and tick the corresponding library)
I would like to correct my previous post. As it was rightly pointed out this can work in the full version of autocad (which is what I was using to test the code) but not in LT unfortunately. All hope is not lost for LT automation though as explained here:
http://metamorphs.blogspot.fr/2011/10/programmingautomating-autocad-lt.html
Sorry for the confusion!
Hello, I know that this topic is too old, but I tried your code and it worked! :D, butI wonder if it is possible to change the printing options, because the PDF file does not appear complete, and I would also like to know if it is possible to export a several lay outs, thanks a lot!!