
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello
I am trying to create a Lisp that renames the existing layouts in a drawing according to the following logic:
- If the drawing has only one layout, rename it as the name of the drawing file.
- If there are two or more layouts, rename them as name of the file (1), name of the file (2)... in the order that they have in the current drawing (left to right), which may not be alphabetical.
I.E. A drawing called "MyDrawing" with one layout called "MyLayout" would have it renamed as "MyDrawing", whereas a drawing called "MyDrawing2" with three layouts named, in this order "D_Layout" "A_Layout" "B_Layout" will have them renamed as "MyDrawing2 (1)" /previously "D_Layout"/, "MyDrawing2 (2)" /previously "A_Layout"/ and "MyDrawing2 (3)" /previously "B_Layout/.
As a complete noob, going through the forums, I managed to find the solution for the simple case:
(setq Q (length (layoutlist)))
( if (= 1 Q)
(command "_-layout" "_rename" "" (vl-filename-base (getvar "dwgname")))
)
I have seen that getting the layouts in left to right order is not such an easy task. I have tried to merge the suggestion given here
in the else condition of the If, but I dont manage to make it work. I think it would look something like this:
(setq Q (length (layoutlist)))
( if (= 1 Q)
(command "_-layout" "_rename" "" (vl-filename-base (getvar "dwgname"))) ;True condition
(
(vl-load-com) (vlax-for layt (vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object))) (if (> (vla-get-TabOrder layt) 0) (setq layt_lst (cons (cons (vla-get-TabOrder layt) (vla-get-Name layt)) layt_lst)) ) ) (setq layt_lst (vl-sort layt_lst '(lambda (x y) (< (car x) (car y))))) (foreach layt layt_lst (setq layoutname (cdr layt))
; Do the layout name change
) ;Else condition of if
) ;if
Could anyone help me a bit? I don't know if the approach for going through the layouts is the more appropiated for my case, but all the codes in the forum seem a bit too high level for me, so I chose the one that looked the simplest.
Thank you very much.
Best regards
Solved! Go to Solution.