Update lisp to return to the first page layout in the drawing

Update lisp to return to the first page layout in the drawing

bgraverholt
Advocate Advocate
1,230 Views
7 Replies
Message 1 of 8

Update lisp to return to the first page layout in the drawing

bgraverholt
Advocate
Advocate

The lisp below I would like it to at the end of the zoom extents on all page layouts to return to the very first page layout in the drawing instead of the one lisp was ran on. Is there a way to do that? 

 

(defun C:ZEa (/ lyt)
  (setq lyt (getvar 'ctab))
  (foreach lay (layoutlist)
    (setvar 'ctab lay)
    (command "_.pspace" "_.zoom" "_extents")
  ); foreach
  (setvar 'ctab lyt)
); defun

 

0 Likes
1,231 Views
7 Replies
Replies (7)
Message 2 of 8

Ranjit_Singh
Advisor
Advisor
add this at the end
(vlax-for i (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))) (if (= (vla-get-taborder i) 1) (setvar 'ctab (vla-get-name i))))
0 Likes
Message 3 of 8

bgraverholt
Advocate
Advocate

Just thought of this is there a way to do this when you close a drawing automatically? So when you click the X the lisp would run? I assume not but would be awesome if it could.

0 Likes
Message 4 of 8

Kent1Cooper
Consultant
Consultant

@bgraverholt wrote:

... is there a way to do this when you close a drawing automatically? So when you click the X the lisp would run? I assume not but would be awesome if it could.


Put redefine close in the "Search This Board" window, and you will be presented with lots of threads about this very question.  Some are specifically about closing with the X, and getting it to run something first, in any workable version of which you could substitute what you want to run.

Kent Cooper, AIA
0 Likes
Message 5 of 8

Ranjit_Singh
Advisor
Advisor

I think the only way would be to do it with a reactor on close. You may, however, avoid the reactor by simply closing it on whatever tab, but then, setting up AutoCAD acaddoc to open a drawing to a particular tab (by adding what I provided to you in the acaddoc.lsp) If that does not work, add it in a startup function.

0 Likes
Message 6 of 8

bgraverholt
Advocate
Advocate

Only problem I can see is sometimes we don't make changes to a drawing don't save the drawing wouldn't need the command to run. So I would need a new warning asking if I want to zoom extent and save drawing. Possibly a little more difficult than I originally thought haha. I will have to take a look at redefine close post and see what I can find.

0 Likes
Message 7 of 8

Kent1Cooper
Consultant
Consultant

@bgraverholt wrote:

.... sometimes we don't make changes to a drawing don't save the drawing wouldn't need the command to run. So I would need a new warning asking if I want to zoom extent and save drawing. Possibly a little more difficult than I originally thought haha. ....


If you are going to need to answer some question or other most of the time, regardless, you may as well leave the X-close function alone.  I have a little command defined, to set the Layer to 0, Zoom to the Limits, Save to two locations [the base location on the Server and a spare backup on the local computer], and Close.  You could do something similar with the addition of stepping through all the Layouts and Zooming [I have that kind of thing in a command definition independent of Closing], and whatever else you want.  And you could define another that Closes and answers No to the whether-to-save question, for times when you know that's what you want to do, and know that it's going to ask.  It does all require Users to be conscious of the possibilities, and under what circumstances X-closing will work without the question being asked, etc., etc.

Kent Cooper, AIA
0 Likes
Message 8 of 8

bgraverholt
Advocate
Advocate

I think I could use what you had in your message and alter it for what I need to use it for. 

0 Likes