How to get/set the collapsed-expanded state of a DzNode in the Content tab
3dcheapskate
Posts: 2,719
The only related thing I can find is the isHidden()/setHidden() in the DS3 DzNode documentation.
But it's not them - they just remove the nodes completely from the Scene pane.
Comments
Do you mean the Scene pane? I'm not at all sure it's possible - it is a UI thing, not a feature of the content itself - even DS doesn't remember it between sessions.
Indeed I do. I was thinking like you until I found the isHidden()/setHidden() - quoting from the DS3 DAZ Script2 docs:
void DzNode::setHidden ( Boolean onOff )
Hide or show this node in the interface.
Parameters:
onOff If true, the node will not appear in the hierarchy list. If false, the node will be displayed in the scene hierarchy.
And that seems very much to be a UI thing...
Not quite sure how to determine if a given node is expanded or collapsed, but I'd imagine if there it's somewhere in this neighborhood.
Yes and no - hidden/shown controls whether the node is visible at all, not how it is listed (collapsed/expanded) if it is shown.
You could build on djigneo's idea by using select( true ) on the nodes to expand to the node, but that wouldn't give feedback about the current state.
djigneo's code works great in DS3 and 4 if the node in question existed before running the script.
However, if the same script first creates the node and its children and then expands the node with djigneo's code, then the parent node always appears collapsed.
(Of course, this effect may be specific to my script (2000 or so lines) - I haven't done a test with a simple script yet...)
My specific requirement is to create a node and two child nodes in my script, and to make sure that all three nodes are shown (i.e. parent node expanded) on the Scene pane.
Have you tried using update() on the node(s) first? I'm not sure if that will help - it may be aimed at the viewport/renderer, not the Scene pane.
I'm not bothered about checking the expanded/collapsed status, so the inability to expand the parent node if the script has just created the parent and child nodes is the only thing missing for me.
Just tried Richard's 'update()' suggestion, before and after djigneo's code, on the parent node and both child nodes, but it doesn't seem to make any difference in either DS3 ar DS4.8). If I create the nodes in my script the parent node is still collapsed. Still need to try with just a minimal script though.
Not a big problem if I can't get the node to display expanded first time - it's just that seeing the visibility status of the two child nodes after running my script is helpful. :)
Interestingly, using DzHierarchyPane::refresh() in addition to DzNode::update() fixes the problem in DS3, but NOT in DS4 (tested with DS4.8 and 4.5)
wbNode.update();
wbIblNode.update();
wbSunNode.update();
// Ensure the Worldball node isn't collapsed
var oMainWindow = App.getInterface();
var oPaneMgr = oMainWindow.getPaneMgr();
var oHierarchyPane = oPaneMgr.findPane(DzHierarchyPane.className());
wbNode.select(true)
oHierarchyPane.refresh()
oHierarchyPane.expandSelected();
oHierarchyPane.refresh()
wbNode.update();
wbIblNode.update();
wbSunNode.update();
oHierarchyPane.refresh()
(Not sure if all the update() and refresh() calls are required)
Sttill keeping my fingers crossed that I may get this to work in DS4 too...
...and it's only the refresh() before expandSelected() that's necessary for it to work in DS3, the other refresh() and upate() calls aren't necessary
var oMainWindow = App.getInterface();
var oPaneMgr = oMainWindow.getPaneMgr();
var oHierarchyPane = oPaneMgr.findPane(DzHierarchyPane.className());
wbNode.select(true)
oHierarchyPane.refresh()
oHierarchyPane.expandSelected();
So just DS4 now...
Here's the simplest complete script that demonstates the problem - save this as "TEST.dsa", make a copy of any Poser prop PP2 file and call that "TEST.pp2", and put them both in the same folder (I think it can be anywhere that you can see from the DAZ Studio Content pane, although I always put them in something like "/Runtime/Libraries/Props/Test/"). Then run the script by (double-)clicking the icon in the Content pane. It simply loads three copies of the prop, parents the 2nd and 3rd to the 1st, then expands the parent node in the Hierarchy pane.
loadPP2 = function()
{
origNodes = Scene.getNodeList();
if ( App.getImportMgr().readFile( getArguments()[0] ) == 0 ) {
var newNodes = Scene.getNodeList();
}
}
loadPP2();
loadPP2();
loadPP2();
aBalls = [];
allNodes = Scene.getNodeList();
for( n = 0; n < allNodes.length; n++ )
if (allNodes[n].getLabel().left(9) == "WorldBall")
aBalls.push(n);
wbNode=allNodes[aBalls[0]]
wbSunNode = allNodes[aBalls[1]]
wbIblNode = allNodes[aBalls[2]]
wbNode.addNodeChild(wbSunNode);
wbNode.addNodeChild(wbIblNode);
var oMainWindow = App.getInterface();
var oPaneMgr = oMainWindow.getPaneMgr();
var oHierarchyPane = oPaneMgr.findPane(DzHierarchyPane.className());
wbNode.select(true)
oHierarchyPane.refresh()
oHierarchyPane.expandSelected();
//oHierarchyPane.closeSelected();
In DS3 this works as I'd expect, expanding the parent node. In DS4 the parent node is always collapsed.
To double check I changed expandSelected() to closeSelected() - DS3 now correctl.y collapses the parent node. DS4 is unchanged (i.e. parent node is collapsed, which in this case is correct)
So it looks to me that DzHierarchyPane.expandSelected() isn't working in DS4.
{Edit 4Dec: Two other things are important to reproduce the problem with this script:
1 - It seems the two files MUST be in a mapped Poser runtime. Putting them in [AnyDazContentFolder]/Scripts/ for example causes the script to crash.
2 - The number and text in the "...if (allNodes[n].getLabel().left(9) == "WorldBall")..." line must match the prop name in the PP2.
Could you report this as a bug please.
Submitted as a bug report -
Request #206032
DzHierarchyPane::expandSelected() doesn't work in DS4