You are here:

AutoCAD/Autolisp program for multiple commands on multiple layouts

Advertisement


Question
Okay.. here is what I need to do.  Rusty and limited on my autolisp.  I have several drawings with multiple layouts (10 or 12 each) and I need to run the same 4 or 5 commands on each layout.  How do I write an autolisp program that will find all the layouts and run the commands (I can write the lisp for the commands, just not sure how to find the layouts and tell it to run these commands then go to the next layout).  Any help would be appreciated.


Thanks,

Floyd Waltman

Answer
I got some help on this one.  Devitg (somehow, that's his name) suggested this long version of code that will work, one of which is applied to a routine:
(vl-load-com)

(setq acad* (vlax-get-acad-object)) ;_ el programa ACAD

(setq adoc (vla-get-activedocument acad*)) ;_ el DWG que esta abierto

(setq layouts-coll (vla-get-layouts adoc));_ the layouts at the dwg





(vlax-for layout layouts-coll

(print(setq lay-name (vla-get-name layout)))

)


or this one could give more help


(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")

(setvar "cmddia" 0)

(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")
(setq msg2 (strcat msg2 "\n" fn))
)
(progn
(command ".-wblock" fn "*" "Y")
(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)
)
)
(setvar "cmddia" 0)
(command "._undo" "_E")
(textscr)
(princ)
)

Another user who calls himself drago2dmax had the following suggestion:

(foreach x (layoutlist)(setvar "ctab" x)(function1)(function2)(functionn)))

On the 2nd one, my question would be, "Is layoutlist a core AutoLISP function?  I don't think so.  My computer is in the shop today (hopefully it will be ready this afternoon), so I won't be able to test anything myself until I get it back.  In order to get the list of layouts, you're probably going to need the activex method shown above in the routine shared by the first user.  Without that, even though the LAYOUT command gives you a (?) option to list the layout names, saving that list as an autolisp symbol can be problematic.  So, try the VLISP (or ActiveX) method and let me know how it goes.



Added 9-19-09
And Thank you, too for your kind words, even though I was wrong about layoutlist.  When I gave you my first answer, about that, I was shooting from the hip without AutoCAD being available because my computer was in the shop.  But LAYOUTLIST is a core AutoLISP command in AutoCAD and verticals.  It makes the whole job a lot easier.


Bill DeShawn
http://my.sterling.net/~bdeshawn

AutoCAD

All Answers


Answers by Expert:


Ask Experts

Volunteer


Bill DeShawn

Expertise

I can address all 2-D questions and some 3-D questions. I do programming in AutoLISP if it doesn`t involve solid modeling. I can also address menu customization issues and can help you find answers to questions I can`t answer by taking your question directly to Autodesk via their newsgroups.

Experience

I used to do electronic and mechanical design for a flat panel monitor manufacturer, and now I do architectural drafting for an architect. I did and do AutoLISP and menu customization and take pride in making my lisp routines to do the work exactly the way the client likes them done.

Publications
I had a routine published in CADENCE magazine (no longer in publication and taken over by CADALYST). Some of my routines are published on my website at http://my.sterling.net/~bdeshawn

©2012 About.com, a part of The New York Times Company. All rights reserved.