DesignCAD 3D Max 2027 box
Now available

DesignCAD 2027

Hatches that follow their boundaries, an on-screen dial to turn your model, and a way to find any command by name, in a clean Windows 11 look.

Halting a macro

Started by SFA, August 25, 2020, 02:26:38 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

SFA

I use a few self-programmed macros (with loops in them). What is the easiest way to make a macro end (by a specific key-press?) when I want it to quit?
SEMPER IN EXCRETIA

bdeck

#1
Here's an example of what DC  can do. The ESC key can interrupt a macro in progress, and some commands or statements within a macro.  But when the macro stops to handle the anykey statement, then ESC has no special power, and any key can be used to trigger an exit, or other action.

Another example (not shown) is the SETPOINT command, where ESC will delete the most recent point set within the command.  When all points have been deleted, then next ESC will exit the SETPOINT command. 


Edit: Added sys(999) test for exit condition, which works only for the INPUT command.

''esctest.d3m     bdeck 8/2020
'
' DC's macro language has no windows message handlers to look for keystrokes.
' (except the escape key)
' ESC will end a macro in progress, unless the macro has stopped to process the anykey statement.
' ESC will also halt certain commands and statements within a macro (such as the input statement below).
' The exit condition from INPUT may be found in sys(999).

gosub keyinit

for x= 0 to 9999
for y= 0 to 9999
z=z+1
print "Hit any key. The escape key will end the macro.  ", z
next y
print "Process Input Command.    z = ", z
input "input any number n, or ESC to exit Input command", n
print "Hit any key. The escape key will do NOTHING.      n =  ", n, "     sys(999) =  ", sys(999)
anykey k
print "key code =  ", k, "    Hit another key. ESC or 0 will end the macro."
anykey kk
if (k_ESC = kk) or  (k_0n = kk) or  (k_0a = kk) or (k_0p = kk) then end
next x
end

keyinit:
k_0n = 96
k_0a = 48
k_0p = 45
k_ESC = 27
return

SFA

Thank you very much Bdeck! Regards,


Stan

SEMPER IN EXCRETIA