Jump to content

Looking Lisp for Splitting multiple layouts from multiple drawing files .


Recommended Posts

Posted

"I am searching for an AutoLISP routine to split multiple layouts into separate CAD files. I currently have a highly effective LISP script for performing this task individually. However, this time, I need a lisp to handle multiple CAD files.

I have approximately 50 drawing files, each containing 5 to 7  layouts with properly named project requirements (around 300 drawings) . Additionally, all files have up to 5 Xref files attached. To issue the final drawing to the client, I need to bind all the Xrefs and separate each layout into individual CAD files (300 binded drawings).

If there is an existing LISP routine for this activity, please provide it."

Posted

Can you post or reference the LISP you use now?

 

If that does what you need on each drawing, sounds like you just need to run it in a batch routine, is that correct?

  • Like 1
Posted
;;;
;;;    LayoutsToDwgs.lsp
;;;    Created 2000-03-27

;;; By Jimmy Bergmark
;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved
;;; Website: www.jtbworld.com
;;; E-mail: info@jtbworld.com
;;;
;;; 2003-12-12 Sets UCS to world in model space to avoid problem with wblock
;;;

;;;    For AutoCAD 2000, 2000i, 2002, 2004
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;   Creates drawings of all layouts.
;;;   Only one layout at a time is saved, the rest are deleted.
;;;   This is handy when you want to save to pre A2k versions.
;;;   The new drawings are saved to the current drawings path
;;;   and overwrites existing drawings.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:LayoutsToDwgs (/ fn path msg msg2 fileprefix)
  (defun DelAllLayouts (Keeper / TabName)
    (vlax-for Layout
                     (vla-get-Layouts
                       (vla-get-activedocument (vlax-get-acad-object))
                     )
      (if
        (and
          (/= (setq TabName (strcase (vla-get-name layout))) "MODEL")
          (/= TabName (strcase Keeper))
        )
         (vla-delete layout)
      )
    )
  )

  (vl-load-com)
  (setq msg "")
  (setq msg2 "")
  (command "._undo" "_BE")
  (setq fileprefix (getstring "Enter filename prefix: "))
  (foreach lay (layoutlist)
    (if (/= lay "Model")
      (progn
        (command "_.undo" "_M")
        (DelAllLayouts lay)
        (setvar "tilemode" 1)
        (command "ucs" "w")
        (setvar "tilemode" 0)
        (setq path (getvar "DWGPREFIX"))
        (setq fn (strcat path fileprefix lay ".dwg"))
        (if (findfile fn)
          (progn
            (command ".-wblock" fn "_Y")
            (if (equal 1 (logand 1 (getvar "cmdactive")))
              (progn
                (setq msg (strcat msg "\n" fn))
                (command "*")
              )
              (setq msg2 (strcat msg2 "\n" fn))
            )
          )
          (progn
            (command ".-wblock" fn "*")
            (setq msg (strcat msg "\n" fn))
          )
        )
        (command "_.undo" "_B")
      )
    )
  )
  (if (/= msg "")
    (progn
      (prompt "\nFollowing drawings were created:")
      (prompt msg)
    )
  )
  (if (/= msg2 "")
    (progn
      (prompt "\nFollowing drawings were NOT created:")
      (prompt msg2)
    )
  )
  (command "._undo" "_E")
  (textscr)
  (princ)
)

 

Posted (edited)

@Bijucad09

With a couple changes, this routine can be boiled down to run as a script in ScripPro or another Script Writer, by simply removing any interaction. just call this in a script, then close each drawing without saving.

You would make a script template with something like this:

(load "Layouts2Dwgs.lsp")
LAYOUTSTODWGS
_Close _n

 

Here is a slightly modernized, boiled-down version of Jimmey Bergmark's original version:

(defun c:LayoutsToDwgs (/ *error* ac cd dc DelLayouts dn dp f fn ls)
   (vl-load-com)

   (defun *error* (msg)
       (if cd (setvar "cmdecho" cd))
       (if f (command-s "._Undo" "_Back"))
       (princ msg)
   )

   (setq ac (vlax-get-acad-object)
         dc (vla-get-activedocument ac)
         ls (vla-get-layouts dc)
         dp (getvar "dwgprefix")
         dn (vl-filename-base (getvar "dwgname"))
   )

   (defun delLayouts (kp / l ln)
      (vlax-for l ls
         (setq ln (vla-get-name l))
         (if (and (/= ln "Model")(/= ln kp))
            (vla-delete l)
         )
      )
   )

   (vla-startundomark dc)
   (setq cd (getvar "cmdecho"))
   (setvar "cmdecho" 0)

   (foreach n (layoutlist)
      (if (/= n "Model")
         (progn
            (vla-Startundomark dc)
            (setq f T)
            (delLayouts n)
            (setq fn (strcat dp dn "-" n ".dwg"))
            (setvar "tilemode" 1)
            (command "._ucs" "_w")
            (setvar "tilemode" 0)
            (if (findfile fn)
               (command "._-wblock" fn "_y" "*")
               (command "._-wblock" fn "*")
            )
            (command "._Undo" "_Back")
         )
      )
   )

   (setvar "cmdecho" cd)
   (vla-EndUndomark dc)
   (princ)
)

 

Edited by pkenewell
Added a simple Error Handler
Posted

P.S. I just tested the routine with the freeware AutoScript, and it works without any issues. The only caveat is it works better if you add "Layouts2Dwgs.lsp" to APPLOAD before running the script to avoid the security dialog. That doesn't stop it however if you just select "Load Always" when the dialog pops up.

Posted (edited)

@Bijucad09 P.P.S. you can add the XREF bind command to the script as well if you can just Bind All or know the XREF names to bind.

(load "Layouts2Dwgs.lsp")
-XREF _B *
LAYOUTSTODWGS
_Close _n

There is also a routine posted HERE you can add to the script to bind xrefs and check for unresolved ones, Purge, Audit, etc.

Edited by pkenewell

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...