Jump to content

Recommended Posts

Posted

I have a toolbar button macro that runs two lisp routines in a loop and I would like to break out of the loop or ctrl+break the loop with a toolbar button (a stop loop toolbar button). What would the best way to accomplish this? I cannot figure out a way that works.

Thanks,

Sean

  • Replies 28
  • Created
  • Last Reply

Top Posters In This Topic

  • Jimmy Sean

    13

  • alanjt

    12

  • The Buzzard

    3

  • Lee Mac

    1

Top Posters In This Topic

Posted Images

Posted

Why not just hit the Escape key?

Posted
Why not just hit the Escape key?

 

 

Ouch! Alan your tougher than Frank Perdue.

Posted (edited)
Ouch! Alan your tougher than Frank Perdue.
It takes a real man to be tougher than a chicken CEO.:lol: Edited by alanjt
Posted
Why not just hit the Escape key?

 

The reason being is that I want to be able to kill the loop and then reset some variables in one fell swoop.

 

Further explanation on what it is that I am trying to achieve. The button macro *^C^CLWTFLASHALLON;LWTFLASHALLOFF;

 

It runs a loop that turns on lineweights and then turns off line weights to create a lightsaber/flashing effect for a specific set of layers. I want to be able to kill the loop and then reset the lineweight with another lisp routine.

 

Might not be the best approach but it was the only way I knew how to do it. I'm open to any ideas of other methods though.

 

The (exit) wouldn't kill it via a button.

 

Thanks,

Sean

Posted

Just code the routines properly with an error handler that will reset your variables.

Posted
The reason being is that I want to be able to kill the loop and then reset some variables in one fell swoop.

 

Further explanation on what it is that I am trying to achieve. The button macro *^C^CLWTFLASHALLON;LWTFLASHALLOFF;

 

It runs a loop that turns on lineweights and then turns off line weights to create a lightsaber/flashing effect for a specific set of layers. I want to be able to kill the loop and then reset the lineweight with another lisp routine.

 

Might not be the best approach but it was the only way I knew how to do it. I'm open to any ideas of other methods though.

 

The (exit) wouldn't kill it via a button.

 

Thanks,

Sean

 

Sounds to me like the programs need the work and not the marcro button. Can you display the programs?

Posted
Just code the routines properly with an error handler that will reset your variables.

 

That would be beyond my skill set, though I'm not apposed to learning how to do it. Could someone point me in the correct direction?

 

Sounds to me like the programs need the work and not the marcro button. Can you display the programs?

 

Sure. This what I have so far and what I need to accomplish is that when it is canceled it returns all the lineweights to default and turns off lwdisplay.

 

;;;;;;;;;;;;;;;;;;;;;;
;Flash All
;;;;;;;;;;;;;;;;;;;;;;
;THIS MACRO MUST BE KEPT SEPARATE FROM LWTFLASHOFF OR IT WILL NOT RUN AND WILL NOT ALLOW ZOOMING AND PANNING WHILE FLASHING.
(defun C:LWTFLASHALLON ()
(command
"-layer"
"LWEIGHT"
"1"
"*"
""
"LWDISPLAY"
"ON"
"DELAY"
"200")
(PRIN1))


;THIS MACRO MUST BE KEPT SEPARATE FROM LWTFLASHON OR IT WILL NOT RUN AND WILL NOT ALLOW ZOOMING AND PANNING WHILE FLASHING.
(defun C:LWTFLASHALLOFF ()
(command
"LWDISPLAY"
"OFF"
"DELAY"
"200"
"-layer"
"LWEIGHT"
"DEFAULT"
"*"
""

)
(PRIN1))

;;;;;;;;;;;;;;;;;;;;;;
;End Flash All
;;;;;;;;;;;;;;;;;;;;;;



;;;;;;;;;;;;;;;;;;;;;;
;Stop Flash
;;;;;;;;;;;;;;;;;;;;;;

(defun C:STOP-FLASH ()
(command
"LWDISPLAY"
"OFF"
"DELAY"
"200"
"-layer"
"LWEIGHT"
"DEFAULT"
"*"
""

)
(PRIN1))

;;;;;;;;;;;;;;;;;;;;;;
;End Stop Flash
;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;
;Flash all Mechanical
;;;;;;;;;;;;;;;;;;;;;;
(defun C:FLASH-M-ALLON ()
(command
"-layer"
"LWEIGHT" "1" "#*|M*"
""
"LWDISPLAY"
"ON"
"DELAY"
"200")
(PRIN1))

(defun C:FLASH-M-ALLOFF ()
(command
"LWDISPLAY"
"OFF"
"DELAY"
"200"
"-layer"
"LWEIGHT"
"DEFAULT"
"*"
""

)
(PRIN1))

;;;;;;;;;;;;;;;;;;;;;;
;End Flash all Mechanical
;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;
;Flash all Electrical
;;;;;;;;;;;;;;;;;;;;;;
(defun C:FLASH-E-ALLON ()
(command
"-layer"
"LWEIGHT" "1" "#*|E*"
"LWEIGHT" "default" "#*|E-COMMUNICATION_CEILING*"
"LWEIGHT" "default" "#*|E-FIRE_ALARM_CEILING*"
"LWEIGHT" "default" "#*|E-NURSE_CALL_CEILING*"
"LWEIGHT" "default" "#*|E-SECURITY_CEILING*"
"LWEIGHT" "default" "#*|E-TEXT-BLOCK*"
"LWEIGHT" "default" "#*|E-TEXT-COM*"
"LWEIGHT" "default" "#*|E-TEXT-SEC*"
"LWEIGHT" "default" "#*|E-TEXT-NC*"
""
"LWDISPLAY"
"ON"
"DELAY"
"200")
(PRIN1))

(defun C:FLASH-E-ALLOFF ()
(command
"LWDISPLAY"
"OFF"
"DELAY"
"200"
"-layer"
"LWEIGHT"
"DEFAULT"
"*"
""

)
(PRIN1))

;;;;;;;;;;;;;;;;;;;;;;
;End Flash all Electrical
;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;
;Flash all Communication
;;;;;;;;;;;;;;;;;;;;;;
(defun C:FLASH-C-ALLON ()
(command
"-layer"
"LWEIGHT" "1" "#*|E-COMMUNICATION_CEILING*"
"LWEIGHT" "1" "#*|E-FIRE_ALARM_CEILING*"
"LWEIGHT" "1" "#*|E-NURSE_CALL_CEILING*"
"LWEIGHT" "1" "#*|E-SECURITY_CEILING*"
"LWEIGHT" "1" "#*|E-TEXT-BLOCK*"
"LWEIGHT" "1" "#*|E-TEXT-COM*"
"LWEIGHT" "1" "#*|E-TEXT-SEC*"
"LWEIGHT" "1" "#*|E-TEXT-NC*"
""
"LWDISPLAY"
"ON"
"DELAY"
"200")
(PRIN1))

(defun C:FLASH-C-ALLOFF ()
(command
"LWDISPLAY"
"OFF"
"DELAY"
"200"
"-layer"
"LWEIGHT"
"DEFAULT"
"*"
""

)
(PRIN1))

;;;;;;;;;;;;;;;;;;;;;;
;End Flash all Communication
;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;
;Flash all Plumbing
;;;;;;;;;;;;;;;;;;;;;;
(defun C:FLASH-P-ALLON ()
(command
"-layer"
"LWEIGHT" "1" "#*|P*"
"LWEIGHT" "default" "#*|P*-FLOWSWITCH*"
"LWEIGHT" "default" "#*|P*-TAMPERSWITCH*"
"LWEIGHT" "default" "#*|PN-FIRE*"
"LWEIGHT" "default" "#*|PN-SPKLR*"
"LWEIGHT" "default" "#*|PN-SPLRHD*"
"LWEIGHT" "default" "#*|PX-FIRE*"
"LWEIGHT" "default" "#*|PX-SPKLR*"
"LWEIGHT" "default" "#*|PX-SPLRHD*"
""
"LWDISPLAY"
"ON"
"DELAY"
"200")
(PRIN1))

(defun C:FLASH-P-ALLOFF ()
(command
"LWDISPLAY"
"OFF"
"DELAY"
"200"
"-layer"
"LWEIGHT"
"DEFAULT"
"*"
""

)
(PRIN1))

;;;;;;;;;;;;;;;;;;;;;;
;End Flash all Plumbing
;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;
;Flash all Fire Protection
;;;;;;;;;;;;;;;;;;;;;;
(defun C:FLASH-FP-ALLON ()
(command
"-layer"
"LWEIGHT" "1" "#*|F*"
"LWEIGHT" "1" "#*|P*-FLOWSWITCH*"
"LWEIGHT" "1" "#*|P*-TAMPERSWITCH*"
"LWEIGHT" "1" "#*|PN-FIRE*"
"LWEIGHT" "1" "#*|PN-SPKLR*"
"LWEIGHT" "1" "#*|PN-SPLRHD*"
"LWEIGHT" "1" "#*|PX-FIRE*"
"LWEIGHT" "1" "#*|PX-SPKLR*"
"LWEIGHT" "1" "#*|PX-SPLRHD*"
""
"LWDISPLAY"
"ON"
"DELAY"
"200")
(PRIN1))

(defun C:FLASH-FP-ALLOFF ()
(command
"LWDISPLAY"
"OFF"
"DELAY"
"200"
"-layer"
"LWEIGHT"
"DEFAULT"
"*"
""

)
(PRIN1))

;;;;;;;;;;;;;;;;;;;;;;
;End Flash Fire Protection
;;;;;;;;;;;;;;;;;;;;;;

 

Thanks,

Sean

Posted

Quickie LWDisplay toggle...

 

(defun c:LWT (/ *error* lwd)
 (defun *error* (msg)
   (and lwd (setvar 'lwdisplay lwd))
   (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))
     (princ (strcat "\nError: " msg))
   )
 )

 (setq lwd (getvar 'lwdisplay))
 (while t
   (setvar 'lwdisplay (abs (1- (getvar 'lwdisplay))))
   (command "_.delay" 200)
 )
 (*error* nil)
 (princ)
)

Posted
Quickie LWDisplay toggle...

 

(defun c:LWT (/ *error* lwd)
 (defun *error* (msg)
   (and lwd (setvar 'lwdisplay lwd))
   (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))
     (princ (strcat "\nError: " msg))
   )
 )

 (setq lwd (getvar 'lwdisplay))
 (while t
   (setvar 'lwdisplay (abs (1- (getvar 'lwdisplay))))
   (command "_.delay" 200)
 )
 (*error* nil)
 (princ)
)

 

 

Thanks, I sort of understand what you are doing but I'm clueless as too how I'm supposed to use it. :unsure:

Posted

It works the same way as the ones you posted.

Posted
It works the same way as the ones you posted.

Ok but not for me.

 

Thanks for having the patience with me.

 

I have mentally pulled apart the lisp you posted but I cannot replicate what mine does in yours. When it runs I can tell it is looping and I can cancel out of it but it never flashes like mine does. I don't see were in yours that is sets the lineweight.

 

(while t

The "t" is it just a arbitrary variable being set or is it something else, I'm not sure.

 

Also what is "abs" in

 

(setvar 'lwdisplay (abs (1- (getvar 'lwdisplay))))

 

Thanks

Sean

Posted

abs is absolute value

 

 

It doesn't set a weight. It just toggles the on/off state of LineWeight display.

Posted

After some trial and error I got it to somewhat work, doesn't flash and doesn't allow me to zoom and pan when looping. Any thoughts as to why I can't zoom and pan?

Posted

After some more trial and error I got it to function the way I want except I need some help with the error handler portion. I know I separated it again but I cannot get it to work if it is all in one lisp. It wouldn't flash and it wouldn't zoom while it was running.

 

On the error handling I cannot get it to work were it will reset the lwdisplay to off and I also need it to set all line weights back to default . Would someone be willing to give me some direction?

 

 

What is "_." before the delay command?

Thanks,

Sean

;;;;;;;;;;;;;;;;;;;;;;
;THIS MACRO MUST BE KEPT SEPARATE FROM LWTFLASHOFF OR IT WILL NOT RUN AND WILL NOT ALLOW ZOOMING AND PANNING WHILE FLASHING.
;;;;;;;;;;;;;;;;;;;;;;
(defun C:LWTFLASHON (/ *error* lwd)
(defun *error* (msg)
;    (and lwd (setvar 'lwdisplay lwd))
   (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))
     (princ (strcat "\nError: " msg))
   )
 )

 (setq lwd (getvar 'lwdisplay))
;  (while t
;    (setvar 'lwdisplay (abs (1- (getvar 'lwdisplay))))
;    (command "_.delay" 2000)
(command "LWDISPLAY" "ON" "DELAY" "200")
 (*error* nil)
 (princ)
)

;;;;;;;;;;;;;;;;;;;;;;
;End Flash On
;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;
;Flash OFF
;;;;;;;;;;;;;;;;;;;;;;
;THIS MACRO MUST BE KEPT SEPARATE FROM LWTFLASHOFF OR IT WILL NOT RUN AND WILL NOT ALLOW ZOOMING AND PANNING WHILE FLASHING.
;;;;;;;;;;;;;;;;;;;;;;
(defun C:LWTFLASHOFF (/ *error* lwd)
(defun *error* (msg)
;    (and lwd (setvar 'lwdisplay lwd))
   (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))
     (princ (strcat "\nError: " msg))
   )
 )

 (setq lwd (getvar 'lwdisplay))
;  (while t
;    (setvar 'lwdisplay (abs (1- (getvar 'lwdisplay))))
;    (command "_.delay" 2000)
(command "LWDISPLAY" "OFF" "DELAY" "200")
 (*error* nil)
 (princ)
)

;;;;;;;;;;;;;;;;;;;;;;
;End Flash OFF
;;;;;;;;;;;;;;;;;;;;;;

Posted

Think about what you are wanting to reset.

As I did with min, I stored the original state of the LWDisplay variable, then when the routine exited or errored, it reset it according to that.

 

_ accounts for language differences (autocad written in english)

. accounts for commands being un/redefined.

Posted

Can someone explain these two lines please?

 

(and lwd (setvar 'lwdisplay lwd))

(if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))

 

 

Are there any error on my interpretation of the code?

      (defun c:LWT (/ *error* lwd)      ;Name of the Function(or program) and variables are local to this program
   (defun *error* (msg)   ;name of the function "error" and its argument passing variable                                                                                                                                
     (and lwd (setvar 'lwdisplay lwd))   ;not sure

     (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))    ; if MSG is equal to BREAK*,*CANCEL*,*QUIT*,"then?
       (princ (strcat "\nError: " msg))              ;prints message
     )
   ) ; ends the error section?
  
   (setq lwd (getvar 'lwdisplay))   ;assigns the lwd variable with the lwdisplay variable of 1 or 0 
   (while t               ;loops the remainder of this program until T is nil
     (setvar 'lwdisplay (abs (1- (getvar 'lwdisplay))))              ;changes the lwdisplay variable from 0 to 1 or 1 to 0
     (command "_.delay" 200)
   )
   (*error* nil) ;sets error to nil
   (princ)
 )
 

 

Thanks

Posted

Ok got it almost there, I need it to be able to zoom (with the mouse wheel) while it is in the loop anyone have a clue why it wouldn't?

 

Here is what I have now.

;;;;;;;;;;;;;;;;;;;;;;
;Flash All
;;;;;;;;;;;;;;;;;;;;;;
(defun C:LWTFLASHALL ()
(command
"-layer"
"LWEIGHT"
"1"
"*"
""
)
(PRIN1)
)
;;;;;;;;;;;;;;;;;;;;;;
;End Flash All
;;;;;;;;;;;;;;;;;;;;;;



;;;;;;;;;;;;;;;;;;;;;;
;Flash On
;;;;;;;;;;;;;;;;;;;;;;
;THIS MACRO MUST BE KEPT SEPARATE FROM LWTFLASHOFF OR IT WILL NOT RUN AND WILL NOT ALLOW ZOOMING AND PANNING WHILE FLASHING.
;;;;;;;;;;;;;;;;;;;;;;
(defun C:LWTFLASHON (/ *error* lwd)
(defun *error* (msg)
  (and lwd (setvar 'lwdisplay lwd))
  (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))
     (princ (strcat "\nError: " msg))
   )
 )

 (setq lwd 0)
  (setvar "lwdisplay" 1)
   (command "_.delay" 200)
;  (*error* nil)
 (princ)
)

;;;;;;;;;;;;;;;;;;;;;;
;End Flash On
;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;
;Flash OFF
;;;;;;;;;;;;;;;;;;;;;;
;THIS MACRO MUST BE KEPT SEPARATE FROM LWTFLASHOFF OR IT WILL NOT RUN AND WILL NOT ALLOW ZOOMING AND PANNING WHILE FLASHING.
;;;;;;;;;;;;;;;;;;;;;;
(defun C:LWTFLASHOFF (/ *error* lwd)
(defun *error* (msg)
   (and lwd (setvar 'lwdisplay lwd))
   (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))
     (princ (strcat "\nError: " msg))
   )
 )

 (setq lwd 0)
   (setvar "lwdisplay" 0)
   (command "_.delay" 200)
;  (*error* nil)
 (princ)
)

;;;;;;;;;;;;;;;;;;;;;;
;End Flash OFF
;;;;;;;;;;;;;;;;;;;;;;

Posted
Can someone explain these two lines please?

 

(and lwd (setvar 'lwdisplay lwd))

(if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))

the first checks to see if the lwd variable is stored and if so, it will set the lwdisplay variable with it.

 

the error message check is just to weed out if there's an actual error message, and if it doesn't match the three basic error message, it will print it.

 

 

Ok got it almost there, I need it to be able to zoom (with the mouse wheel) while it is in the loop anyone have a clue why it wouldn't?

 

Here is what I have now.

;;;;;;;;;;;;;;;;;;;;;;
;Flash All
;;;;;;;;;;;;;;;;;;;;;;
(defun C:LWTFLASHALL ()
(command
"-layer"
"LWEIGHT"
"1"
"*"
""
)
(PRIN1)
)
;;;;;;;;;;;;;;;;;;;;;;
;End Flash All
;;;;;;;;;;;;;;;;;;;;;;



;;;;;;;;;;;;;;;;;;;;;;
;Flash On
;;;;;;;;;;;;;;;;;;;;;;
;THIS MACRO MUST BE KEPT SEPARATE FROM LWTFLASHOFF OR IT WILL NOT RUN AND WILL NOT ALLOW ZOOMING AND PANNING WHILE FLASHING.
;;;;;;;;;;;;;;;;;;;;;;
(defun C:LWTFLASHON (/ *error* lwd)
(defun *error* (msg)
  (and lwd (setvar 'lwdisplay lwd))
  (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))
     (princ (strcat "\nError: " msg))
   )
 )

 (setq lwd 0)
  (setvar "lwdisplay" 1)
   (command "_.delay" 200)
;  (*error* nil)
 (princ)
)

;;;;;;;;;;;;;;;;;;;;;;
;End Flash On
;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;
;Flash OFF
;;;;;;;;;;;;;;;;;;;;;;
;THIS MACRO MUST BE KEPT SEPARATE FROM LWTFLASHOFF OR IT WILL NOT RUN AND WILL NOT ALLOW ZOOMING AND PANNING WHILE FLASHING.
;;;;;;;;;;;;;;;;;;;;;;
(defun C:LWTFLASHOFF (/ *error* lwd)
(defun *error* (msg)
   (and lwd (setvar 'lwdisplay lwd))
   (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))
     (princ (strcat "\nError: " msg))
   )
 )

 (setq lwd 0)
   (setvar "lwdisplay" 0)
   (command "_.delay" 200)
;  (*error* nil)
 (princ)
)

;;;;;;;;;;;;;;;;;;;;;;
;End Flash OFF
;;;;;;;;;;;;;;;;;;;;;;

 

Try replacing the (while T with (while (eq 5 (car (grread T 15 0)))

this way, it will allow you to pan around and once you hit any key or click the mouse, it will exit. Just keep in mind that it will only cycle the on/off state, etc. if your mouse is moving, but since you'll be panning around, it will work fine.

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