Author Topic: Delete all layouts?  (Read 4959 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.