Hello,
I'm using VS2013 (VB) and Autocad 2010 to write some code to prepare (ie. setting the drawing size, orientation, layers on/off, config name etc.) some drawing files before using Adobe PDFMaker to make pdfs. During testing, we noticed that if a Layout (Layout1) has been activated by simply clicking on the tab, it will be included in the pdf. In other words, we get one sheet for the “Model” and one sheet for “Layout1” in the pdf. If the Layout1 tab has never been clicked in a drawing, we get one only sheet in the pdf representing a printout of “Model”. We only want the printout of the “Model” as we do not utilize Layouts for printing.
I would like to iterate through the layouts and delete everything except the “Model”. When trying to delete “Layout1”, an error is thrown saying “Unable to set current layout”. I think if I could set the “Model” as current, the “Layout1” could be deleted. So my question is how to set “Model” as the current layout so I can delete “Layout1”. OR… I am I going about this wrong? Is there a way to de-activate a Layout tab once it has been clicked. I looked to see what gets “activated”, but I can’t tell.
I have searched many Autocad forums and found examples of how to set a Layout as current or active using VLISP. I also found examples in VB, but they were not using ObjectDBX. They all used an active session of Autocad.
Any help would be greatly appreciated.
Here is a condensed version of the code:
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
---------------------------------------------------
Dim AxDbDoc As AxDbDocument
Dim objACApp As AcadApplication
objACApp = Nothing
On Error Resume Next
objACApp = GetObject(, "AutoCAD.Application.18") 'acad 2010
AxDbDoc = objACApp.GetInterfaceObject("ObjectDBX.AxDbDocument.18") 'acad 2010
AxDbDoc.Open(strFileName) 'Open the drawing
'**** Set up the drawing for making the PDF ****
'Delete all Layouts (except Model)
For j = AxDbDoc.Layouts.Count - 1 To 0 Step -1
If AxDbDoc.Layouts(j).Name.ToString <> "Model" Then
AxDbDoc.Database.Layouts(j).Delete() <== THIS IS WHERE IT ERRORS WITH “LAYOUT1”
End If
Next
With AxDbDoc.ModelSpace.Layout
'define layer settings here
'define plot settings here
End With
AxDbDoc.SaveAs(AxDbDoc.Name) 'save the file
Hi,
in AutoCAD it's not valid to delete all layouts, so you have the modelspace and at least one layout (and that can't be deleted).
- alfred -
Hi Alferd,
Thank you for the quick response. Ok, I understand. How about de-activating a Layout tab once it has been clicked? I noticed today that if I make a copy of my drawing and then make a pdf of that drawing, it only prints the Model. I'm guessing this is because the Layout1 has not been activated in the copy?
Kind Regards,
Lorna