PDA

View Full Version : save and zoom extents


chrisw.94380
2005-10-26, 05:00 PM
I know that I have seen stuff for adding to an existing command. What I want to do is have a lisp that will zoom extents when the drawing is closed and saved. Is there a way to do this so that it's not everytime it is saved only when the drawing is being closed?

Opie
2005-10-26, 05:08 PM
You will need to look into reactors if using lisp. Look at the :vlr-beginClose reactor event used with the vlr-dwg-reactor function.

chrisw.94380
2005-10-26, 05:11 PM
or actually an easier way is if you just have it zoom extents when you open the drawing

chrisw.94380
2005-10-26, 05:25 PM
Okay I have figured out that I want to zoom extents when opening a drawing. However I would like to zoom extents not only in model space but also i all of my layout tabs for the drawing. Is there a way to zoom extents for all of your model and layout tabs at once. I understand that I need to put this routine into addoc.lsp I believe it is. But how do I get it to run automatically also?

Opie
2005-10-26, 05:26 PM
or actually an easier way is if you just have it zoom extents when you open the drawing
You could do that as well. But, that is not what you had asked, that is why I mentioned the reactors.

The following placed in your user created Acad.lsp file should work.
(command "_zoom" "Extents")

chrisw.94380
2005-11-01, 10:52 PM
Is there a way to zoom extents on the model tabs and the layout tabs?

Opie
2005-11-01, 11:34 PM
Is there a way to zoom extents on the model tabs and the layout tabs?
Yes it is currently a doable request. You would need to cycle through each tab, perform the desired actions, return to the current tab (if desired).

There is some code on these boards to switch between tabs that could be used for a start.

chrisw.94380
2005-11-03, 03:26 AM
I been searching the forum and have not been able to find anything. Tried using tile mode but that only switches me between the model tab and one layout tab. Sometimes I have multiple layout tabs. Does anyone have a sample or a link to some code?

Opie
2005-11-03, 05:19 AM
Chris, this post contains some code to set the psltscale to 0 for each layout. You could modify it to execute a zoom -> extents instead of setting, or in addition to, the psltscale to 0 for each layout tab.

CAB2k
2005-11-03, 11:36 AM
Perhaps this will help.
(defun zoom_all_layouts (/ lay layouts *acad* *doc* )
(vl-load-com)
(setq *acad* (vlax-get-acad-object)
*doc* (vla-get-activedocument *acad*)
layouts (vla-get-layouts *doc*)
)
(vlax-for lay layouts ; step through layouts
(vla-put-activelayout *doc* lay) ; activate layout
(if (= (vla-get-activespace *doc*) 0) ; If in paperspace
(if (= (vla-get-mspace *doc*) :vlax-true); in mspace viewport
(vla-put-mspace *doc* :vlax-false) ; inactivate vp
) ; endif
) ;endif
(vla-zoomextents *acad*)
)
)
(defun c:zal ()
(zoom_all_layouts)
)

chrisw.94380
2005-11-03, 03:00 PM
code worked well. Now I want this to happen everytime the save command is run. What is the way to do this so that I don't mess anything up.

chrisw.94380
2005-11-03, 03:32 PM
I guess I only need this to run when a drawing is being closed and saved.

Opie
2005-11-03, 03:34 PM
I guess I only need this to run when a drawing is being closed and saved.
Or when you open the drawing. ;)

CAB2k
2005-11-03, 04:14 PM
I like that idea best so something that will run each time you open a drawing.
;; add this to one of your startup routines.
;; assumes that the lisp is saved as "zoom_all_layouts.lsp"
(if (or zoom_all_layouts (load "zoom_all_layouts.lsp"))
(zoom_all_layouts)
)

chrisw.94380
2005-11-03, 05:49 PM
The only reason I need it for closing is for the drawing to show up in the preview when you are looking through the files.

Opie
2005-11-03, 06:02 PM
The only reason I need it for closing is for the drawing to show up in the preview when you are looking through the files.

Assuming you use the code CAB posted, the following should run that code on the event the drawing is closed.
(vlr-dwg-Reactor nil '((:vlr-BeginDocClose . zoom_all_layouts)))

If it works, it should run everytime the drawing is closed whether you were saving the drawing or not.

chrisw.94380
2005-11-03, 06:23 PM
I am using Land Desktop so I cannot use the close command because of the sdi mode. Am I able to substitute in the exit command.

Opie
2005-11-03, 06:28 PM
I am using Land Desktop so I cannot use the close command because of the sdi mode. Am I able to substitute in the exit command.
Try the :vlr-BeginClose argument instead.

chrisw.94380
2005-11-03, 06:40 PM
(defun zoom_all_layouts (/ lay layouts *acad* *doc* )
(vl-load-com)
(setq *acad* (vlax-get-acad-object)
*doc* (vla-get-activedocument *acad*)
layouts (vla-get-layouts *doc*)
)
(vlax-for lay layouts
(vla-put-activelayout *doc* lay)
(if (= (vla-get-activespace *doc*) 0)
(if (= (vla-get-mspace *doc*) :vlax-true)
(vla-put-mspace *doc* :vlax-false)
)
)
(vla-zoomextents *acad*)
(vlr-dwg-Reactor nil '((:vlr-BeginClose . zoom_all_layouts)))



)
)




This is the code that I am using right now and can't seem to get it to work. I was unsure of where to place the reactor.

[ Moderator Action = ON ] What are [ CODE ] tags... (http://forums.augi.com/misc.php?do=bbcode#code) [ Moderator Action = OFF ]

Opie
2005-11-03, 07:02 PM
You will need to place the code for the reactor outside of your routine. It will not work correctly located inside your routine.

CAB2k
2005-11-03, 08:53 PM
Use in a button like this:
^C^Czoom_all_layouts;Close
assumes the lisp is loaded
or try this
(command "undefine" "close")
(defun c:close ()
;; assumes that the lisp is saved as "zoom_all_layouts.lsp"
(if (or zoom_all_layouts (load "zoom_all_layouts.lsp"))
(zoom_all_layouts)
)
(command "._qsave")
(command "._close")
)

Added to your start up routine it redefines the close command.
You can still use the standard close by adding a dot like this .close

This routine is incomplete as the case where the drawing has not been saved yet
it will not have a proper name. The qsave command will be wanting an answer
to this question: Save drawing as <C:\Program Files\ACAD2000\Drawing1.dwg>:

So this is a starting place for you.

kennet.sjoberg
2005-11-04, 10:16 AM
. . .What I want to do is have a lisp that will zoom extents when the drawing is closed and saved. . .
Just cut and paste the code in to your command prompt window, and see what happens when you save or exit/save your drawing.

(vl-load-com)
(defun Function_When_Saving_A_Drawing (ObjArg ListArg / )
(alert "Zoom ext will run")
(vla-zoomextents (vlax-get-acad-object ) )
(princ)
)
(vlr-dwg-reactor nil '((:vlr-beginSave . Function_When_Saving_A_Drawing )) )


...(command "undefine" "close")...
hmmm.. sorry this i probably a end of road solution.
If I don't miss mind you can not redefine some of the [X] ,_exit, ._quit and ._close commands.

so i think a reactor is a must.

: ) Happy Computing !

kennet