Message 1 of 18
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Ok so the code below is what I've got, but I'm sure there's a more efficient way.
What I want to do is count how many layouts are in a drawing and swap between the first and last layouts (no matter what they're called)
Also if it's not the first layout selected it needs to swap to that first.
The code below uses some variables from other code that people helped me with.
I'm using AutoCAD LT 2025
(defun c:ToggleFirstLastLayout ()
(vl-load-com)
;; (setq layoutNames '()) ; Initialize an empty list to hold layout names
(setq layouts (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-acad-object)))) ; Get all layouts
(setq listlayouts (layorder))
(setq firstLayout (car listlayouts)) ; Get the first layout
(setq lastLayout (last listlayouts))
(setq layoutCount (vla-get-Count layouts))
(setq numLayouts (vla-get-Count layouts))
(if (> numLayouts 1)
(progn
(setq currentLayoutName (getvar "CTAB")) ; Get current layout name
(if (= currentLayoutName (car listlayouts))
(progn
(command "_-LAYOUT" "SET" (last listlayouts)) ; Switch to last layout
)
(progn
(command "_-LAYOUT" "SET" (car listlayouts)) ; Switch to first layout
)
)
)
(princ "\nThere are less than two layouts (excluding ModelSpace).")
)
(princ)
)
Howard Walker
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Solved! Go to Solution.