VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ObjectDBX and VB - How to set Model as the active/current layout?

2 REPLIES 2
Reply
Message 1 of 3
ennorl
1297 Views, 2 Replies

ObjectDBX and VB - How to set Model as the active/current layout?

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

 

2 REPLIES 2
Message 2 of 3
Alfred.NESWADBA
in reply to: ennorl

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 -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 3
ennorl
in reply to: Alfred.NESWADBA

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost