Undo/Redo inisde command (Rhinocommon c#)

rhinocommon
undo

#1

Hi,
its possible to implement Undo/Redo feature inside command. For example, in class Rhino.Input.Custom.GetPoint, when I get a lot of points in the loop, I wanna to implement undo/redo for single point. Just as in the Polyline command in Rhino.

Thanks for help.


(Dale Fugier) #2

Hi Marcin,

The Polyline command maintains an array of picked points. When you click the Undo option, it simply removes the last element in the array.

Does this help?

– Dale


#3

Thanks,
I know, but my Command code looks like this:

// Rhino.Input.Custom.GetPoint Class      
gcp = new GetCircleRadiusPoint(new Point3d(0,0,0),gmeshes,block,window);
                gcp.AcceptUndo(true);
                gcp.SetCommandPrompt("Point o object (Press ESC or ENTER to cancel...)");
              
           

                gcp.Constrain(gmeshes, false);
             
               for(;;)
                {
                  // Begin undo Record
                    gcp.Get(true); //get points while left mouse button is up
                 // End undo Record
                    if (gcp.CommandResult() == Result.Cancel)
                    {
                        break;
                    }
                }

This command get points on Mesh while user press Enter o Esc. Undo works only on whole Command,
I do not know how to write code to Undo work in each call on gcp.Get () method;

Thanks for help


(Dale Fugier) #4

Hi Marcin,

Does this sample give you any hints?

https://github.com/dalefugier/SampleCsCommands/blob/master/SampleCsGetMultiplePoints.cs

– Dale


#5

Very thanks Dale,

This piece of code solved the problem:

  else if (res == GetResult.Undo)
                {
                    // my UNDO code
                }

so simple, GetResult.Undo :slight_smile: I missed it in reading Rhinocommon docs.
Thanks

Marcin