Is there a way to group a set of commands to be put on the undo stack as one?

I have done my first bit of ruby code for SU! Woo hoo!

But now I was wondering if I could group a bunch of commands that place a bunch of entities on to the model as one? Since the tool is supposed to look like it’s a single command, I should allow it to be undone in one command too.

Have a look at model#start_operation and model#commit_operation

2 Likes

Excellent! That was what I was looking for. Thx

FTR, please only refer to a “tool” as a code object that implements a Sketchup::Tool class interface.

If it is a command, ie a sequential set of tasks fired by a UI element (menu item or toolbar button) then it is a command rather than a tool.

From the SketchUp Extension UX Guidelines

Only Call Tools Tools

In a wider context a tool could mean anything you use to get a job done, but in SketchUp a tool more specifically means something that listens to mouse and/or keyboard input (implements the tool interface). Line tool and Circle tool are tools while Make Components and Shaded With Textures are not tools. Avoid referring to commands “tools” when they aren’t.

And you are also misusing the term “command” in the programming sense …

You are referring to code statements.
These statements are usually a combination of reference assignments and method calls.

Ex:

inst = ents.add_instance(comp_def, transform)

The tool asks the user for some input (using the tool API) and the does a series of commands based on that. So what are you saying that it is then? A tool or a command?

Yeah.

A tool if it acts like it, walks like it and talks like it.

:duck:

Most tools do perform tasks based upon user input (picking points, manipulating objects, etc.)
Think about the user manipulating the model in an interactive way, and that is a tool.

But just acting upon the model as a whole, or what context or object has already been selected, and then doing something with that (such as exporting, tagging it with data, etc.) would be a command. (The latter is a context command because it acts upon the selected context. These commands are usually inserted conditionally onto the right-click context menu. As a counter-example, a tool is almost never inserted onto the context menu.)

Sketchup.active_model.start_operation "My_Extension"

My_Extension name appears in undo. As a new politician in the Sketchup team, this name is important and should refer to your extension. It should be a unique name. When the user sees this name in undo list, can understand it is your extension.

Yes. Thanks. I hope that helps someone else, as I am aware of this. Thx again