Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can't delete all layouts?

7 REPLIES 7
Reply
Message 1 of 8
mdhutchinson
980 Views, 7 Replies

Can't delete all layouts?

Why can't I get this to work?... okay, it is being used via AcCoreConsole.exe

I get the following...  

; error: bad argument type: VLA-OBJECT nil

 

(defun delAllLayouts ()
 (vl-load-com)
 (vlax-for item
    (vla-get-Layouts
      (vla-get-ActiveDocument
        (vlax-get-acad-object)   <--- line pops the error
      ) 
   )
   (if (not (eq (vla-get-Name item) "Model"))
     (vla-delete item)
   )
 )
)

7 REPLIES 7
Message 2 of 8

Hi,

 

There has to be at least 1 paperspace layout, you can not delete them all.

 

To check for the "Model" layout, I use the ModelType property of the layout object.

 

 (vlax-for item
    (vla-get-Layouts
      (vla-get-ActiveDocument
        (vlax-get-acad-object)   <--- line pops the error
      ) 
   )

   (setq ModelType (vla-get-ModelType item))

 

   (cond

     ((= ModelType :vlax-true)

       ; "Model" layout

       ; Ignore.

     )

 

     ((= ModelType :vlax-false)

       ; Paperspace layout.

       ; Decide here which Paperspace layout you want to keep and delete the others.

       ; "Layout1" may have been renamed and may not exist.

       ; There has to be at least 1 paperspace layout.

     )

   );cond

;   (if (not (eq (vla-get-Name item) "Model"))
;     (vla-delete item)
;   )
 )

 

 

Regards,

Trevor

Message 3 of 8
Kent1Cooper
in reply to: mdhutchinson

That line doesn't give me an error [but I haven't run the whole routine in any of my drawings...!].  Re-boot and try again?

 

Interestingly, the (layoutlist) function doesn't include the Model tab in the list it returns, which means you can do this without needing to check whether each Layout is "Model" or not, to decide whether to delete it, for example this way:

 

(setvar 'ctab "Model")

(foreach layout (layoutlist) (command "_.layout" "_delete" layout))

 

Even if you're scared of the (command) function as some seem to be, you could do the deleting with (vl...) functions, but starting from (layoutlist)'s return rather than from (vla-get-Layouts ...), and still eliminate the Name test.

Kent Cooper, AIA
Message 4 of 8


@trevor.bird.au wrote:

.... 

There has to be at least 1 paperspace layout, you can not delete them all.

....


Actually, you can -- I just set up a drawing and tried it, using the (command) approach [it may be that the (vl...) approach won't let you delete them all, but I didn't test that].  I tried it both with Layout1 renamed and not.  It won't leave you in the end with no paper space Layouts, but you can delete them all, after which it will leave you with just one, called Layout1.  Even if Layout1 is the only one left, and even if it still has that name, it will delete it, and then reconstitute a new one by that name, and it will be empty, even if the old one had things drawn in it.  If, on the other hand, you unnecessarily decide on one to keep on the assumption that you can't delete them all, the one you keep won't be emptied unless you build in something to do that.

Kent Cooper, AIA
Message 5 of 8

Hi Kent,

 

It's also interesting how using "command" to delete all layouts, seems to have some built in check to make sure that there's at least 1 paperspace layout.

 

On a new drawing which had Layout1 and Layout2 by default, your method retained Layout1 and did not throw an error.

I'm guessing Layout1 i a new drawing is also the default last active layout and is retained as the 1 and only paperspace layout.

 

Regards,

Trevor

Message 6 of 8

lol that's also very interesting.

Message 7 of 8

My code runs fine in full blown AutoCAD... it is in AcCoreConsole that I have the issue.

?

Message 8 of 8


@trevor.bird.au wrote:

Hi Kent,

 

It's also interesting how using "command" to delete all layouts, seems to have some built in check to make sure that there's at least 1 paperspace layout.

 

On a new drawing which had Layout1 and Layout2 by default, your method retained Layout1 and did not throw an error.

I'm guessing Layout1 i a new drawing is also the default last active layout and is retained as the 1 and only paperspace layout.

....


My guess is that it's not making sure at least 1 paper space Layout stays in the drawing, but instead, if you delete them all, it responds to the absence of any by re-making a blank one, which it then calls Layout1 regardless of whatever the deleted ones were called.  If you rename Layout1 to something else, so there is no Layout with that name in the drawing, and then do the delete-them-all thing, you don't end up with that or any of your otherwise-named Layouts retained, but it does get rid of all of those, and anything drawn in them, and then sticks a blank Layout1 back in so you don't have none of them.

Kent Cooper, AIA

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

Post to forums  

Autodesk Design & Make Report

”Boost