Advice on implementing undo/redo in a Tool
-
C4D SDK newbie here. I am implementing a geometry creation Tool which works by dragging an initial shape and then allows multiple edits through handle or other drags in the viewport or via attribute changes in the AM. I would like these changes to be undoable while the tool is active i.e. until the tool is finalized via ESC or something happens like the active object changes.
Does anyone have any advice on how best to manage this?
(I reluctantly asked three AIs and got three answers -- hidden tag (Copilot), object base container (ChatGPT) and do it yourself (Claude))
Thanks.
-
Hey @SteveHill3D,
Welcome to the Maxon developers forum and its community, it is great to have you with us!
Getting Started
Before creating your next postings, we would recommend making yourself accustomed with our forum and support procedures. You did not do anything wrong, we point all new users to these rules.
- Forum Overview: Provides a broad overview of the fundamental structure and rules of this forum, such as the purpose of the different sub-forums or the fact that we will ban users who engage in hate speech or harassment.
- Support Procedures: Provides a more in detail overview of how we provide technical support for APIs here. This topic will tell you how to ask good questions and limits of our technical support.
- Forum Features: Provides an overview of the technical features of this forum, such as Markdown markup or file uploads.
It is strongly recommended to read the first two topics carefully, especially the section Support Procedures: How to Ask Questions.
About your First Question
You could look at our edgecuttool.cpp C++ SDK example, it demonstrates both the usage of undos and cinema::InteractiveModeling_Restart, i.e., rolling updates. In some cases
InteractiveModeling_Restartwill not cut it you have to un-roll your undos yourself or even not use undos at all for rolling updates and instead work with a tool finalization logic.By chance I just wrote an example for the latter for the upcoming Python SDK. You will not be able to run it, as the customer release version is missing the Python API to deal with SDS weights, but you can have a look at its code. The idea is simple: Establish a ground truth and operate based on that. But for modelling tools and especially tools that add or remove geometry using undos and
InteractiveModeling_Restartshould be preferred when possible, as it will be usually faster, as the cinema core can pull some tricks you cannot as a third party.Cheers,
FerdinandPlease understand that this example is a preview and might be subject to change.
py-cmd_tool_finalization_2026_2.zip -
Thank you for the pointers. I will digest the examples.