Hi Peer,
re:
> If I have something selected, run this:
> <...>
> and then hit Undo, the new line goes away, but the previously selected object stays unselected.
That's normal behavior, when a geometry undo unit is created which happens after the command exits, the geometry undo unit will have whatever selection is on the object at that time.
Since the previously selected object was not either created nor deleted during the command's execution, it will not get a geometry undo unit generated for it and so it will be unaffected by doing an undo.
re:
> But, if I swap the order of the last two lines:
> <...>
> Then hitting Undo once causes the previously selected object to become selected again, while hitting
> Undo a second time makes the line finally go away.
This happens because moi.geometryDatabase.deselectAll(); generates a "selection undo" unit in addition to the geometry undo unit.
Selection undo units are ephemeral and only undo the most recent selection or visibility change. You can stop one from being generated here by setting selected=false directly instead of using moi.geometryDatabase.deselectAll(); Like this:
moi.geometryDatabase.getSelectedObjects().setProperty( 'selected', false );
> How should I get a command to act like a single thing (1 undo unit generated ?) so that hitting Undo
> once brings back the scene exactly as it was before running the command?
MoI's undo does not operate like that, it is not guaranteed that selection of objects that were not created or destroyed will be modified when doing an undo.
But if you want consistency between these 2 variations, then use moi.geometryDatabase.getSelectedObjects().setProperty( 'selected', false ); instead of moi.geometryDatabase.deselectAll();
- Michael
|