LISP to Zoom Extents on Drawing Load – Paperspace Only

LISP to Zoom Extents on Drawing Load – Paperspace Only

nrz13
Advisor Advisor
5,577 Views
26 Replies
Message 1 of 27

LISP to Zoom Extents on Drawing Load – Paperspace Only

nrz13
Advisor
Advisor

Does anyone already have a LISP or know how to tell AutoCAD to zoom extents on the current layout if it is a Paperspace layout?  It only needs to be the current layout when opened, since that's the only one the bug affects, but we don't want model space zoomed to extents automatically.

Since it doesn't seem that Autodesk is going to fix the bug it introduced in 2015 with the statusbar loading over the layout, I guess it's time to add a fix to my custom.lsp file.

IF LAYOUT=PAPERSPACE, THEN:
(command "zoom" "extents")(princ))


Work:  AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-8700K, 32GB RAM, Samsung 960 Pro SSD, AMD Radeon Pro WX 5100, 3 Dell Monitors (3840x2160)
Home: AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-11700, 64GB RAM, Samsung 980 Pro SSD, NVIDIA Quadro P2200, Dell Monitor (3840x2160)
0 Likes
Accepted solutions (2)
5,578 Views
26 Replies
Replies (26)
Message 2 of 27

Anonymous
Not applicable
(if (= 1 (getvar "tilemode"))
(command "zoom" "extents")
)
0 Likes
Message 3 of 27

nrz13
Advisor
Advisor

Thanks for the reply, but I seem to be missing a step.  I actually ended up putting this at the end of my acaddoc.lsp file so it would load with each drawing load, but it doesn't seem to be working.  The other function in my acaddoc.lsp file works fine, though, so it's not the file or a linking problem.

Here's what my command prompt shows when loading a drawing:

Opening an AutoCAD 2013 format file.
Regenerating layout.


AutoCAD menu utilities loaded..undefine copy *Cancel*

Command:

Autodesk DWG.  This file is a TrustedDWG last saved by an Autodesk application or Autodesk licensed application.

Command:

Command:



And here's the entire contents of my acaddoc.lsp file (it wouldn't let me attach):

;;; Assign Dimensions with Measurements Overridden to Own Layer - by Kent Cooper (Modified 2014/06/20)
(vl-load-com); [if not already done]
(if (setq ss (ssget "_X" '((0 . "DIMENSION") (1 . "~")))); ignores no-override ones; returns nil if it finds none
  (progn ; "wrapper" to make all operations into one 'then' argument
    (command "_.layer" "_thaw" "Dimensions_Overridden Text" ""); just in case -- won't care if it doesn't exist
    (repeat (sslength ss)
      (setq en (ssname ss 0))
      (if (not (wcmatch (cdr (assoc 1 (entget en))) "*<>*")); override doesn't contain actual measurement
        (progn ; 'then'
          (if (not (tblsearch "layer" "Dimensions_Overridden Text"))
            ; doesn't already exist -- create only if not and if appropriate object(s) found
            (command "_.layer" "_new" "Dimensions_Overridden Text" "c" "6" "Dimensions_Overridden Text" "")
              ; [no need to Thaw if new]
          ); if
          (vlax-put (setq obj (vlax-ename->vla-object en)) 'Layer "Dimensions_Overridden Text")
          (vlax-put obj 'Color 256); = Bylayer
        ); progn
      ); if
      (ssdel en ss)
    ); repeat
  ); progn ['then' -- no 'else' -- do nothing if none found]
); if [found some potentially appropriate object(s)]
(princ)


; Zoom Paperspace Layout to Extents on Drawing Load (workaround for AutoCAD 2015/2016 Bug)
(if (= 1 (getvar "tilemode"))(command "zoom" "extents"))


Work:  AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-8700K, 32GB RAM, Samsung 960 Pro SSD, AMD Radeon Pro WX 5100, 3 Dell Monitors (3840x2160)
Home: AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-11700, 64GB RAM, Samsung 980 Pro SSD, NVIDIA Quadro P2200, Dell Monitor (3840x2160)
0 Likes
Message 4 of 27

ВeekeeCZ
Consultant
Consultant

Erased by user.

0 Likes
Message 5 of 27

hmsilva
Mentor
Mentor

@nrz13 wrote:

Does anyone already have a LISP or know how to tell AutoCAD to zoom extents on the current layout if it is a Paperspace layout?  It only needs to be the current layout when opened, since that's the only one the bug affects, but we don't want model space zoomed to extents automatically.

Since it doesn't seem that Autodesk is going to fix the bug it introduced in 2015 with the statusbar loading over the layout, I guess it's time to add a fix to my custom.lsp file.

IF LAYOUT=PAPERSPACE, THEN:
(command "zoom" "extents")(princ))


Hi nrz13,

 

try

 

(if (and (/= 1 (getvar "tilemode"))
         (= 1 (getvar "cvport"))
    )
  (command "_.zoom" "extents")
)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 6 of 27

nrz13
Advisor
Advisor

BeekeeCZ:
Thanks for the suggestion, but it didn't work for me.  When opening a drawing, it returned:
; error: malformed list on input


Henrique:
That got me pretty close, and it's better than before, but it doesn't quite zoom to extents.  When opening AutoCAD, it cuts off our borders entirely.  When opening a drawing after that point it cuts off half of our borders on top and bottom, but at least the statusbar isn't covering up the drawing area anymore.  Thanks for your input!


Work:  AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-8700K, 32GB RAM, Samsung 960 Pro SSD, AMD Radeon Pro WX 5100, 3 Dell Monitors (3840x2160)
Home: AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-11700, 64GB RAM, Samsung 980 Pro SSD, NVIDIA Quadro P2200, Dell Monitor (3840x2160)
0 Likes
Message 7 of 27

ВeekeeCZ
Consultant
Consultant
Maybe instead of zoom extents is zoom to all better?
(command "_.zoom" "all")
0 Likes
Message 8 of 27

nrz13
Advisor
Advisor

That had the same result as "extents", unfortunately.  I went ahead and tried "previous" as well as a shot in the dark, but no luck.


Work:  AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-8700K, 32GB RAM, Samsung 960 Pro SSD, AMD Radeon Pro WX 5100, 3 Dell Monitors (3840x2160)
Home: AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-11700, 64GB RAM, Samsung 980 Pro SSD, NVIDIA Quadro P2200, Dell Monitor (3840x2160)
0 Likes
Message 9 of 27

hmsilva
Mentor
Mentor

@nrz13 wrote:

Henrique:
That got me pretty close, and it's better than before, but it doesn't quite zoom to extents.  When opening AutoCAD, it cuts off our borders entirely.  When opening a drawing after that point it cuts off half of our borders on top and bottom, but at least the statusbar isn't covering up the drawing area anymore.  Thanks for your input!


You're welcome, nrz13.

 

It should work as expected...

Only for testing purpose, try to change

 

(command "_.zoom" "extents")
;; to
(vla-zoomextents (vlax-get-acad-object))

 EDIT: or

 

(if (and (/= 1 (getvar "tilemode"))
         (= 1 (getvar "cvport"))
         (setq ss (ssget "_X" (list (cons 410 (getvar 'CTAB)))))
    )
  (command "_.zoom" "_O" ss "")
)

 

Henrique

 

EESignature

0 Likes
Message 10 of 27

nrz13
Advisor
Advisor

That returned the same error as BeekeeCZ's proposed solution:
; error: malformed list on input

 

 


Work:  AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-8700K, 32GB RAM, Samsung 960 Pro SSD, AMD Radeon Pro WX 5100, 3 Dell Monitors (3840x2160)
Home: AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-11700, 64GB RAM, Samsung 980 Pro SSD, NVIDIA Quadro P2200, Dell Monitor (3840x2160)
0 Likes
Message 11 of 27

hmsilva
Mentor
Mentor

@nrz13 wrote:

That returned the same error as BeekeeCZ's proposed solution:
; error: malformed list on input


nrz13,

 

none of the approaches I suggested, should cause that return...

 

EDIT: please attach your acaddoc.lsp, zipped if needed

 

Henrique

EESignature

0 Likes
Message 12 of 27

nrz13
Advisor
Advisor

For clarification, here's what I put in and the result:

(if (and (/= 1 (getvar "tilemode"))(= 1 (getvar "cvport")))(vla-zoomextents (vlax-get-acad-object))
; error: malformed list on input

(if (and (/= 1 (getvar "tilemode"))(= 1 (getvar "cvport"))(setq ss (ssget "_X" (list (cons 410 (getvar 'CTAB))))))(command "_.zoom" "_O" ss ""))
Has the same result as using (if (and (/= 1 (getvar "tilemode"))(= 1 (getvar "cvport")))(command "_.zoom" "all"))

acaddoc.lsp attached below.


Work:  AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-8700K, 32GB RAM, Samsung 960 Pro SSD, AMD Radeon Pro WX 5100, 3 Dell Monitors (3840x2160)
Home: AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-11700, 64GB RAM, Samsung 980 Pro SSD, NVIDIA Quadro P2200, Dell Monitor (3840x2160)
0 Likes
Message 13 of 27

hmsilva
Mentor
Mentor

@nrz13 wrote:

For clarification, here's what I put in and the result:

(if (and (/= 1 (getvar "tilemode"))(= 1 (getvar "cvport")))(vla-zoomextents (vlax-get-acad-object))
; error: malformed list on input


You did miss a bracket at the end...

 

(if (and (/= 1 (getvar "tilemode"))(= 1 (getvar "cvport")))(vla-zoomextents (vlax-get-acad-object)))

 and did the zoom all, worked.

 

Your acaddoc.lsp file don't have nothing wrong...

 

EDIT:

 

nrz13, I don't have in this old laptop AC2015/2016, could you please tell me if, when you open a dwg in a layout, and type de zoom extents at the command line, It works as expected?

 

Henrique

 

EESignature

0 Likes
Message 14 of 27

nrz13
Advisor
Advisor

With the missing bracket, the error went away, but the result is still the same as when I used

(if (and (/= 1 (getvar "tilemode"))(= 1 (getvar "cvport")))(command "_.zoom" "all"))

 

I'm also not sure why it's not working the same as manually zooming to extents, but I know far less than you about this.  Thanks again for your time and help and at least I'm closer to have this AutoCAD bug covered up with what you've already provided me.


Work:  AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-8700K, 32GB RAM, Samsung 960 Pro SSD, AMD Radeon Pro WX 5100, 3 Dell Monitors (3840x2160)
Home: AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-11700, 64GB RAM, Samsung 980 Pro SSD, NVIDIA Quadro P2200, Dell Monitor (3840x2160)
0 Likes
Message 15 of 27

Kent1Cooper
Consultant
Consultant

@nrz13 wrote:

... it doesn't seem to be working.

....
; Zoom Paperspace Layout to Extents on Drawing Load (workaround for AutoCAD 2015/2016 Bug)
(if (= 1 (getvar "tilemode"))(command "zoom" "extents"))


If the issue is that you might sometimes come up in a Layout but in Model Space through a Viewport, as hmsilva's suggestion appears to be assuming, another way to account for that would be:

 

(if (= 0 (getvar 'tilemode)) (command "_.pspace" "_zoom" "_extents"))

 

That would Zoom to the Layout Extents regardless, forcing it into Paper Space if it's not there already, whereas if it opens in Model Space through a Viewport, I believe hmsilva's suggestion would leave it there and un-Zoomed [but maybe that's what you want].

Kent Cooper, AIA
0 Likes
Message 16 of 27

nrz13
Advisor
Advisor

We always exit out of the viewports into full paperspace, so we just need the paperspace layout zoomed to extents (the edges of our title block).

I tried the code you posted.  There was no error, but it didn't do anything either.

I'm about to leave the office for today, so I'll catch up with any further posts tomorrow.  Thanks, everyone!


Work:  AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-8700K, 32GB RAM, Samsung 960 Pro SSD, AMD Radeon Pro WX 5100, 3 Dell Monitors (3840x2160)
Home: AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-11700, 64GB RAM, Samsung 980 Pro SSD, NVIDIA Quadro P2200, Dell Monitor (3840x2160)
0 Likes
Message 17 of 27

Kent1Cooper
Consultant
Consultant

@nrz13 wrote:

.... it's not working the same as manually zooming to extents ....


I don't have any idea why that should be, either, but I have one more suggestion -- Zoom to a window specifically calling for the lower left and upper right corners of the drawing extents:

 

(command "_.zoom" (getvar 'extmin) (getvar 'extmax))

Kent Cooper, AIA
0 Likes
Message 18 of 27

hmsilva
Mentor
Mentor
Accepted solution

@nrz13 wrote:

With the missing bracket, the error went away, but the result is still the same as when I used

(if (and (/= 1 (getvar "tilemode"))(= 1 (getvar "cvport")))(command "_.zoom" "all"))

 

I'm also not sure why it's not working the same as manually zooming to extents, but I know far less than you about this.  Thanks again for your time and help and at least I'm closer to have this AutoCAD bug covered up with what you've already provided me.


Try

 

(if (and (/= 1 (getvar "tilemode"))
         (= 1 (getvar "cvport"))
    )
  (vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) (strcat "_.zoom extents\r"))
)

 

 Henrique

EESignature

0 Likes
Message 19 of 27

Kent1Cooper
Consultant
Consultant

@nrz13 wrote:

...
I tried the code you posted.  There was no error, but it didn't do anything either.
...


You probably caught it too quickly, before I noticed and fixed my error.  I had

  (if (= 1 (getvar ....

rather than

  (if (/= 1 (getvar ....

 

But when I edited it, I decided to change it to

  (if (= 0 (getvar ....

Kent Cooper, AIA
0 Likes
Message 20 of 27

nrz13
Advisor
Advisor

That did it – thanks, Henrique!

And thanks again everyone for your replies and help!


Work:  AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-8700K, 32GB RAM, Samsung 960 Pro SSD, AMD Radeon Pro WX 5100, 3 Dell Monitors (3840x2160)
Home: AutoCAD 2022.1.3, Windows 10 Pro v22H2 64-bit, Intel Core i7-11700, 64GB RAM, Samsung 980 Pro SSD, NVIDIA Quadro P2200, Dell Monitor (3840x2160)
0 Likes