How to Select Node/Object in Scene by script + Clear all Selections by script?
Shadowz
Posts: 45
So theres two scripts I need, 1 is to simply select an object/note in my scene and the other is to clear all selections in my scene.
The goal is to first clear all selections in my scene and then select the required node/object so that I can apply stuff like materials, presets, other custom script actions without having to Find & select the object myself from the scene.
I am a total newbie with stuff like this so any help is much appreciated.
Post edited by Shadowz on
Comments
Toggling seelction on or off just needs node.select( true/false ), wheer node is the node you wish to select/deselect. http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/node_dz#a_1ad43530e0dd2a0a0e6d325444f5e9c25d
Finding nodes, by naem or label or just getting a list, is done through DzScene http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/scene_dz
So you could use
var aSceneNodes = Scene.getSelectedNodeList();
to get all of the currently selected ndoes, then go through the array doing select(false ) on each to end up with nothing selected. Then you need to get the node you want selected, by name of label or whatever, and use select( true ) on that.
You probably want to end up with something like this
(function(){
// Setup so you can undo
beginUndo();
beginNodeSelectionHold();
// Deselect everything
Scene.selectAllNodes (false);
// Do your custom thing here, something like this
var oMyNode = Scene.findNode ('My Node Name');
oMyNode.select();
App.getContentMgr().mergeFiles (['/Presets/My Preset.duf', '/Materials/My Material.duf']);
// Finish undo setup
restoreNodeSelectionHold();
acceptUndo ("My custom thing");
})();
Amazing thank you, its what I needed. I am a little unclear on these and why I would need it:
beginUndo();
beginNodeSelectionHold();
restoreNodeSelectionHold();
acceptUndo ("My custom thing");
But from your code I got to achieve what I needed to do which is this:
Thank you, I can now run a script that can find a node and apply whatever is required like presets, materials etc.
Also do you happen to know how to also run custom script actions or scripts by code?, kind of like the line where you showed how to apply the materials etc. That way if I need to run another script that has a specific function, I can just call that through the script execution. Sorry to shoehorn another question here. Regardless, I am happy that I got my original question solved.
beginUndo() and acceptUndo(...) will add an entry to the undo stack for everything that happens in between them. Then you can go to 'Edit -> Undo' to undo whatever your script did (for example, if you had the wrong node selected when you ran it).
beginNodeSelectionHold() and restoreNodeSelectionHold() will save the list of currently selected nodes and restore it when finished, so that any selection changes you make are only active while your script is running.
You can call an external script by using a DzScript object. See the Sub Script sample script for an example.
Ah, awesome very handy. I assumed even if I ran the script without that, the undo would still work.