Jump to content

Recommended Posts

Posted

I am trying to modify an existing lisp routine to include a function for the user (that's me) to cancel running the routine. When the lisp is running, there seems to be no way to cancel it. (and for a large dwg it can take a long, long time to finish) I wouldn't think you'd have to code an exit or quit function in a program, but apparently for this one I do because the only way to quit is to CTRL+SHFT+ESC and kill the ACAD process. Thx.

Posted

Is your code running a loop or something?

What else is keeping that function running so long?

Posted

Sounds like processing a large data set... Perhaps due to inefficient code (not sure, because none was posted).

 

In any event, Ctrl+Shift have nothing to do with it, only when you hit Esc did the routine stop due to built-in (or localized) *error* handler.

Posted
In any event, Ctrl+Shift have nothing to do with it, only when you hit Esc did the routine stop due to built-in (or localized) *error* handler.
I think the OP means Ctrl+shift+Esc opens the Task Manager, from which he then terminates the acad.exe process.

 

But yes, there's probably something going wrong inside the Lisp. Perhaps a loop which never finishes, or code running extremely inefficiently / through too many iterations. We can only say for sure if we can see the code - so waiting for the OP to return with some more info.

Posted
Sounds like processing a large data set... Perhaps due to inefficient code (not sure, because none was posted).

 

But yes, there's probably something going wrong inside the Lisp. Perhaps a loop which never finishes, or code running extremely inefficiently / through too many iterations. We can only say for sure if we can see the code - so waiting for the OP to return with some more info.

 

Agreed, its the most likely culprit.

 

1+

Posted (edited)

Sorry, here is the code.

I put this in a macro to run when closing out a dwg. But, if I run the code on a large dwg set (150+) layouts it's murderous. When I try to cancel it using ESC, it doesn't do anything. So, I have to wait an hour or kill the process. It's not a big deal if I have time, but if I forget and I need to save the drawing (like I just did), then I'm screwed. I have to allow it to complete in order to save my changes.

 

 

 
(vl-load-com)
(defun c:zza (/ *error* oldCtab)
 (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)
)


Edited by rkmcswain
Added [CODE] tags
Posted
Sorry, here is the code.

I put this in a macro to run when closing out a dwg. But, if I run the code on a large dwg set (150+) layouts it's murderous. When I try to cancel it using ESC, it doesn't do anything. So, I have to wait an hour or kill the process. It's not a big deal if I have time, but if I forget and I need to save the drawing (like I just did), then I'm screwed. I have to allow it to complete in order to save my changes.

 

 

 

(vl-load-com)

(defun c:zza (/ *error* oldCtab)

(defun *error* (msg)

(and oldCtab (setvar 'ctab oldCtab))

(cond ((not msg)) ; Normal exit

((member msg '("Function cancelled" "quit / exit abort"))) ; 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)

)

 

 

I thought ^that^ looked familiar.

 

... So why not just check for unsaved changes first?

 

(vl-load-com)

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

 (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 (= 0 (getvar 'dbmod))
   (if (and (setq oldCtab (getvar 'ctab))
            (setq acApp (vlax-get-acad-object))
       )
     (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)
       )
     )
   )
   (prompt "\n** Unsaved changes, save and try again ** ")
 )

 (*error* nil)
)

Posted

... a large dwg set (150+) layouts

 

[PeteCampbellVoice]

 

... A thing like that.

 

[/PeteCampbellVoice]

 

pete.jpg

 

#MadMen

Posted

Probably will be quickier when iterate through layouts,

instead of:


(foreach tab (layoutlist)


....


)

use this:

(setq olayouts  (vla-get-layouts doc))
(vlax-for olayout olayouts  


;|rest code here|;


)

Not tested

Posted

I recently changed mine to this:

 

(defun c:ZAL (/ ctab)
 ;; Zoom extents of viewport in All Layouts (excluding Model)
 ;; Alan J. Thompson
 (or *Acad* (setq *Acad* (vlax-get-acad-object)))
 (or *AcadDoc* (setq *AcadDoc* (vla-get-activedocument *Acad*)))
 (setq ctab (getvar 'CTAB))
 (foreach layout (layoutlist)
   (setvar 'CTAB layout)
   (vla-put-mspace *AcadDoc* :vlax-false)
   (vla-zoomwindow *Acad* (vlax-3d-point (getvar 'LIMMIN)) (vlax-3d-point (getvar 'LIMMAX)))
 )
 (setvar 'CTAB ctab)
 (princ)
)

  • 11 years later...
Posted

Does anyone want to test setting these 3 variables to the top to the best performing.

 

I notice it a lot better.

 

(vl-load-com)

;; https://www.theswamp.org/index.php?topic=53336.msg585756#msg585756
;; Zoom Extents All Layouts
;; Mod by 3dwannab on 2025.06.12 to try turning regen variables to the best performing.

(defun c:ZEAL (/ app doc restore) 

  (command "REGENAUTO" "OFF") ;; Obsolete. Controls automatic regeneration of a drawing. But stick it in there anyway
  (setvar "LAYOUTREGENCTL" 2) ;; 0 = The drawing is regenerated each time you switch tabs. 1 = For the Model tab and the last layout made current, the display list is saved to memory and regenerations are suppressed when you switch between the two tabs. For all other layouts, regenerations still occur when you switch to those tabs. 2 = The drawing is regenerated the first time you switch to each tab. For the remainder of the drawing session, the display list is saved to memory and regenerations are suppressed when you switch to those tabs.
  (command "RTREGENAUTO" "OFF") ;; 0 = Prevents automatic regeneration when panning and zooming. 1 = Allows automatic regeneration when panning and zooming.

  (setq app     (vlax-get-acad-object)
        doc     (vla-get-activedocument app)
        restore (vla-get-activelayout doc)
  )

  (vlax-for layout (vla-get-layouts doc) 
    (vla-put-activelayout doc layout)
    (if (or (eq 1 (getvar 'tilemode)) (eq 1 (getvar 'cvport))) 
      (vla-zoomextents app)
      (progn 
        (vla-put-mspace doc :vlax-false)
        (vla-zoomextents app)
        (vla-put-mspace doc :vlax-true)
      )
    )
  )

  (vla-put-activelayout doc restore)

  (command "REGENAUTO" "ON")
  (setvar "LAYOUTREGENCTL" 2)
  (command "RTREGENAUTO" "ON")

  (princ)
)

 

  • Like 1

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