lastknownuser Posted June 20, 2023 Posted June 20, 2023 Got a new laptop with autocad 2021, been using autocad 2018 on work pc before, and this has been working with 2018 version but it doesn't on 2021. Maybe its a system variable issue, anyhow I'd really like to find solution. Nothing complicated, I have several layouts with viewport (1 in every layout), and I'd like to change scale of all layout viewports at once with lisp. Here is the code that has been working with 2018 version, from model space, and it changed scale of viewport in all layouts (2 here for example). On 2021 version it doesn't work at all if I run it from model, and only works for 1 layout if I run it in that layout. (setq V1 (ssget "_X" (list '(410 . "A4 - L (1)") '(0 . "VIEWPORT")))) (setq vp1 (ssname V1 0)) (setq vport1 (vlax-ename->vla-object vp1)) (vla-put-customscale vport1 0.2) (setq V2 (ssget "_X" (list '(410 . "A4 - L (2)") '(0 . "VIEWPORT")))) (setq vp2 (ssname V2 0)) (setq vport2 (vlax-ename->vla-object vp2)) (vla-put-customscale vport2 0.2) Quote
mhupp Posted June 20, 2023 Posted June 20, 2023 (edited) Paper space itself is a "viewport" and is always 1. Autocad 2021 might be selecting that first now. so when you call (ssname V1 0) its calling paper space? This selects all viewports in one go except the paper space (69 . 1) makes a list of all vla-objects. Sets their scale (defun C:VPScale (/ VPSS) (vla-startundomark (setq Drawing (vla-get-activedocument (vlax-get-acad-object)))) ;set undo point (if (setq VPSS (ssget "_X" '((0 . "VIEWPORT") (-4 . "!=") (69 . 1)))) ;select all viewports in drawing but not paper space. (foreach obj (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex VPSS))) (vla-put-customscale obj 0.2) ;set scale of viewport ) ) (vla-Regen Drawing acAllViewports) ;it runs on model space too but doesn't change anything except needs a regen. (vla-endundomark Drawing) ) Edited June 20, 2023 by mhupp Quote
lastknownuser Posted June 21, 2023 Author Posted June 21, 2023 5 hours ago, mhupp said: Paper space itself is a "viewport" and is always 1. Autocad 2021 might be selecting that first now. so when you call (ssname V1 0) its calling paper space? This selects all viewports in one go except the paper space (69 . 1) makes a list of all vla-objects. Sets their scale (defun C:VPScale (/ VPSS) (vla-startundomark (setq Drawing (vla-get-activedocument (vlax-get-acad-object)))) ;set undo point (if (setq VPSS (ssget "_X" '((0 . "VIEWPORT") (-4 . "!=") (69 . 1)))) ;select all viewports in drawing but not paper space. (foreach obj (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex VPSS))) (vla-put-customscale obj 0.2) ;set scale of viewport ) ) (vla-Regen Drawing acAllViewports) ;it runs on model space too but doesn't change anything except needs a regen. (vla-endundomark Drawing) ) Thanks for reply, yeah I figured that paper space is a viewport itself, sslength was 2 if I had one layout, but that is not the problem as I tried also (ssname V1 1). And your code also doesn't work for me. sslength of VPSS is correct, but the issue is the same, doesn't work from model space, only works for 1 layout if I run it from there. But I noticed now that when I first run lisp it changes some layouts, for example not the first one but all else, also zoom in paper space is changed (from extends to 0.2). But the second time if I change the scale (example from 0.2 to 0.5) nothing happens for any of the layouts. Really weird, I can't figured out why, I also sent it to a friend who is using 2017 version and it also doesn't work... Quote
lastknownuser Posted June 21, 2023 Author Posted June 21, 2023 Also I think viewport except paperspace should be (69 . 2), or on? I did what I needed other way since I can't understand what is wrong with the first idea. I got list of all layouts with (layoutlist), then created loop to set each to ctab and from there change each viewport scale. Seems slower but it works. But its really weird the one I used before now doesn't work anymore, just like the code @mhupp you posted above. Quote
mhupp Posted June 22, 2023 Posted June 22, 2023 The ssget I posted uses a relational operator to filter the ssget (setq VPSS (ssget "_X" '((0 . "VIEWPORT") (-4 . "!=") (69 . 1)))) Select all viewports not equal to (69 . 1) Select all viewports except ones that have (69 . 1) 17 hours ago, lastknownuser said: But its really weird the one I used before now doesn't work anymore, just like the code @mhupp you posted above. Might be a system settings then maybe? Check for locked or frozen layers the viewport is on. did you check other drawings or just this one? Quote
lastknownuser Posted June 23, 2023 Author Posted June 23, 2023 On 22/06/2023 at 02:30, mhupp said: The ssget I posted uses a relational operator to filter the ssget (setq VPSS (ssget "_X" '((0 . "VIEWPORT") (-4 . "!=") (69 . 1)))) Select all viewports not equal to (69 . 1) Select all viewports except ones that have (69 . 1) Might be a system settings then maybe? Check for locked or frozen layers the viewport is on. did you check other drawings or just this one? Oh okay, didn't know that "!=" means that, but your code did select those with (69 . 1), thats why I asked. I just put '((0 . "VIEWPORT") (69 . 2)) and it was okay then. Don't know what system setting could affect this. All layers are of course on, viewport is on, checked on multiple drawings, created few viewports in empty drawing, still doesn't work... really weird. I see the viewport, and as I said, it doesn't work from model but if I'm in the certain layout, it works (and just for that one if its loop code) Quote
lastknownuser Posted June 23, 2023 Author Posted June 23, 2023 SOLVED! It was LAYOUTREGENCTL sys variable, it was set to 2 (by default), changed it to 0 like it was on my previous work pc. Listed all variables from old pc and compared with current. 1 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.