Author Topic: Delete all layouts?  (Read 4958 times)

0 Members and 1 Guest are viewing this topic.

KewlToyZ

  • Guest
Delete all layouts?
« on: November 30, 2007, 04:53:03 PM »
I'm just looking for the short and sweet bit of code for deleting all layouts from a drawing.
I see AutoCAD will still make a layout which is fine but I want to remove extra information from files to be used as XREF's

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Delete all layouts?
« Reply #1 on: November 30, 2007, 04:54:59 PM »
Code: [Select]
(vlax-for lo (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-Acad-Object)))
  (if (/= (vla-get-Name lo) "Model")
    (vla-Delete lo)
  )
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

KewlToyZ

  • Guest
Re: Delete all layouts?
« Reply #2 on: November 30, 2007, 06:18:23 PM »
Thanks Tim =)
I'll post my mess when I'm finished :-P

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Delete all layouts?
« Reply #3 on: November 30, 2007, 06:19:12 PM »
Thanks Tim =)
I'll post my mess when I'm finished :-P
Cool.  You're welcome.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

KewlToyZ

  • Guest
Re: Delete all layouts?
« Reply #4 on: November 30, 2007, 07:59:53 PM »
Hi Tim,

I'm missing something from a batch processing lisp routine you posted before.
I seem to keep breaking the thing :ugly:

Code: [Select]
;; To Batch Drawings As ZBase XREF's ......
;;
;; Note: replace the Path/filename below to call up your Lisp
;;       to process the drawings the way you want.
;;
;; Make sure your lisp program is in a 'support' folder ..
;; Setup to batch specific project drawing files and prevent any non illiterate from destroying a project


(autoload "mkxref" '("mkxref"))

(setq my_lisp_file "mkxref.lsp"); Place your specific lisp here !

;; Load Supporting Functions
;; Old Version of 'BrowseForFolder' by: Tony Tanzillo
(defun BrowseForFolder ( Message / sh folder parentfolder folderobject result)
 (vl-load-com)
  (setq sh
   (vla-getInterfaceObject
     (vlax-get-acad-object)
       "Shell.Application"
     )
   )


   (setq folder
      (vlax-invoke-method
          sh
          'BrowseForFolder
          0
          Message
          0
       )
   )
   (vlax-release-object sh)


    (if folder
      (progn
         (setq parentfolder
           (vlax-get-property folder 'ParentFolder)
         )
        (setq FolderObject
           (vlax-invoke-method
              ParentFolder
               'ParseName
              (vlax-get-property Folder 'Title)
           )
        )
       (setq result
          (vlax-get-property FolderObject 'Path)
       )
       (mapcar 'vlax-release-object
         (list folder parentfolder folderobject)
       )
     (if (/= (substr result (strlen result)) "\\")
       (setq result (strcat result "\\"))
       result
     )
   )
 )
); defun

(defun C:MAKEXREF ()
;; portions by Tim Willey
  (if (setq DirPath (BrowseForFolder "Select directory to batch drawings."))
   (progn
    (setq DwgList (vl-directory-files DirPath "*.dwg" 1))
    (setq ScrFile (strcat DirPath "batchme.scr"))
    ;(setq Ofil (open ScrFile "W"))
    (setq Ofil (open ScrFile "R"))
     (write-line "SDI 0" Ofil); Force Multi-Document mode
     (write-line (strcat "(setvar " (chr 34) "FILEDIA" (chr 34) " 0)") Ofil)


;; Check for specific project drawing names starting with "Z0001"..
;; Edit this line for your specific batch

     (foreach Dwg DwgList
      ;;(if (= (substr Dwg 1 5) "P0604")
       (progn
        (setq FullPath (strcat DirPath Dwg))
        (write-line (strcat "_.open " (chr 34) FullPath (chr 34)) Ofil)
        (write-line (strcat "(load " (chr 34) my_lisp_file (chr 34) ")") Ofil)
        (write-line (strcat "(setvar " (chr 34) "FILEDIA" (chr 34) " 1)") Ofil)
        (write-line "_.qsave" Ofil)
        (write-line "_.close" Ofil)
       ); progn
      ;;); if
     ); foreach
     (write-line (strcat "(setvar " (chr 34) "FILEDIA" (chr 34) " 1)") Ofil)
     (close Ofil)
     (command "_.script" ScrFile)
   ); progn
  ); if
 (princ)
); function
 (prompt "\nType MAKEXREF to begin the batch process:")
 (princ)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Delete all layouts?
« Reply #5 on: November 30, 2007, 08:54:18 PM »

Mr Z

How about a hint ?


kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Delete all layouts?
« Reply #6 on: December 01, 2007, 12:12:06 AM »
Here is one problem.
Code: [Select]
    ;(setq Ofil (open ScrFile "W"))
    (setq Ofil (open ScrFile "R"))
You can't write to a file when you open it for read.  The 'w' stands for 'write' and the 'r' stands for 'read', so switch the comment.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Delete all layouts?
« Reply #7 on: December 01, 2007, 01:54:41 AM »
 :wink:

I was going to let him cut his own bait.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Delete all layouts?
« Reply #8 on: December 01, 2007, 06:21:17 AM »
:wink:

I was going to let him cut his own bait.

Ah.  I'm sorry for messing up the teaching session.  Next time I will read into your message a little more.  :wink:
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

KewlToyZ

  • Guest
Re: Delete all layouts?
« Reply #9 on: December 03, 2007, 09:58:37 AM »
Just curious,
I didn't want to write to the file.
I am using an -exporttoautocad to create a new file with a pre-fix and removing AEC Objects?
This R prevents the lisp routine from doing the export?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Delete all layouts?
« Reply #10 on: December 03, 2007, 11:02:42 AM »
Just curious,
I didn't want to write to the file.
I am using an -exporttoautocad to create a new file with a pre-fix and removing AEC Objects?
This R prevents the lisp routine from doing the export?
What do you think my portion of the code is doing?
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

KewlToyZ

  • Guest
Re: Delete all layouts?
« Reply #11 on: December 03, 2007, 11:30:45 AM »
From what I can tell it is batching through the files and saving them on close.
It is loading the routine without actually calling the command from the loaded routine.

I assumed I could run commands aginst the file in memory without saving in read only?

I just needed to change the qsave line and check against the prompt for saving changes on close instead.
« Last Edit: December 03, 2007, 11:35:21 AM by KewlToyZ »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Delete all layouts?
« Reply #12 on: December 03, 2007, 11:38:08 AM »
From what I can tell it is batching through the files and saving them on close.
It is loading the routine without actually calling the command from the loaded routine.

I assumed I could run commands aginst the file in memory without saving in read only?

I just needed to change the qsave line and check against the prompt for saving changes on close instead.
All it is doing is writing the script file.  Then it calls the script command.  That is why you need to open the text file to write.  If you don't want it to save, then remove that line.  If you want to see if the drawing needs to be saved, and then answer the prompts correctly, look at the system variable 'dbmod'.  This will tell you if the drawing has been changed.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

KewlToyZ

  • Guest
Re: Delete all layouts?
« Reply #13 on: December 03, 2007, 01:42:20 PM »
Thanks for the smelling salts...
I was brain dead  :lmao:

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Delete all layouts?
« Reply #14 on: December 03, 2007, 01:48:42 PM »
Thanks for the smelling salts...
I was brain dead  :lmao:
That is what we are here for.  Sometimes even if you know how to fish..... one forgets the bait.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

KewlToyZ

  • Guest
Re: Delete all layouts?
« Reply #15 on: December 03, 2007, 02:45:14 PM »
I was wondering if you guys have a work around for 2008 and its tendency to go to an empty environment?
I was trying to do a new from template at the start of the process but it seems to stall out the process because the new file creates a new empty command set. This wasn't a problem in 2007.

KewlToyZ

  • Guest
Re: Delete all layouts?
« Reply #16 on: December 03, 2007, 03:10:12 PM »
Nevermind, I just added a (command "resume") to the lisp file I referenced.

I am curious if anyone else finds the 2008 nature to close out to an empty (no menus, no drawing) a major pain without really serving any purpose.
Everytime I network custom menus and it attempts to close out, the environment hangs up.
I used Etherreal to test against it but it would appear to just be something local that has it hang in memory rather than looking for a file. I just don't understand how this translates to a feature. If the drawing is closed there is no further use for the environment to be open?
« Last Edit: December 03, 2007, 04:06:02 PM by KewlToyZ »

deegeecees

  • Guest
Re: Delete all layouts?
« Reply #17 on: December 03, 2007, 04:32:14 PM »
I think AD elected to keep the AutoCad app running like that for certain situations, i.e. batch process's, SDI env., etc. Just my unschooled opinion.

KewlToyZ

  • Guest
Re: Delete all layouts?
« Reply #18 on: December 03, 2007, 11:05:29 PM »
Quote
Just my unschooled opinion.
LOL your on top of more than I sir!

I find a few batching utilities are stalling with it unless I open an additional window.
I'm suspicious it may be the MdiTab17.arx file that creates tabs for all of the files in the drawing environment.
I wish they would just integrate the feature into the CAD environment to begin with, but this may be the very reason they haven't.

KewlToyZ

  • Guest
Re: Delete all layouts?
« Reply #19 on: December 04, 2007, 05:54:34 PM »
I'm seriously missing something though when it comes to just doing a qnew at the start of a routine?
If I dont have an extra file open, the entire interface is super slow hanging when it tries to unload and reload the AEC libraries for the menus. Really a stupid process with MEP, hence why I felt the mepty envrionment kills and stalls batch processes so much.

If A new file opens it clears to a new command line history so it won't do it I guess????
Never ran into the need before now so I never knew an issue existed.

KewlToyZ

  • Guest
Re: Delete all layouts?
« Reply #20 on: December 06, 2007, 09:09:33 PM »
What is really kicking me in the head though?
It runs perfectly on Vista Ultimate, and gives me grief on XP!

I'll post a package in a few days when I finish it out.
That batch routine has been an awesome crutch, I have to thank Tim for it again!
So far it has allowed me to actually gain on general labor and productivity issues with client file handling.

We have had a great deal of grief with 2008 MEP and version conflicts.
The most honest thing I can say is that projects are being handled as CAD files so AEC removal has become a major crutch as well. Getting ADT 2005 projects has resulted in strange bug entity points being generated miles away from origin in the Z-Axis. So I AEC Export after setting all points in the Z axis to 0.

The major drawback to the routines is it replaces the initial Drawing1.dwg in memory on XP but doesn't in Vista. When this happens, every close of a file is trying to unload the menus and compile the cui/mnl files. Slows the entire process badly due to ABS.cui and all of our general customizations. I beleive it is a bug using the MdiTab17.arx file with 2008. If I do a new file from a template it stalls. So before I run the routine I have to open a qnew Drawing2.dwg. It sort of works....

I've been testing and refining for handling a more or less general formatting system to remove some guesswork and production failures by using some sugar for my users and taking the manual tasks out for a change.

The 2008 MEP Unreconciled Layers (bug/feature - who uses it?) issue is a major drawback but the batching utility lets me at least have a viable workaround. The work around let me apply more general formatting to try and smooth out the project work flow for the office. If I can actually get a few months out of it, I would be happy.
« Last Edit: December 06, 2007, 09:34:57 PM by KewlToyZ »