Way to fire a command without it adding to the undo stack?

Hi there,

As the title says, is there a way to fire a command without it being recorded in the undo-stack?

I use a custom command SetTargetToCursor quite frequently: CommandTracker shows I’ve used it 6.5K times on a file that I’ve been working on since late April.

What bothers me is there are situations where I’m looking around my model a lot before modelling anything or wanting to undo something, so I’ll end up using the command a lot. When I want to undo something, I have to hit Ctrl-Z a bunch of times to go past all my SetTargetToCursor commands before I get to a relevant modelling command.

So my command history often looks like this:

I tried adding SetTargetToCursor to the ‘Never repeat these commands’ box in Options > General but no luck.

If it helps, the command is a plug-in of a Rhinoscript that I compiled using the built-in script compiler. Could there be a way to add some code to pause and start the undo-stack recording at the beginning and end of the script respectively?

If anyone has any ideas, I’d appreciate it.

– Vince

Where does your custom command come from, the SetTargetToCursor one? If you made it, can you share the code, so we can take a look at what is going on?

As long as the document is not modified or an undo record is started from the command code, the command should not get on the undo stack.

1 Like
import Rhino
doc = Rhino.RhinoDoc.ActiveDoc
doc.UndoRecordingEnabled = False
Rhino.RhinoApp.RunScript("SetTargetToCursor", True)
doc.UndoRecordingEnabled = True

You can save this file in the script folder %AppData%\McNeel\Rhinoceros\7.0\scripts and use this macro with a key combination or alias:
_NoEcho !_-RunPythonScript SetTargetToCursor.py

SetTargetToCursor.py (164 Bytes)


Hi Menno, sure thing:

SetTargetToCursorSteps_VCD.rvb (1.4 KB)
SetTargetToCursor_VCD.rvb (4.9 KB)

These are modified versions of Jarek’s SetTargetToCursor script

Which I used the script compiler to make this ‘plugin’:
SetTargetToCursor.rhp (15.5 KB)

From what I can tell a command that does not modify the document will not be recorded in the undo stack.
So that suggests your script is adding something to the document.
I see a Rhino.AddTextDot and then later it looks like the script deletes it.
If you can do without that code then I think the undo problem will go away.


That’s a good point @jim .
@vcruzdesigns I just tested the code without add/delete the dot object and in that case the script does not get recorded in the Undo stack, which should solve your original problem. I don’t think the dot is that important anyway.

1 Like

@Mahdiyar - it’s an interesting idea, but unfortunately you cannot use _-RunPythonScript while running another command. And this particular script is essential to be able to use while working with other commands, which works great with RhinoScript.

For me it is a very serious limitation of Python scripts, it’s been discussed before but seems like there is no interest in making it work @ RMA for now. YT item here, marked Future:
RunScript vs RunPythonScript inside commands problem : RH-56354 (myjetbrains.com)

I hope it’s not heading this direction @Alain :

1 Like

Thanks @jim and @Jarek, the change works. The dot wasn’t necessary and actually, the command feels a little quicker to run now too.