Problems triggering an action

I'm trying to script the 'Invert Selection' action that appears on the Scene pane menu under Select - shortcut is Ctrl-Shift-I.  I have studied the two scripts referenced here: https://www.daz3d.com/forums/discussion/111426/trigger-menu-action-from-script and come up with this.

actionMgr = MainWindow.getActionMgr();print(String("Number of actions: %1").arg(actionMgr.getNumActions()));		for (m = 0; m < actionMgr.getNumActions(); m++) {	action = actionMgr.getAction(m);	if (action.text == "Invert Selection") {		print(m, action.text, "<", action.className(),"<", action.defaultMenu, action.description,action.defaultShortcut);	}}//action = actionMgr.getAction(236);action = actionMgr.findAction("DzHPInvertSelectionAction");print(action.text,  action.defaultMenu, action.description, action.defaultShortcut);print(String("Action is enabled? %1!").arg(action.enabled));action.trigger();

The output is this:

2018-05-17 21:42:17.646 DEBUG: Number of actions: 756
2018-05-17 21:42:17.668 DEBUG: 201 Invert Selection < DzFacetSelInvertAction <  Inverts the current selection. Ctrl+/
2018-05-17 21:42:17.672 DEBUG: 236 Invert Selection < DzHPInvertSelectionAction < DzHierarchyPane::Select Invert the current selection of items in the scene Ctrl+Shift+I
2018-05-17 21:42:17.723 DEBUG: Invert Selection DzHierarchyPane::Select Invert the current selection of items in the scene Ctrl+Shift+I
2018-05-17 21:42:17.723 DEBUG: Action is enabled? true!

So everything appears to be well and yet, nothing changes in the Scene pane - the one node I have selected stays selected and everything else stay unselected.

Any ideas what I am doing wrong?

 

Comments

  • Richard HaseltineRichard Haseltine Posts: 100,961

    Rob offers

    (function(){		var oActionMgr = MainWindow.getActionMgr();	var oAction = oActionMgr.findAction( "DzHPInvertSelectionAction" );	if( !oAction ){		return;	}		oAction.trigger();	})();

     

  • andya_b341b7c5f5andya_b341b7c5f5 Posts: 694
    edited May 2018

    Thanks, you confirmed I had got the right code to find the action and then trigger it.  The problem seems to be that I am looping through all the nodes in the scene, and retrieving info from some of the methods/properties to print out - just experimenting with what data is available and where.  When I identify a node that is selected, I try to invert the selection.  If I break the loop at that point, the selection is inverted.  If I do not break the loop, but go on to 'look at' other nodes, then the selection does not remain inverted, even though there is no attempt to change the selected or not selected status of any of the other nodes.  That does not feel right, but I can separate the two processes - gathering info and inverting the selection - to resolve the issue.

    Post edited by andya_b341b7c5f5 on
  • Richard HaseltineRichard Haseltine Posts: 100,961

    Why not just use node.select( ! node.isSelected() )?

  • Richard HaseltineRichard Haseltine Posts: 100,961

    I think you are possibly misunderstanding what Invert selection does - it affects everything in the scene, seelcting what is unselected and deslecting what is selected, so running it twice will indeed restore the status quo ante. If you want to invert the scene selection run the action once, no iterating over nodes, if you want to change the state of only certain nodes use my previous post to invert, or simply node.seelct( false ) if you just want to deselect the selected nodes.

Sign In or Register to comment.