Jump to content

zoom extend the all opened drawings


muthu123

Recommended Posts

Dear all,

 

I am trying the code in Visual LISP Bilble and it is not working. Please correct the code. This is to zoom all the opened drawings.

(defun c:zoomall ()
 (setq #acad   (vlax-get-acad-object)
       #docs   (vla-get-documents #acad)
       cur_doc (vla-get-activedocument #acad)
       cnt     (vla-get-count #docs)
 )
 (vlax-for each #docs
   (vla-put-activedocument each)
   (vla-zoomextents #acad)
   (vla-save each)
 )
 (vla-put-activedocument cur_doc)
)

Link to comment
Share on other sites

Firstly, there's a few things such as you need to have vl-load-com called at least once per DWG:

(vl-load-com)
(defun c:zoomall (/ each #docs #acad)
 (setq #acad   (vlax-get-acad-object)
       #docs   (vla-get-documents #acad)
       ;; cur_doc (vla-get-activedocument #acad)
       ;; cnt     (vla-get-count #docs)
 )
 (vlax-for each #docs
   ;; (vla-put-activedocument each)
   (vla-Activate each)
   (vla-zoomextents #acad)
   (vla-save each)
 )
 (vla-put-activedocument cur_doc)
)

But even this is not necessarily going to work ... Lisp is a bit tricky when working on multiple DWGs. You need to ensure that the code is loaded into each DWG, but even then it doesn't work correctly. Here's a quote from ACad2008's developer help:

You can access multiple document namespaces using ActiveX automation, and AutoLISP provides access to ActiveX methods (see ). However, accessing multiple documents with ActiveX is an unsupported feature of AutoLISP. For example, an AutoLISP program running in the context of document A can change the active document to document B by calling vla-put-activedocument. Changing the active document, though, immediately suspends execution of the program. The program may resume execution if the user activates the window containing document A but the system will be in an unstable state and likely to fail.
Link to comment
Share on other sites

Firstly, there's a few things such as you need to have vl-load-com called at least once per DWG:
(vl-load-com)
(defun c:zoomall (/ each #docs #acad)
 (setq #acad   (vlax-get-acad-object)
       #docs   (vla-get-documents #acad)
       ;; cur_doc (vla-get-activedocument #acad)
       ;; cnt     (vla-get-count #docs)
 )
 (vlax-for each #docs
   ;; (vla-put-activedocument each)
   (vla-Activate each)
   (vla-zoomextents #acad)
   (vla-save each)
 )
 (vla-put-activedocument cur_doc)
)

But even this is not necessarily going to work ... Lisp is a bit tricky when working on multiple DWGs. You need to ensure that the code is loaded into each DWG, but even then it doesn't work correctly. Here's a quote from ACad2008's developer help:

 

 

dear irneb,

yes. It is not working.

Link to comment
Share on other sites

Are you trying to do this yourself? I've got an idea on how to perform it without having to activate each DWG in turn, but it's a bit complex and I don't have a lot of time to play around right now.

 

Anyhow, my idea is to get hold of the DWG's active viewport (MS or Ps ... whichever's current). Then to get the bounding box of all that's drawn in the current space and change the VP's extents to the bounding box. At least such would be possible through the vla stuff, but how well it would work / what other problems may occur I don't know.

Link to comment
Share on other sites

But that's why I'm suggesting obtaining the bounding box of all the entities. Then modifying the zoom factor of the active view port to suit. It's always a view port, even in model space you're inside a viewport (just a tiled viewport), and in PS the 1st viewport is the PS itself. So it should work by changing the viewport's view's width, height and center properties to suit the bounding box from all the entities shown in it.

Link to comment
Share on other sites

I am not sure if I know what you mean. If I am off the topic, Just ignore this post.

 

Would'nt that work if you add it to your ACADDOC.lsp?

 

I just use a simple command call to Zoom Extents for every drawing that opens.

 

Just an example of my ACADDOC.lsp

(defun-q DWG:SETUP ()  
 (vl-load-com)
 (setvar "cmdecho" 0)
 (setvar "osmode" 16383)
 (setvar "orthomode" 1)
 (setvar "psltscale" 0)
 (setvar "angbase" 0)
 (setvar "angdir" 0)
 (command "_.layer" "_s" "0" "")
[color=red]  (command "_.zoom" "_E")[/color]
 (command "_.regenall")
 (load "C:\\ACADDOC\\TDS\\TDS.lsp")
 (princ))
(princ)
(setq S::STARTUP (append S::STARTUP DWG:SETUP))

 

 

Maybe you could load your code that way for each drawing and run it?

Link to comment
Share on other sites

That would work nicely for each DWG as and when it opens. What the OP is after is a command which would zoom extents to all already opened files: i.e. he's got 2+ DWG files opened already, he now wants to issue one command to zoom extents in each.

Link to comment
Share on other sites

*IF* pursuing alternative solutions... perhaps adding the 'Zoom Extents' call to a :vlr-CommandWillStart reactor (specifically the 'save' command)?

 

This would accomplish the task, conditionally based on active tab prior to saving each drawing worked on by the OP, and would only require minimal code, no? :unsure:

Link to comment
Share on other sites

That would work nicely for each DWG as and when it opens. What the OP is after is a command which would zoom extents to all already opened files: i.e. he's got 2+ DWG files opened already, he now wants to issue one command to zoom extents in each.

 

Thanks for the clarification irneb, I was not sure.

Link to comment
Share on other sites

That would work nicely for each DWG as and when it opens. What the OP is after is a command which would zoom extents to all already opened files: i.e. he's got 2+ DWG files opened already, he now wants to issue one command to zoom extents in each.

 

I see, NVM then. I must have misunderstood the OP's request.

Link to comment
Share on other sites

  • 2 years later...
But that's why I'm suggesting obtaining the bounding box of all the entities. Then modifying the zoom factor of the active view port to suit. It's always a view port, even in model space you're inside a viewport (just a tiled viewport), and in PS the 1st viewport is the PS itself. So it should work by changing the viewport's view's width, height and center properties to suit the bounding box from all the entities shown in it.

Hi,irreb

It sounds well.

Do you have some successful code about what you said in this topic?

Many thanks.

Xia

Link to comment
Share on other sites

  • 5 years later...

Sorry for digging up an old thread but I've tried to get it to work.

 

I can see this cycling through each layout and model space on open drawings and it's zooming in but when it's finished I tab through the drawings it's has had no affect.

 

I know LeeMac has said this cannot be done with zoomextents but maybe things have changed. I found the zoom layout in drawing code from LeeMac elsewhere.

 

Thanks.

 

(defun C:test ( / dwg lay layout obj acapp acdoc aclay )
(vl-load-com)
(vlax-for dwg (vla-get-Documents (vlax-get-acad-object))
	(vl-load-com)
	(vlax-for lay (vla-get-layouts dwg)
		(setq acapp (vlax-get-acad-object)
			acdoc (vla-get-activedocument acapp)
			aclay (vla-get-activelayout acdoc)
			)
		(vlax-for layout (vla-get-layouts acdoc)
			(vla-put-activelayout acdoc layout)
			(if (eq acpaperspace (vla-get-activespace acdoc))
				(vla-put-mspace acdoc :vlax-false)
				)
			(vla-zoomextents acapp)
			)
		(vla-put-activelayout acdoc aclay)
		(princ)
		)
	(vla-regen dwg acAllViewports)
	)
(princ)
)

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...