Cancel aborts the remaining macro only when a command is active

I found state-dependent behavior from the Cancel command inside a command macro.

Run this macro:

Polyline 0,0 1,0 Cancel Polyline 0,1 1,1 Enter

Result: nothing is created. The first Polyline is canceled, and Rhino ignores everything after Cancel.

Now run this macro:

Polyline 0,0 1,0 Enter Cancel Polyline 0,1 1,1 Enter

Result: two polylines are created. Because the first Polyline has already completed, Cancel has nothing to cancel; it becomes a no-op and Rhino continues with everything after it.

This makes Cancel state-dependent as a macro control-flow operation:

  • If a command is active, it cancels that command and the remainder of the macro.
  • If no command is active, it cancels nothing and the remainder of the macro continues.

I expected Cancel to have consistent behavior for the remaining macro. Since the documentation says it “cancels the current command,” I would expect it to cancel the active command and then continue processing subsequent macro commands.

This matters for automated command testing: a test cannot safely use Cancel to leave an interactive command and then perform cleanup, save, or exit, because whether those later commands run depends on the exact command state.

I reproduced this in Rhino 9 WIP for Windows. Is this behavior intentional, or is it a bug?

Not sure why are you using Cancel in a macro? I have never used that.

An open-ended command like Polyline needs an Enter to tell Rhino that you are finished adding points. After that the macro can continue or stop. Other commands which have a fixed number of inputs will automatically stop when correct the number of inputs is reached.

Polyline 0,0 1,0 1,-1 Enter
Polyline 0,1 1,1 1,2 Enter
Polyline 0,0 1,0 1,-1 Enter
Circle 0 1
Circle 1,-1 1

Sure, the workaround for Cancel being broken is not to use it.

But I wasn’t asking how to complete a Polyline macro. I was reporting that Cancel behaves inconsistently depending on whether a command is active, and asking whether I misunderstand its intended behavior or whether this is a bug.

Thanks for replying, but if the behavior is broken, avoiding the command does not really address the issue. It should be fixed.

As I said, I have never used Cancel in a macro - and I have written a few. I don’t recall having seen it used by someone else here before your post - I could certainly have missed one or two though - but it’s far from common in any case.

Can you give an example of a macro where the use of Cancel is the only way to make it work correctly?

I’ll reply with another “as I said”:

I am reporting an issue with a command and asking, “Is this behavior intentional, or is it a bug?”

You are ignoring that question and replying, “I have never used that,” as though I had asked how to use it, when to use it, or how to accomplish something that the command appears to do.

Whether I can produce a macro in which Cancel is the only possible solution is irrelevant to the bug report. The issue is that its behavior inside a macro is undocumented and state-dependent.

The behavior of ! is documented:

  • ! at the beginning of a macro cancels any previously running command, then the macro continues.

  • ! anywhere else in a macro cancels the remainder of the macro.

The documentation for Cancel, however, says only that it cancels the current command and deselects objects. It does not document its effect on the remainder of a macro.

What I observe is:

  • Cancel at the beginning of a new macro can cancel a previously running command, clear the selection, and allow the new macro to continue.

  • Cancel after starting a command within that same macro cancels both the active command and the remainder of the macro.

  • If no command is active when Cancel is reached, it does nothing and the remainder of the macro continues.

That is the inconsistency I reported. I am asking whether this behavior is intentional and merely undocumented, or whether it is a bug that should be fixed, not for an alternative way to finish a Polyline.