muthu123 Posted January 10, 2011 Share Posted January 10, 2011 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) ) Quote Link to comment Share on other sites More sharing options...
irneb Posted January 10, 2011 Share Posted January 10, 2011 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. Quote Link to comment Share on other sites More sharing options...
muthu123 Posted January 10, 2011 Author Share Posted January 10, 2011 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. Quote Link to comment Share on other sites More sharing options...
irneb Posted January 10, 2011 Share Posted January 10, 2011 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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 10, 2011 Share Posted January 10, 2011 AFAIK, the ZoomExtents method will only work on the Current Drawing. Discussion here. Quote Link to comment Share on other sites More sharing options...
irneb Posted January 11, 2011 Share Posted January 11, 2011 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. Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted January 11, 2011 Share Posted January 11, 2011 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? Quote Link to comment Share on other sites More sharing options...
irneb Posted January 11, 2011 Share Posted January 11, 2011 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. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted January 11, 2011 Share Posted January 11, 2011 *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? Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted January 11, 2011 Share Posted January 11, 2011 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. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted January 11, 2011 Share Posted January 11, 2011 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. Quote Link to comment Share on other sites More sharing options...
alanjt Posted January 11, 2011 Share Posted January 11, 2011 Be careful when in a viewport, vla-zoomextents works even if the viewport is locked. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 11, 2011 Share Posted January 11, 2011 But that's why I'm suggesting obtaining the bounding box of all the entities. Apologies for the confusion, I was replying to the original method proposed. Quote Link to comment Share on other sites More sharing options...
xiaxiang Posted January 15, 2013 Share Posted January 15, 2013 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 Quote Link to comment Share on other sites More sharing options...
3dwannab Posted March 23, 2018 Share Posted March 23, 2018 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) ) Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted March 23, 2018 Share Posted March 23, 2018 @3dwannab Read this topic in its entirety... https://www.theswamp.org/index.php?topic=53336.0 Quote Link to comment Share on other sites More sharing options...
3dwannab Posted March 23, 2018 Share Posted March 23, 2018 I see that, thanks. How do I get that MPTools.dvb imported to use the command (_RunAll "(c:ZEAL)") I've read that RUNALL utility thread but couldn't see how to get the dvb file. There's code there but unsure of what to do with it. See here: https://www.theswamp.org/index.php?topic=53336.msg585756#msg585756 Thanks. Quote Link to comment Share on other sites More sharing options...
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.