Jump to content

Recommended Posts

Posted

Hi, I need some help with a piece of code. I found this code on another forum thread that I think will do what I need, but it needs to be modified. What I want to be able to do is apply a "zoom all" to all layouts in the current dwg. (so, when a dwg is opened I can reset the layouts first--some drawings have a "many" layouts, so the need is to clean things up a bit before working)

 

Here is the code as it is now...(which does a zoom all, but only on the current layout)

 

(vl-load-com)

(defun c:zza ()

(setq lay_list (layoutlist)

lay_list_len (length lay_list)

lay_nth 0

)

(repeat lay_list_len

; (command "layout" "set" (nth lay_nth lay_list))

(command "zoom" "all")

(setq lay_nth (1+ lay_nth))

)

(princ)

)

 

I have the one line rem'd out because I don't want to change the layouts (for my purposes it wouldn't be necessary) I don't know lisp so this code may not work as it is anyway. All I need is the zoom all command.

 

Here is another piece of code that copies the current layout's page setup to all layouts that might work as well (or be better to modify)...

 

(vl-load-com)

(defun c:cps (/ Adoc Layts clyt)

(setq aDoc (vla-get-activedocument (vlax-get-acad-object))

Layts (vla-get-layouts aDoc)

clyt (vla-get-activelayout aDoc)

)

( foreach

itm

(vl-remove (vla-get-name clyt) (layoutlist))

(vla-copyfrom (vla-item Layts itm) clyt)

(command "_zoom" "all") ;;added

)

(princ)

)

 

How would I change this? (I don't need to change the page setups)

 

Thx

Posted

Consider this adaptation:

 

(vl-load-com)

(defun c:ZoomAll (/ *error* oldCtab acApp)

 (defun *error* (msg)
   (and oldCtab (setvar 'ctab oldCtab))
   (cond ((not msg))                                                   ; Normal exit
         ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
         ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
   )
   (princ)
 )

 (if (and (setq oldCtab (getvar 'ctab))
          (setq acApp (vlax-get-acad-object))
     )
   (foreach tab (layoutlist)
     (setvar 'ctab tab)
     (vla-zoomall acApp)
   )
 )
 (*error* nil)
)

Posted

Thx BlackBox. It does work, however I had some unintended consequences to my title blocks. (wiped out the multi-line text--may be just an anomaly) However, this probably isn't going to work as envisioned. Some of my dwg's have over a hundred layouts; so you can imagine the problem of regenerating every layout while trying to open. Even with an open dwg and running the lsp could be an issue on a large dwg. Thanks for your help.

Posted

Yes, looks like that was just an anomaly. (just wanted to clarify) Thanks.

Posted

You're welcome; I'm happy to help. :beer:

Posted

Better get out of model, before you execute zoom.

 

(defun c:ZAL (/ doc acad ctab)

 (setq acad (vlax-get-acad-object)
       doc  (vla-get-activedocument acad)
       ctab (getvar 'CTAB)
 )

 (foreach layout (layoutlist)
   (setvar 'CTAB layout)
   (vla-put-mspace doc :vlax-false)
   (vla-zoomall acad)
 )

 (setvar 'CTAB ctab)

 (princ)
)

Posted

... For those that want to restore MSpace before leaving the Layout, incorporate this snippet:

 

;; <snip>

   (foreach tab (layoutlist)
     (setvar 'ctab tab)
     (if (setq mspace (< 1 (getvar 'cvport)))
       (vla-put-mspace acDoc :vlax-false)
     )
     (vla-zoomall acApp)
     (if mspace
       (vla-put-mspace acDoc :vlax-true)
     )
   )

;; <snip>

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...