undo a command (scripting)
All  1-8  9-15

Previous
Next
 From:  pressure (PEER)
10939.9 In reply to 10939.7 
Hi Michael,

I've been digesting your last couple of messages while trying to figure out how to force a command that doesn't create/destroy geometry to get an undo unit.

I figured out that using moi.ui.propertiesPanel.setAnnotationProp() is a way to do this for my annotation example.

But, I'm still not sure how to get an undo unit when changing object visibility, lock state, or selection state. One hack for getting an undo unit associated with setting hidden=true is:
code:
    moi.geometryDatabase.deselectAll();
    seamEdgesList.setProperty('selected', true);
    moi.geometryDatabase.hide();

But, that doesn't seem quite right. I'm wondering about what gets run when I click on a lock or visibility icon or in the selection dot column in the browser. What happens when I click on the Visible.png icon in the browser?

What gets called when I do selection using the scene browser or object properties dialog?

- Peer
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
10939.10 In reply to 10939.9 
Hi Peer,

re:
> But, I'm still not sure how to get an undo unit when changing object visibility, lock state, or selection state.

There isn't currently any facility exposed for a script command to generate this kind of undo.

Normally in MoI this type of object property manipulation is not done in a dedicated command because it can also be useful to be able to perform them while still running inside of a command.


> What happens when I click on the Visible.png icon in the browser?

The function SceneBrowserItem::OnStatusClick() is called, which among other things calls the internal C++ functions:

SaveSelectionUndo();

AlterStatus( ... );

SetSelectionUndoRevision();


> What gets called when I do selection using the scene browser or object properties dialog?

When you do selection using the scene browser, SceneBrowserItem::OnSelectionClick() is called which among other things calls:

SaveSelectionUndo();

Selects stuff...

SetSelectionUndoRevision();


When you do it selection by clicking on a label in the object properties dialog, detailedFilterClicked() is called which among other things calls:

SaveSelectionUndo();

... Manipulates selection ....

SetSelectionUndoRevision();


So what you need to do for having a selection undo is to call SaveSelectionUndo() first, then after all changes to hidden/locked/selected have been done SetSelectionUndoRevision() needs to be called to establish which geometry revision number the selection undo is tired to.

Selection undo doesn't actually generate a normal undo unit that goes in the undo stack, it's a special case in undo where before processing anything from the regular undo stack it checks if there is a stored selection undo available that matches the current database revision number and if there is restores that instead of performing the regular undo.

I'll set up script access to SaveSelectionUndo()/SetSelectionUndoRevision() off of geometryDatabase so it will be possible for you to use it too.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  pressure (PEER)
10939.11 In reply to 10939.10 
Hi Michael,

Thanks for explaining the inner workings of selection undo and for setting up access. It's going to be nice to be able make some script commands undoable.

- Peer
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  pressure (PEER)
10939.12 In reply to 10939.10 
Hi Michael,

I've had some trouble with undoing scripts that include an object picker. In one case the object picker seemed to interfere with creation of a selection undo unit. Now I've got a situation where I'm using an object picker to get an edit point so that I can move that edit point.

Here's a self-contained snippet. If you run it on a new blank file you'll see:



And then if you hit Undo you'll see an intermediate stage of what the script did:



No matter how many times you hit Undo you'll never get back to an empty environment.

Is there a way for me to clean this up so that it's neatly undoable?

code:
var index = 0;
var destinationPoint = moi.vectorMath.createPoint(1,1,1);

var rect_factory = moi.command.createFactory( 'rectangle' );
rect_factory.setInput( 0, moi.vectorMath.createFrame() );
rect_factory.setInput( 1, null );
rect_factory.setInput( 2, 5 );
rect_factory.setInput( 3, 5 );
rect_factory.setInput( 4, false );
var objList = rect_factory.calculate();
moi.geometryDatabase.addObjects(objList);

var obj = objList.item(0);

obj.showPoints = true; // must show points to make them editable
obj.setEditPointSelected(index, true);

/*
non-interactive object picker with allowEditPoints()
simply to get edit point into an objectList so that it can be manipulated
*/
var objectpicker = moi.ui.createObjectPicker();
objectpicker.allowEditPoints();
objectpicker.done();
var editPointInList = objectpicker.objects;

var basePt = obj.getEditPoint(index);

var factory = moi.command.createFactory('move');
factory.setInput(0, editPointInList);
factory.setInput(1, basePt)
factory.setInput(2, destinationPoint);

// remove the original object, gather up the newly moved object, and add to database
moi.geometryDatabase.removeObject(obj);
var movedObjInList = factory.calculate();
moi.geometryDatabase.addObjects(movedObjInList);

// re-hide the edit points
movedObjInList.item(0).showPoints = false;


- Peer

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
10939.13 In reply to 10939.12 
Hi Peer, try this:

code:
var index = 0;
var destinationPoint = moi.vectorMath.createPoint(1,1,1);

var rect_factory = moi.command.createFactory( 'rectangle' );
rect_factory.setInput( 0, moi.vectorMath.createFrame() );
rect_factory.setInput( 1, null );
rect_factory.setInput( 2, 5 );
rect_factory.setInput( 3, 5 );
rect_factory.setInput( 4, false );
var objList = rect_factory.calculate();
//moi.geometryDatabase.addObjects(objList);

var obj = objList.item(0);

obj.showPoints = true; // must show points to make them editable
obj.setEditPointSelected(index, true);

/*
non-interactive object picker with allowEditPoints()
simply to get edit point into an objectList so that it can be manipulated
*/
/*
var objectpicker = moi.ui.createObjectPicker();
objectpicker.allowEditPoints();
objectpicker.done();
var editPointInList = objectpicker.objects;
*/

var basePt = obj.getEditPoint(index);

var factory = moi.command.createFactory('move');
factory.setInput(0, objList);
factory.setInput(1, basePt)
factory.setInput(2, destinationPoint);

// remove the original object, gather up the newly moved object, and add to database
moi.geometryDatabase.removeObject(obj);
var movedObjInList = factory.calculate();
moi.geometryDatabase.addObjects(movedObjInList);

// re-hide the edit points
movedObjInList.item(0).showPoints = false;


That removes moi.geometryDatabase.addObjects(objList); , and removes the objectpicker piece
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  pressure (PEER)
10939.14 In reply to 10939.13 
Thanks Michael for the edited code!

What you posted works for me by itself, but when I try incorporating it into the larger thing I'm working on I still have the same kind of problem with undo.

I removed the other instances of moi.geometryDatabase.addObjects() and don't have any object pickers, but the problem persists.

Is there a general principal I can use to troubleshoot this?

- Peer
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  Michael Gibson
10939.15 In reply to 10939.12 
Hi Peer, it looks like there's a bug where undo can get confused in certain cases if you both add and remove the same object within the same command.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All

 

 
 
Show messages: All  1-8  9-15