Author Topic: 3rd option for Esc-issue, i.e. Sys(996), or better, a new "ON ESC" statment  (Read 5722 times)

JJG

  • Hero Member
  • *****
  • Posts: 715
I think it would be very great to have a third option for sys (996):
Presently, there are Sys(996)=0  or Sys(996)=1   [see please Sys(996) description in Macros17.hlp-file]

Why the need for a third option ? :

Indeed, in numerous macros, it is necessary to store many settings as variables, before doing anything (eg. to save initial layer number, RGB variables, line width, text size, etc. ...), in order to be able to restore all these parameters to the end of the execution of the macro and, therefore, to return in DesignCAD with exactly the same parameters before running the macro.

But if you may hit the Esc-key during the macro, to stop it urgently, actually all your initial settings (that you may have took care to store in the top of the macro execution, in order to restore them to the end) are lost ... (not lol !)

So, to do this, this third option of Sys(996)    [eg. Sys(996)=2 ]     could work as an instruction "GOTO" and thus lead to a label (for example " QUIT: "), in which we could perform these operations to return the parameters as before macro action, or anything else needed before quitting urgently the macro through the Esc-key.


What do the other developers of macro think about ?
« Last Edit: June 08, 2011, 01:13:28 AM by JJG »

paulerens

  • Hero Member
  • *****
  • Posts: 915
Re: 3rd option for Esc-issue, i.e. Sys(996)
« Reply #1 on: June 05, 2011, 11:27:57 AM »
I support this idea!

Pearco

  • Hero Member
  • *****
  • Posts: 823
Re: 3rd option for Esc-issue, i.e. Sys(996)
« Reply #2 on: June 05, 2011, 02:14:49 PM »
Bingo!! In deed a great idea.
Jim
User since ProDesign 1.5

Rob S

  • Hero Member
  • *****
  • Posts: 4262
    • Construction Estimating Program for General Contractors
Re: 3rd option for Esc-issue, i.e. Sys(996)
« Reply #3 on: June 05, 2011, 09:43:27 PM »


This seems almost like asking for a macro undo - sort of a way to back out of an unfinished macro. 

Somehow I think this might be better handled by having an "On Esc" macro statement that allows the user to program what should happen if esc key is pressed, which might vary depending on how far into the macro you have gotten.  This would work like the current "On error"


The entire control over this would then be within the macro where it is needed.
User since Pro-design

JJG

  • Hero Member
  • *****
  • Posts: 715
Re: 3rd option for Esc-issue, i.e. Sys(996)
« Reply #4 on: June 05, 2011, 10:27:27 PM »
This seems almost like asking for a macro undo - sort of a way to back out of an unfinished macro.


Not exactly, Rob S :
a macro-undo is an action " at posteriori", that is to say that you do not necessarily, and certainly not "automatically" (because it is you, the user, who takes "responsibility", or not, to execute the macro-undo), while there [with a third Sys(996) option], the macro itself ends the "rearrangement" of all settings (or all other action you may have programmed for) if a hit on the Esc-key occurs.
« Last Edit: June 06, 2011, 01:34:01 AM by JJG »

JJG

  • Hero Member
  • *****
  • Posts: 715
Re: 3rd option for Esc-issue, i.e. Sys(996)
« Reply #5 on: June 06, 2011, 03:19:24 AM »
There might be another way to make something equivalent to a third option for Sys(996),
and better structured in terms of writing code:

Indeed, this morning, I was reading the file "macro17.hlp", and I find the description of a statment that I have never used = ON ERROR statment.

Also, it would probably be better to create a new statment :
"ON ESC" statment
on the same model (as ON ERROR),
that would operate in the way, ie. if a hit of Esc-key is encountered during the execution of the macro, this will cause directly the execution to be transfered to the specified label (the name you wish). then, macro execution will continue from the label until an END statment (or eventualy a RESUME statment) is encountered.

Rob S

  • Hero Member
  • *****
  • Posts: 4262
    • Construction Estimating Program for General Contractors
Re: 3rd option for Esc-issue, i.e. Sys(996)
« Reply #6 on: June 06, 2011, 07:18:33 AM »
Quote
Also, it would probably be better to create a new statment :
"ON ESC" statment
on the same model (as ON ERROR),

Now, where have I seen that idea once before !!!  :)
User since Pro-design

Lar

  • Hero Member
  • *****
  • Posts: 2477
Re: 3rd option for Esc-issue, i.e. Sys(996)
« Reply #7 on: June 06, 2011, 07:29:30 AM »
Very good idea, JJG.

What you can do right now, until your idea is implemented, is write all 'undo' parameters in an external basiccad file using the 'print #' statement (you would have to use 'open' to create the file first). Every time just before the macro changes a parameter you save the current parameter in the d3m file. Then, if you have to abort you just run the new macro file and replace all you settings.

The added benefit of this: you could compile your saved settings into a database for future access.

Lar

JJG

  • Hero Member
  • *****
  • Posts: 715
Re: 3rd option for Esc-issue, i.e. Sys(996)
« Reply #8 on: June 06, 2011, 08:11:46 AM »
Lar,

That's what I'm doing for quite some time :
that kind of parameters have identical names in all my macros, and in my macros that need to restore some original settings, the macro write itself the parameters of these initial settings into a file that is systematically re-writing about himself in each macro execution, in order to stay updated continuously.

Then, if necessary, I execute another macro to restore these settings.

But this method is not "automatic" (sometimes in the heat of the action, I forget to do it), and secondly, it unnecessarily monopolizes the resources of the machine, slowing down (slightly) the execution of macros, and also somewhat complicates their writing.
Not to mention what might happen if the hit of Esc occurs in the same time while writing the backup file settings ... !!!

With the solution I am asking all would be so much easier !
« Last Edit: June 06, 2011, 09:38:46 AM by JJG »

Lar

  • Hero Member
  • *****
  • Posts: 2477
Re: 3rd option for Esc-issue, i.e. Sys(996)
« Reply #9 on: June 07, 2011, 06:23:53 AM »
JJG, each of your points I actually thought about while writing my previous post but did not want to elaborate too much, but here goes (these are my opinions if doing this for myself - I'm not trying to change you mind):

A] overwriting identical names :
1] shouldn't matter since I would be wanting dcad to return to it's previous state before running the macro, not to a standard state. If this was necessary I would have 'standard state' macros; 
2] if overwriting was a problem I would have the macro add the date and maybe the time to the filename.

B] resources:
1] My basiccad is extremely fast and efficient. I have macros that write the current state of all the layers to an external file and it gets finished before my finger completely relaxes from pressing the mouse button when I click on the custom toolbox icon. I have another macro that reads the dcad entities in the drawing and writes c++ type code to a sequence of external macros to run in another 3d program. This could take some time, depending on the number of entities in the drawing, in which case I switch to another program or to my web browser while dcad runs the macro, with no performance penalties;

2] I don't understand what you mean by 'not automatic' since it would be written into the macro and so would be executed automatically.

C] shouldn't complicate the macro any more than your proposal since 'on esc' would go to a section of the macro that would somehow record the previous parameters.

D] I don't think dcad starts one instruction before completing the previous one so if you press esc while it's writing to the external file it would hold the keypress in the keyboard buffer until it finishes the writing.

Please understand that I like your idea but it will surely be years before it is implemented, if ever.

Lar

Dr PR

  • Hero Member
  • *****
  • Posts: 5379
Re: 3rd option for Esc-issue, i.e. Sys(996)
« Reply #10 on: June 07, 2011, 12:42:41 PM »
It is a very good idea. In fact, ALL programs should automatically work this way. I have written some fairly complex programs that use ESCape to abort any operation in progress and return to the starting conditions. Wish DesignCAD worked that way!

Phil
DesignCAD user since 1987

JJG

  • Hero Member
  • *****
  • Posts: 715
Re: 3rd option for Esc-issue, i.e. Sys(996)
« Reply #11 on: June 07, 2011, 12:47:31 PM »
Lar,

Thank you first of all the interest you have shown in this issue of management of Esc, which is far from trivial.

I answer your questions in the disorder, I apologize !

B]2] by "not automatic", I mean that you (=the user) must necessarily have to pay attention that the macro that you stopped by Esc may have changed some settings, and therefore it is necessary to run another macro to repair these changes. As I said, sometimes, in the heat of the action, you forget to run the macro to repair such changes, and hence risk of errors in the work you did afterwards. It is often annoying.

C] for me, it is obvious that include lines of code that must write an external file (... etc) is extending the writing of the macro, and then complicate it.
You mean that an instruction "ON ESC" equally will complicate the macro : I do not agree with you. In macros where one have take care to store some DesignCAD settings in variables, inevitably, there is a sequence where one will restore these variables, otherwise it is useless !
So, in fact, work is already done, there is not more to do than to add a label before the sequence , if not already done so.

D] maye be you are right for this.
« Last Edit: June 07, 2011, 01:50:29 PM by JJG »

JJG

  • Hero Member
  • *****
  • Posts: 715
Re: 3rd option for Esc-issue, i.e. Sys(996)
« Reply #12 on: June 08, 2011, 01:23:14 AM »
A] overwriting identical names :
1] shouldn't matter since I would be wanting dcad to return to it's previous state before running the macro, not to a standard state. If this was necessary I would have 'standard state' macros; 
Yes it works indeed ! it is necessary to restore only the settings that the macro (stopped urgently by Esc) has changed, that is to say, those that one care was taken to store into variables, and that the macro itself would have restored if it had performed normally until the end.

paulerens

  • Hero Member
  • *****
  • Posts: 915
Quote
1027 - Message Box Style for the ESC (V. 13)
[0=OK (default)
 1 =  OK/Cancel
 2 = Abort/Retry/Ignore
 3 = Yes/No/Cancel
 4 = Yes/No
 5 = Retry/Cancel]
This function allows the programmer to specify the style of MessageBox that appears for the Message statement.

1028 - Return code for the last ESC (Read-only) (V. 13)
[1=OK
 2 = Cancel
 3 = Abort
 4 = Retry
 5 = Ignore
 6 = Yes
 7 = No]
This function allows the programmer to determine the user's response to a ESC.

If this would by possible,after Esc,we would already by far!  ???
And, this application already exist!!
« Last Edit: June 08, 2011, 07:52:10 AM by paulerens »

Rob S

  • Hero Member
  • *****
  • Posts: 4262
    • Construction Estimating Program for General Contractors

Isn't this why we need "On Esc" because the esc key press will have terminated the macro, so it will not reach the dialog asking for what to do?  Using "On Esc" would effectively terminate what is happening, and continue the macro at whatever subroutine is specified.

The issue with running your pre-programmed restore sequence is that the macro may not yet have changed the settings in question when the esc key was pressed.

If the this sequence simply restores sys numbers to original, this does not matter. 
User since Pro-design