ChrisCMU Posted April 30, 2009 Posted April 30, 2009 Does anybody know of a custom or built in way to re-order the layout tabs? I have a drawing with about 200 tabs in there (different site locations). I like to keep them alphabetical so I can find then when needed. Right now I have to drag the tab into it's proper place (which can be time consuming). I'd like to be able to automatically alphabetize them. In a somewhat related question, does anybody know how I could export all layout tabs (based on their current page setup) at once? I would prefer if it dropped the suffix and prefix (BTW, can you change these?) from the file name. The prefix is the drawing name and the suffix is the "(1)" it puts on there. I'd love to not have to delete that every time I export it. Quote
CmdrDuh Posted April 30, 2009 Posted April 30, 2009 I think it can be done, I seem to remember doing that a long time ago. Let me look through my code archive Quote
Lee Mac Posted April 30, 2009 Posted April 30, 2009 Couldn't resist: [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:sortlay [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] lst[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-for[/color][/b] lay [b][color=RED]([/color][/b][b][color=BLUE]vla-get-layouts[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-ActiveDocument[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-get-acad-object[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] lst [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] lay lst[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] lst [b][color=RED]([/color][/b][b][color=BLUE]vl-remove-if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]function[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]lambda[/color][/b] [b][color=RED]([/color][/b]y[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]eq[/color][/b] [b][color=#ff00ff]"Model"[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-Name[/color][/b] y[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] lst[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]function[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]lambda[/color][/b] [b][color=RED]([/color][/b]x[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-put-TabOrder[/color][/b] x [b][color=RED]([/color][/b][b][color=BLUE]1+[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-position[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-Name[/color][/b] x[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]acad_strlsort[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]vla-get-Name[/color][/b] lst[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] lst[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] Quote
ChrisCMU Posted May 1, 2009 Author Posted May 1, 2009 I get an error when running that: ; error: no function definition: VLAX-GET-ACAD-OBJECT Quote
lpseifert Posted May 1, 2009 Posted May 1, 2009 add this near the top (or add it to your acaddoc.lsp file) (vl-load-com) Quote
ChrisCMU Posted May 1, 2009 Author Posted May 1, 2009 thanks, that works great! Have any of you ever seen a way to do the export question I had? Quote
Lee Mac Posted May 1, 2009 Posted May 1, 2009 Sorry about that error Chris, I have (vl-load-com) in my ACADDOC.lsp, so I don't notice any problems if I have left it out - my apologies. When you say "export" layout tabs, what exactly do you mean? I can easily modify the Layout tab names, but I am not sure exactly what you want done with them Quote
ChrisCMU Posted May 1, 2009 Author Posted May 1, 2009 Sorry about that error Chris, I have (vl-load-com) in my ACADDOC.lsp, so I don't notice any problems if I have left it out - my apologies. When you say "export" layout tabs, what exactly do you mean? I can easily modify the Layout tab names, but I am not sure exactly what you want done with them Well, I have hundreds of layouts in my drawing. each one is named for the site they represent (these are well sites in a large field of hundreds of wells). An example of the layout name might be: "Echo_Springs_Federal_2_26" I want to be able to export all the layout tabs in the drawing with only using the layout name to a defined workspace. Currently when I export them to PDFs the default is: drawingname layoutname "(1)" I don't want the drawing name or the "(1)" appended to it. I've been trying to find a setting to fix that but I can't. any ideas? I thought of writing a script to strip the drawing name and the "(1)" off there, but it won't work because Autocad puts those spaces in there. And besides, I don't have the other part figured out either (to export them all at once). Quote
Lee Mac Posted May 1, 2009 Posted May 1, 2009 Ok, I understand about the layout names, but how do you export them? Excuse my AutoCAD ignorance, I am really only into the programming side and haven't actually used AutoCAD that much. Lee Quote
ChrisCMU Posted May 1, 2009 Author Posted May 1, 2009 I use the plot button/command and the name of the plotter is "Adobe PDF" In case it matters, the properties on all layouts are the same (size, orientation, etc). All those setting are saved within the layout though, so I doubt any of that would need to be included in any LISP. Quote
Lee Mac Posted May 1, 2009 Posted May 1, 2009 This might be useful to you: http://web2.airmail.net/terrycad/AutoLISP-Code.htm Top one ^^ Quote
CAB Posted May 1, 2009 Posted May 1, 2009 Another: ;; 07/14/2005 CAB (defun C:TabSort (/ cnt doc lay) (vl-load-com) (setq cnt 1 doc (vla-get-activedocument (vlax-get-acad-object)) ) (foreach lay (acad_strlsort (vl-remove "Model" (layoutlist))) (vla-put-taborder (vla-item (vla-get-layouts doc) lay) cnt) (setq cnt (1+ cnt)) ) (princ) ) Quote
CAB Posted May 1, 2009 Posted May 1, 2009 ;; --------------------------------------------------------------------------- ;; Function: tabsort ;; Purpose : sort Tabs by the prefix then the first numbers found ;; AUTHOR Charles Alan Butler @ TheSwamp.org ;; --------------------------------------------------------------------------- ;; Last Update 03/01/2006 CAB (defun C:TabSort (/ cnt doc lay) (vl-load-com) ;; --------------------------------------------------------------------------- ;; Function: Num_sort ;; Purpose : sort list of strings by the prefix then the first numbers found ;; AUTHOR Charles Alan Butler @ TheSwamp.org ;; Params : tablst: list of strings to sort ;; Returns : sorted list ;; --------------------------------------------------------------------------- (defun Num_Sort (tablst / tab ptr len loop tmp tmp2 sub lst) (defun vl-sort-it (lst func) (mapcar '(lambda (x) (nth x lst)) (vl-sort-i lst func)) ) (defun sort2 (tmp2 sub) (setq tmp2 (append (vl-sort-it sub '(lambda (e1 e2) (< (cadr e1) (cadr e2)))) tmp2 ) ) ) ;; convert to a list (string) -> (prefix num string) (foreach tab tablst (setq ptr 1 len (strlen tab) loop t ) (while loop (cond ((wcmatch "0123456789" (strcat "*" (substr tab ptr 1) "*")) (setq tmp (cons (list (substr tab 1 (1- ptr)) (atof (substr tab ptr)) tab ) tmp ) loop nil ) ) ((> (setq ptr (1+ ptr)) len) ;; no number in string (setq tmp (cons (list tab nil tab) tmp) loop nil ) ) ) ; end cond stmt ) ) ;; sort on the prefix (setq tmp (vl-sort-it tmp '(lambda (e1 e2) (< (car e1) (car e2))))) ;; Do a number sort on each group of matching prefex (setq idx (length tmp)) (while (> (setq idx (1- idx)) -1) (cond ((not sub) (setq sub (List (nth idx tmp)) str (car (nth idx tmp)) ) ) ((= (car (nth idx tmp)) str) ; still in the group (setq sub (cons (nth idx tmp) sub)) ) ) ; end cond stmt (if (= idx 0) ; end of list (progn (setq tmp2 (sort2 tmp2 sub)) (if (/= (car (nth idx tmp)) str) (setq tmp2 (append (list (nth idx tmp)) tmp2)) ) (setq str (car (nth idx tmp))) ) ) (if (/= (car (nth idx tmp)) str) ;; next group, so sort previous group (setq tmp2 (sort2 tmp2 sub) sub (list (nth idx tmp)) str (car (nth idx tmp)) ) ) ) ; end while (setq lst (mapcar 'caddr tmp2)) (princ) lst ) ; end defun ;;========================================================================== (setq cnt 1 doc (vla-get-activedocument (vlax-get-acad-object)) ) (foreach lay (num_sort (vl-remove "Model" (layoutlist))) (vla-put-taborder (vla-item (vla-get-layouts doc) lay) cnt) (setq cnt (1+ cnt)) ) (princ) ) ; end defun (prompt "\nTabSort loaded, enter TabSort to run.") (princ) Quote
Lee Mac Posted May 1, 2009 Posted May 1, 2009 Nice CAB. Just goes to show what they say about coding these things - its all been done before Quote
ChrisCMU Posted May 1, 2009 Author Posted May 1, 2009 This might be useful to you: http://web2.airmail.net/terrycad/AutoLISP-Code.htm Top one ^^ I'm having a hard time figuring out how to configure things right. It says to: "Change the following global lists *PlotterInfo@ and *PlotStyles@ to suit the specifications of each AutoCAD department" Where are those lists? sorry, I'm a little lost. Quote
ChrisCMU Posted May 1, 2009 Author Posted May 1, 2009 add this near the top (or add it to your acaddoc.lsp file) (vl-load-com) When I had 2007 I could find that file in the programs folder. Now I have 2010 and I cannot find it anywhere. If I do a windows search it does not show up (even including hidden files). I see "acad2010.lsp" and "acad2010doc.lsp" but the help file says you should not edit the second one for whatever reason: Warning: Do not modify the reserved acad2010doc.lsp file. Autodesk provides the acad2010doc.lsp file, which contains AutoLISP-defined functions that are required by AutoCAD. This file is loaded into memory immediately before the acaddoc.lsp file is loaded. I thought maybe they got rid of the acaddoc.lsp and just want you to change the ACADLSPASDOC setting to load the regular one on start up. But then it says this in the help file (in addition to mentioning it above): The acaddoc.lsp file is intended to be associated with each document (or drawing) initialization. This file is useful if you want to load a library of AutoLISP routines to be available every time you start a new drawing (or open an existing drawing). So that file must exist still. how come I can't find it? Quote
lpseifert Posted May 1, 2009 Posted May 1, 2009 The acaddoc.lsp does not come with the installation of Acad. It's just a text file easily created with Notepad. Quote
Lee Mac Posted May 2, 2009 Posted May 2, 2009 Just create an ACADDOC.lsp with Notepad (save it as a .lsp file and put it in your search path file) Quote
Recommended Posts
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.