Export layout to model AutoCAD LISP

© Corel Corporation. All rights reserved. The content herein is in the form of a personal web log ("Blog") or forum posting. As such, the views expressed in this site are those of the participants and do not necessarily reflect the views of Corel Corporation, or its affiliates and their respective officers, directors, employees and agents. Terms of Use / Privacy​ ​/ ​Cookies / Terms and Conditions / User Guidelines.

We have a few clients that on occasion will need separate drawings for each layout we have in our drawings. It's time consuming to File>Save As for each drawing needed and then go in each new drawing and delete the unnecessary layout tabs. There are LISP routines out there that do just what we need. Could functionality be added to Land/FX to address this? Thanks!

(LISP example - http://jtbworld.com/autocad-export-layouts-to-drawings-layoutstodwgs-lsp)

Jon,

That is something that is already on our radar, as it is something we need in the drawing cleanup process. This is definitely an interesting and novel solution. I would rewrite it using Export instead of WBlock, and it currently is not compatible with non-English installations. Oh, and it does need some more careful error handling through the operation (it's not confirming that the save was successful).
In the meantime, we do recommend setting up your projects with a single sheet per drawing. I would also be curious if the "Export Layout to Model" feature would satisfy your needs in the interim?

--J

Heya,

I find that 'export layout to model' just doesn't work.

My work around is thus;

Publish the wanted layout to a .pdf, either the entire set of layouts/drawings or as a single one. 

Open a new drawing and use 'pdfimport' command & right click 

Navigate to said pdf.

Select sheet/layout in question.

ok

wait.......blue bar at bottom right can move slowly.

Then modify drawing as required - check any scaling issues that may arise. nuke. purge etc.

save as.

Would love a function for this purpose.

Cheers

Jobe

Joby,

That's interesting.  Another user also brought to our attention the incredible Lee Mac tool, Steal:

http://www.lee-mac.com/steal.html

It is still on our radar to address this, but has certainly been deprioritized due to it being such a seldom needed task.

--J

Thanks Captain J

I may give that a trial next time i've the need for 'stealing' a layout.

:)

Hi Jon,

There's the "Save Layout as Drawing" command under "Save As" (or_exportlayout) already built into AutoCAD that does what you're describing. I've used it a could of times and it works great.

Tim

  • Page :
  • 1

There are no replies made for this post yet.
Be one of the first to reply to this post!

Since AutoCAD 2009, we have had the ability to export a single layout to a new model space drawing. (CAD Tip No. 3100 is all about this process.) This routine by Amir Hossein Sattarian allows you to export multiple layouts to individual DWG files automatically. After you load the LISP file, run the command LXA and the LISP code will do the rest. Each layout will be exported to a separate DWG file. The DWG files will be located in a new subfolder of the current drawing's folder named "Layouts." The LISP code actually writes a script file, then loops the calls to the built-in ExportLayout command.

Often I need to create a useable DWG file for customers.  The problem is we use xrefs for our drawings, so a file save as doesn’t work because the source file is still linked and can’t be exploded.  However, by using the Export Layout to Model command, it just takes a few steps to create a useable DWG for my customer. 

  1. Open file that contains the xref.
  2. Pick file.
  3. Select Export Layout to Model.
  4. Save to desktop (this takes a bit of time to process).
  5. New window will open asking if you want to open the new drawing.

I don’t know when this feature came out, but it sure has helped a lot. A big improvement on what was once a time-consuming process using a finicky AutoLISP routine and often ending up basically redrawing the print.

Notes from Cadalyst tip reviewer R.K. McSwain: This is more or less a repeat of Tip #3100, but Jeanie's tip here emphasizes that external references are bound to the main drawing during this process. This is an important feature of this process that should not be overlooked.

About the same thing we do.
I use these Export routines to create our backgrounds and automate as much as possible.
One of those things you want to click and go get a cup of coffee, come back, you have a background file.
Depends completely on how complex the project is though.
Including the original filename helps people a year or so later still find out how to update the project even if they didn't set it up.

;;; Create an exported Zbase-xref file from architectural files
(DEFUN c:zbx()
;====================================================================== Turn on command line responses
(setvar "CMDECHO" 0); DO NOT CHANGE THIS LINE
;======================================================================
;(alert "This routine creates an exported bound version of all the files in the directory you select!")

(command "TILEMODE" 1)
(command "Zoom" "Extents")
(command "Undo" "Begin")
;======================================================================
(autoload "zxv" '("zxv"))
(c:ZXV)

;====================================================================== Delete Page Setups & Set Plot Style to KTA.ctb
(prompt "\n   Delete Old Page Setups !!!")
(autoload "dps" '("dps"))
(c:dps)
(princ "\n   All Layouts Deleted!")
(princ)

;======================================================================

(prompt "\n Detach All Image References.....")
(autoload "ix" '("ix"))
(c:ix)

;======================================================================

(princ "\n   Standard KTA drawing variables initiated!!")
(command "-style" "Standard" "archquik.shx" "0" "1" "0" "No" "No")
(princ "\n   Archquik.shx is the Standard font!")
(princ)
;====================================================================== Control Line Scaling
(command "PSLTSCALE" 0)
(command "MSLTSCALE" 0)
;======================================================================
(princ "\n   MSpace & PSpace LTScale Varaibles set to 0!! \n Defaults to LTSCALE settings now!")
(princ)

;====================================================================== Layer setups for backgrounds
(prompt "\n   Thawing and Showing all layers.")
(command "layer" "t" "*" "on" "*" "u" "*" "")
(command "Zoom" "Extents")
(command "regenall")

;======================================================================
(prompt "\n   XREF binding begins!")

(prompt "\n   BINDTYPE set to Insert for all XREF's!")
    (command "BINDTYPE" 1)
;(autoload "XRB" '("XRB"))
;(c:XRB)

(autoload "XRBIND" '("XRBIND"))
(c:XRBIND)
;======================================================================
;(prompt "\n   Re-Load All XREF's as a precaution........")
;(autoload "rax" '("rax"))
;(c:rax)
;======================================================================
(princ "\n   All XREF's Re-Loaded!!")

;======================================================================

(prompt "\n   Set Layer 0 as current Layer.")
(command "_.layer" "s" "0" "")

;======================================================================
(autoload "repair" '("repair"))
(c:repair)
;======================================================================
(princ "\n   Standard KTA drawing variables Loaded!!")

;======================================================================
(princ "\n   Setting All Objects & Entities to ByLayer!!!!!!")
(command "setbylayer" "all" "" "yes" "yes")
(command "chprop" "all" "" "c" "bylayer" "")

(autoload "mkbylayer" '("mkbylayer"))
(c:mkbylayer)

;======================================================================
(princ "\n   Setting all DimStyles ByLayer......")
(autoload "DS2BL" '("DS2BL"))
(c:DS2BL)
;======================================================================
(princ "\n   All Possible Objects, DimStyles, Lines, Arrows, & Text set to ByLayer!!")

;====================================================================== Layer setups for backgrounds

(autoload "MAKE8" '("MAKE8"))
(c:MAKE8)
(prompt "\n   All Layers Made Color 8 Grey !!!")

(command "_.layer" "c" "7" "DEFPOINTS" "")
(prompt "\n   Layer Defpoints Color is White!")

(autoload "hatch29" '("hatch29"))
(c:HATCH19)

(autoload "LRD" '("LRD"))
(c:LRD)
(alert "\n All KTA NCS Layer names (if present) set to proper colors & descriptions!!!")
;(autoload "8" '("8"))
;(c:8)

;(autoload "19" '("19"))
;(c:19)

;======================================================================
(command "regenall")
(prompt "\n   Layer colors completed !!!")

;======================================================================
(prompt "\n   Setting All 3-D Items to zero height in Z-Axis!!! ---Please be patient---")
(defun z-zero (/ a ss len e o10 l10 n10 f o11 l11 n11 o39 n39)
(setq a 0)
(princ "\n   Changes entities' z-coordinate to 0 (2D from 3D)." )
(setq ss (ssget "_X" ))
(setq len (sslength ss))
(repeat len
(setq e (entget (ssname ss a)))
(setq o10 (assoc 10 e))
(setq l10 (list (cadr (assoc 10 e)) (caddr (assoc 10 e)) 0.0))
(setq n10 (cons 10 l10))
(setq f (subst n10 o10 e))
(entmod f)
(setq a (1+ a))
);end repeat

(setq a 0)
(repeat len
(setq e (entget (ssname ss a)))
(setq o11 (assoc 11 e))
(setq l11 (list (cadr (assoc 11 e)) (caddr (assoc 11 e)) 0.0))
(setq n11 (cons 11 l11))
(setq f (subst n11 o11 e))
(entmod f)
(setq a (1+ a))
);end repeat

(setq a 0)
(repeat len
(setq e (entget (ssname ss a)))
(setq o39 (assoc 39 e))
(setq n39 (cons 39 0))
(setq f (subst n39 o39 e))
(entmod f)
(setq a (1+ a))
);end repeat

)
;======================================================================
(z-zero)
;======================================================================

;(prompt "\n Normal Detach of all XREF's not found!")
; (command "-xref" "Detach" "*")

;(prompt "\n Selecting ALL Object's!")
(command "SELECT" "ALL" "")

  ;(prompt "\n Exploding New Blocks of these XREF Object's!")
; (command "EXPLODE" "LAST" "")

;======================================================================
;(princ "\n   Objects in audit phase. Please be patient......")
;(command "audit" "y")
;(command "qsave")

;======================================================================
(princ "\n   Purging empty file entries.......")
(c:purgeall)
(princ "\n")
;(command "saveas" "2007" "" "y")
(princ "\n   File Purge Complete !!!!!!......")

;============================================== begin file name structure
(setq myPath (getvar "DWGPREFIX"))
(princ "\n   Current File Path : ")
(princ myPath)

  (setq myFile (getvar "DWGNAME"))
(princ "\n   Current File Name : ")
(princ myFile)

 (princ "\n   Stripped File Name : ")
(setq strippedFile (vl-filename-base myFile))
(princ strippedFile)

(princ "\n   File Prefix :")
(setq newPrefix (strcase "ZBaseBND-"))
(princ newPrefix)

(princ "\n   File Extension :")
(setq newExtension (strcase ".dwg"))
(princ newExtension)

(setq newName (strcat newPrefix strippedFile newExtension))
(princ "\n   New file name : ")
(princ newName)

(setq newFile (strcat myPath newName))
(princ "\n   New file to Open :\n")
(princ newFile)

(princ "\n   continue to Export.....\n")

(alert "
\n *-----------------------    AEC Objects will be removed.    --------------------------*
\n 1.) XREF's have been bound.
\n 2.) You will find your file with the 'ZBaseBND-' as the prefix in the filename.
\n 3.) File will be opened for you after clicking OK and export is complete.
\n 4.) You have just made a KTA Bound XREF for project use.
\n 5.) You may need to Burst the XREF's that are now Blocks in the file.
\n 6.) Cleanup any unnecessary items.
\n 7.) If MTEXT Objects have not adopted KTA's background colors, \n     run the StripMText command. Follow the prompts.
\n 8.) Use the MKB command to fix any other colors not 8 or 19.
\n 9.) This file will undo all changes before saving and closing."
)

;========================================== Begin Export Function
;(command "-exporttoautocad")
;(command "Format" "2007")
;(command "Prefix" "ZBaseBND-")
;(command "Suffix" ".")
;(command "T")
;(command "Insert")
;(command "Bind" "Yes" "" "")

(defun myExport07()
(princ "\n   Begin 2007 -ExportToAutoCAD functions :\n")
(command "-exporttoautocad")
(command "Format" "2007")
(command "T")
(command "Insert")
(command "Prefix" "ZBaseBND-")
;(command "Suffix" ".")
(command "Bind" "Yes" "" "")
(princ)
)

(defun myExport08()
(princ "\n   Begin 2008 -ExportToAutoCAD functions :\n")
(command "-exporttoautocad")
(command "Format" "2007")
(command "T")
(command "Insert")
(command "Prefix" "ZBaseBND-")
;(command "Suffix" ".")
(command "Bind" "Yes" "" "")
(princ)
)

(defun myExport()
(princ "\n   Begin 2010 -ExportToAutoCAD functions :\n")
(command "-exporttoautocad")
(command "Format" "2007")
(command "Prefix" "ZbaseBND-")
(command "Suffix" ".")
(command "T")
(command "Insert")
(command "Bind" "Yes" "" "")
(princ)
)
;============================== AutoCAD 2007 =====================================
; ACADVER = "17.0s (LMS Tech)"
;(if (= (vlax-product-key) "Software\\Autodesk\\AutoCAD\\R17.0\\ACAD-5001:409")
(if (= (getvar "ACADVER") "17.0s (LMS Tech)")
(myExport07)
(princ)
) ;End If

; ACADVER = "17.1s (LMS Tech)"
;============================== AutoCAD MEP 2008 =================================
; ACADVER = "17.2s (LMS Tech)"
;(if (= (vlax-product-key) "Software\\Autodesk\\AutoCAD\\R17.2\\ACAD-7006:409")
(if (= (getvar "ACADVER") "17.1s (LMS Tech)")
(myExport08)
(princ)
) ;End If

;============================== AutoCAD MEP 2009 =================================
; ACADVER = "17.2s (LMS Tech)"
;(if (= (vlax-product-key) "Software\\Autodesk\\AutoCAD\\R17.2\\ACAD-7006:409")
(if (= (getvar "ACADVER") "17.2s (LMS Tech)")
(myExport)
(princ)
) ;End If

;============================== AutoCAD MEP Acad 2010 =================================
; ACADVER = "17.2s (LMS Tech)"
;(if (= (vlax-product-key) "Software\\Autodesk\\AutoCAD\\R17.2\\ACAD-7006:409")
(if (= (getvar "ACADVER") "18.0s (LMS Tech)")
(myExport)
(princ)
) ;End If

;============================== AutoCAD MEP 2010 =================================
; ACADVER = "17.2s (LMS Tech)"
;(if (= (vlax-product-key) "Software\\Autodesk\\AutoCAD\\R17.2\\ACAD-7006:409")
(if (= (getvar "ACADVER") "18.1s (LMS Tech)")
(myExport)
(princ)
) ;End If

;=================================== Undo & save to leave original file as found

(princ "\n   Begin to return file to original state :\n")
(command "Undo" "End")
(command "Undo" "Back" "Y")
(command "saveas" "2007" "" "y")
;(command "qsave")
;===================================
(princ "\n   Locating New file to Open :\n")
(if (= (findfile newFile) nil)
(alert "\n Could not locate file.")
) ; end if

(defun OpenFile ()
(vla-open
(vla-get-documents
(vla-get-application (vlax-get-acad-object))
)
newFile
)
) ;_defun

(OpenFile)
;====================================================================== Turn on command line responses
(setvar "CMDECHO" 1); DO NOT CHANGE THIS LINE
;======================================================================

(princ "\n   File open successful!!")
(command "close")
)