mhupp Posted October 29 Posted October 29 Another tip if your setting multiple variables. You can handle them with 4 lines of code. (defun C:lnze (/ lyt) ;(setq oldEcho (getvar "CMDECHO") ; oldNOMUTT (getvar "NOMUTT") ; lyt (getvar "CTAB") ;) (setq vars '(cmdecho nomutt ctab) ;list of variables as many as you want. vals (mapcar 'getvar vars) ;store old values to a list ) ;(setvar 'CMDECHO 0) ;(setvar 'NOMUTT 1) (mapcar 'setvar vars '(0 1)) ;this sets cmdecho 0 and nomutt 1, stops at short list so ctab isn't changed. (vl-catch-all-apply '(lambda () (foreach lay (layoutlist) (setvar 'CTAB lay) (setvar 'CVPORT 1) (vl-cmdf "_.ZOOM" "_E") ) ) ) ;(setvar "CTAB" lyt) ;(setvar "CMDECHO" oldEcho) ;(setvar "NOMUTT" oldNOMUTT) (mapcar 'setvar vars vals) ;restore old values (princ) ) Quote
Paul Li Posted October 29 Posted October 29 38 minutes ago, ronjonp said: Side topic but I've found that this: (setq ss (ssget "_X" '((0 . "VIEWPORT") (-4 . "!=") (69 . 1)))) Does not work with layouts that are not initialized. CAB at TheSwamp put this together many moons ago and it's been solid ( don't remember what the function was originally named ) (defun rjp-getvports (/ a b c lst ss) (if (setq ss (ssget "_X" '((0 . "VIEWPORT")))) (progn (foreach e (mapcar 'cadr (ssnamex ss)) ;;Paper space block (if (and (setq a (cdr (assoc 330 (entget e)))) ;;Layout (setq b (cdr (assoc 340 (entget a)))) ;;Viewport not wanted (setq c (cdr (assoc 331 (entget b)))) ) (or (equal c e) (setq lst (cons (list e (cdr (assoc 71 (entget b)))) lst))) ) ) ) ) ;;Sort the list by taborder L 2 R (mapcar 'car (vl-sort lst (function (lambda (x y) (< (cadr x) (cadr y)))))) ) @ronjonp When I first open the sample TrueViewports.dwg I shared in a previous post which defaults to Layout2 and I run (length (rjp-getvports)) I get 7. Even after initializing by clicking on Layout1. I still get 7. But after clicking on Layout2 when I run @DavidP code I get 6: (sslength(setq ss (ssget "_X" '((0 . "VIEWPORT") (-4 . "<>") (69 . 1) (410 . "~Model"))))) Likewise when I run my code I posted earlier I also get 6: (sslength (ssget "_X" '((0 . "VIEWPORT") (67 . 1) (-4 . "/=") (69 . 1)))) I think mine & @DavidP code is similar. But what I don't see is whether @DavidP code is filtering out something more than compared to mine. Quote
BIGAL Posted October 29 Posted October 29 Just a comment using Bricscad only finds. D05 (sslength (ssget "_X" '((0 . "VIEWPORT") (67 . 1) (-4 . "/=") (69 . 1)))) returns 4 D03 = 4 D05 (sslength (setq ss (ssget "_X" (list (cons 0 "VIEWPORT") (cons 410 (getvar 'ctab)))))) returns 1 ie no normal viewports D03 = 2 a pspace and 1 viewport The order of SS is Viewport...Viewport Pspace may be different in Acad. I copied viewports for testing. Then erased one by one using (ssname ss X) can not erase pspace of course. 1 Quote
DavidP Posted October 30 Author Posted October 30 3 hours ago, Paul Li said: @ronjonp When I first open the sample TrueViewports.dwg I shared in a previous post which defaults to Layout2 and I run (length (rjp-getvports)) I get 7. Even after initializing by clicking on Layout1. I still get 7. But after clicking on Layout2 when I run @DavidP code I get 6: (sslength(setq ss (ssget "_X" '((0 . "VIEWPORT") (-4 . "<>") (69 . 1) (410 . "~Model"))))) Likewise when I run my code I posted earlier I also get 6: (sslength (ssget "_X" '((0 . "VIEWPORT") (67 . 1) (-4 . "/=") (69 . 1)))) I think mine & @DavidP code is similar. But what I don't see is whether @DavidP code is filtering out something more than compared to mine. I assuming "<>" and "/n" filter produce the same result as they both mean "not equal" (assuming lisp supports both syntax) Filter 410 . "~Model" may depend whether you have model space view ports or not. If you omit it and have no view ports in model space then the result should be the same. Regarding the codes I don't believe they are consistent, I did notice if its off screen we get -1 but not always but I haven't done enough testing to come to a conclusion. Looping through the layouts is the only thing I found that makes the codes predictable. I may test in BricsCad the morning to see how it behaves (if it supports the code as is). Quote
Paul Li Posted October 30 Posted October 30 FYI: my (67 . 1) filters out model space vports so only paper space vports will be selected. 1 Quote
DavidP Posted October 30 Author Posted October 30 BricsCAD reports the correct number of view-ports without requiring looping through the layouts first. Quote
SLW210 Posted October 30 Posted October 30 I have a Zoom Extents in Modelspace and Zooms Extents, then .9x in all layouts, it helps with the offset AutoCAD puts on some drawings when opening them, plus works for finding odd paperspace items, zooms just a little more to show the edges. Still trying to determine what is wrong with Lee Mac VPOUTLINE LISP? Are you looking for a count of true viewports? I have a LISP that gives this report of true viewports in all layouts, as well as places a border in modelspace and creates/checks for my viewport layer. ====================================== AutoVPBrdr REPORT ====================================== True layout viewports: 5 Viewport layer assignments: 5 Layer assignment failures: 0 Modelspace borders created: 5 Viewports skipped: 0 -------------------------------------- Layer: Viewport Color: 45 Plot: OFF ====================================== It only places a border for a viewport referencing Top/Plan view. 1 1 Quote
mhupp Posted October 30 Posted October 30 (edited) 7 hours ago, Paul Li said: FYI: my (67 . 1) filters out model space vports so only paper space vports will be selected. Yeah fig so just left 410 in there to be safe. Edited October 30 by mhupp Quote
ronjonp Posted October 30 Posted October 30 Here's another without command calls: (defun c:zal (/ a d c tabs) ;; RJP » 2020-07-08 (setq c (getvar 'ctab)) (vlax-for x (vla-get-layouts (setq d (vla-get-activedocument (setq a (vlax-get-acad-object))))) (setq tabs (cons (list (vla-get-name x) (vla-get-taborder x)) tabs)) ) ;; The sort makes sure that the tabs step left to right (foreach x (cdr (vl-sort tabs '(lambda (r j) (< (cadr r) (cadr j))))) (setvar 'ctab (car x)) (vlax-put d 'mspace 0) (vla-zoomextents a) ) (setvar 'ctab c) (princ) ) 3 Quote
Steven P Posted October 30 Posted October 30 7 hours ago, SLW210 said: I have a Zoom Extents in Modelspace and Zooms Extents, then .9x in all layouts, it helps with the offset AutoCAD puts on some drawings when opening them, plus works for finding odd paperspace items, zooms just a little more to show the edges. These are ones I use: To record the current zoom: (setq currentzoom (list (getvar 'viewctr) (getvar 'viewsize))) .. zoom as you want And this returns you to where you were. (vla-ZoomCenter (vlax-get-acad-object) (vlax-3d-point (car currentzoom)) (cadr currentzoom)) Never tried with viewports but some ssget types need the entities to be selected to be in view, maybe viewports are the same 2 Quote
SLW210 Posted Friday at 04:13 PM Posted Friday at 04:13 PM Here is my latest zoom .9x in all layouts. I hadn't noticed the OP posted a .dwg, so i ran my Viewport Border into Model code on it. Is the result you wanted? ====================================== AutoVPBrdr REPORT ====================================== True layout viewports: 4 Viewport layer assignments: 4 Layer assignment failures: 0 Modelspace borders created: 3 Viewports skipped: 1 -------------------------------------- Layer: Viewport Color: 45 Plot: OFF ====================================== ZE_Z9XP_1.1.lsp 1 Quote
Paul Li Posted 11 hours ago Posted 11 hours ago (edited) On 10/30/2026 at 7:43 AM, mhupp said: Yeah fig so just left 410 in there to be safe. @DavidP @mhupp as they say...there's more than one way to skin a cat... either with 67 or 410 or go crazy and do both 67 & 410...but the result is the same: vports from Model are filtered out Edited 11 hours ago by Paul Li Quote
BIGAL Posted 10 hours ago Posted 10 hours ago Like @SLW210 I had a move the title block in layouts to 0,0 and then zoom extents, had one user that would move the title block as it was the way he liked to draft. We had auto plot layouts so was part of our company standard to have title at 0,0. Quote
Paul Li Posted 10 hours ago Posted 10 hours ago On 10/29/2026 at 1:44 PM, DavidP said: I added some prompt suppression... (defun DP:llnze (/ lyt) (setq oldEcho (getvar "CMDECHO") oldNOMUTT (getvar "NOMUTT") lyt (getvar "CTAB") ) (setvar "CMDECHO" 0) (setvar "NOMUTT" 1) (vl-catch-all-apply '(lambda () (foreach lay (layoutlist) (setvar "CTAB" lay) (setvar "CVPORT" 1) (vl-cmdf "_.ZOOM" "_E") ) ) ) (setvar "CTAB" lyt) (setvar "CMDECHO" oldEcho) (setvar "NOMUTT" oldNOMUTT) (princ) ) FYI, Your code works fine in your sample dwg because as you loop through each layout the space is already set in pspace. But the code fails when it encounters a layout with a vport set in mspace. The following revised loop segment code accommodates for this: (vl-catch-all-apply '(lambda () (foreach lay (layoutlist) (setvar "CTAB" lay) ; (setvar "CVPORT" 1) ; this will error out if in mspace (setq cvport (getvar "cvport")) ; save current psace vport # (if (> 1 cvport) ; chk if in mspace (progn ; then (vl-cmdf "_.Pspace" "_.ZOOM" "_E" "_.Mspace") ; goto pspace then zoom extent and return to mspace (setvar "cvport" cvport) ; return to mspace of original vport # ) (vl-cmdf "_.ZOOM" "_E") ; else just zoom extent in pspace ) ; if ) ; foreach ) ; lambda Quote
EnM4st3r Posted 48 minutes ago Posted 48 minutes ago On 10/29/2026 at 10:47 PM, Paul Li said: @ronjonp When I first open the sample TrueViewports.dwg I shared in a previous post which defaults to Layout2 and I run (length (rjp-getvports)) I get 7. Even after initializing by clicking on Layout1. I still get 7. But after clicking on Layout2 when I run @DavidP code I get 6: (sslength(setq ss (ssget "_X" '((0 . "VIEWPORT") (-4 . "<>") (69 . 1) (410 . "~Model"))))) Likewise when I run my code I posted earlier I also get 6: (sslength (ssget "_X" '((0 . "VIEWPORT") (67 . 1) (-4 . "/=") (69 . 1)))) I think mine & @DavidP code is similar. But what I don't see is whether @DavidP code is filtering out something more than compared to mine. i cannot replicate this. When i first open TrueViewports.dwg "Layout2" is already initialized. Without initializing "Layout1" Running (sslength (ssget "_X" '((0 . "VIEWPORT") (67 . 1) (-4 . "/=") (69 . 1)))) -> i get 7 But running (length (rjp-getvports)) -> i get 6 so at least for me on this test drawing file @ronjonps code seems to work without initializing the layouts. Quote
EnM4st3r Posted 36 minutes ago Posted 36 minutes ago i think this is the thread with CABs code. https://www.theswamp.org/index.php?topic=10992.0 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.