Creating a Layout using Visual LISP in AutoCAD

by Fenton Webb

Here’s a nice example that shows how to add a Layout using Visual LISP. It also shows how to set a Plot Style configuration and the Paper Size, and then make the new Layout active…

(defun c:addMyLayout ()

  (vlloadcom)

  (setq acadApp (vlaxgetAcadobject))

  (setq acadDoc (vlagetActiveDocument acadApp))

  (setq layouts (vlagetLayouts acadDoc))

 

  ;; Delete the layout named "Test" if it exists

  (vlaxfor objLayout layouts

    (if (= (vlagetname objLayout) "Test")

      (progn

        (princ

          (strcat "\nDeleted Layout named "

              (vlagetname objLayout) "…"

          )

        )

        (vladelete objLayout) ;delete the Layout

        (vlaxreleaseobject objLayout) ; release the Layout Object

      );progn

    );if

  ) ;vlaxfor

 

  (setq layoutObj (vlaadd layouts "Test"))

 

  ;; Assign Grayscale.CTB to the Layout

  (vlaputStyleSheet layoutObj "Grayscale.ctb")

 

  ;; Assign DWF configuration to the Layout

  (if (= (substr (vlaxvariantvalue (vlagetvariable acadDoc "ACADVER")) 1 2) "15")

    (vlaputconfigname layoutObj "PublishToWeb DWF.pc3")

    (vlaputconfigname layoutObj "DWF6 ePlot.pc3")

  ) ;if

 

  ;; Assign Paper Size B to the Layout  

  (vlaputcanonicalmedianame

    layoutObj

    "ANSI_expand_B_(11.00_x_17.00_Inches)"

  )

 

  ;; Make the new Layout Active

  (vlaputactivelayout acadDoc layoutObj)

 

  ;; Example getting StyleSheet and Configname, not doing anything

  ;; with them here however

  (setq currPStyle (vlaGetStyleSheet layoutObj))

  (setq currConfig (vlaGetconfigname layoutObj))

  (princ)

)

 


Comments

3 responses to “Creating a Layout using Visual LISP in AutoCAD”

  1. Irné Barnard Avatar
    Irné Barnard

    Much more elegant and efficient version here:
    http://www.theswamp.org/index.php?topic=42101.0

  2. Thanks for this great example
    I am wondering if there an exampl to import layout from existing drawing?
    Thanks

  3. Thnks,
    could this be a more detailed lisp routine by creating /drawing custom paper sizes layouts.
    We hope from you to write a lisp that could initiate a Template layout for the most common paper sizes like A4,A3,A2,A1, A0 by drawing a rectangle frame with the Exact size of paper.

Leave a Reply to SalamaCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading