Property not found in some cases. Why?
eonian_839392445b
Posts: 5
HI Daz Team and fellow scripters.
I try to write a script to select a property and changed its value via script.
Unfortunately, while it works from some of them, some come back not found, even if I used the exact same method.
It looks like a problem that some properties are nested, I could be wrong about that.
Does anyone have an idea how to solve this problem?
Thanks for your help
Here is the script:
// Function to select a characterfunction selectCharacter(characterName) { // Get the figure by label var figure = Scene.findNodeByLabel(characterName); if (figure == null) { print("Could not find figure: " + characterName); return; } // Select the figure figure.select(); print("Figure " + characterName + " has been selected."); return figure;}// Function to list all properties of a characterfunction listProperties(figure) { var numProperties = figure.getNumProperties(); var result = []; for (var i = 0; i < numProperties; i++) { var property = figure.getProperty(i); result.push(property.getLabel()); } return result;}// Function to set a specific property of a character to a given valuefunction setProperty(figure, propertyName, value) { var numProperties = figure.getNumProperties(); for (var i = 0; i < numProperties; i++) { var property = figure.getProperty(i); if (property.getLabel() === propertyName) { property.setValue(value); print("Set property " + propertyName + " to " + value); return; } } print("Property " + propertyName + " not found");}// Call the function with the name of your charactervar figure = selectCharacter("name of the character in the scene"); // replace with your character nameif (figure) { var properties = listProperties(figure); print("Properties: " + properties.join(", ")); setProperty(figure, "Label of the property in the parameters panel", 1.0); // set the property to 100%} else { print("Character not found");}
Comments
ok, after trying everything I found a way. I don't understand why Daz does not let us access the parameters in just one way and that's it. Very confusing.
Some properties belong to the shape, or are clones of proeprties on other nodes.
There is a great sample for getting properties:
http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/properties/node_properties/start
There is also another way, which is to use DzSceneHelper. Note that when you use getPropertiesOnNode() that you have to tell it whether to include the modifiers or not. If you don't get modifiers then you will only get node properties and morphs will be left out.
thanks Guys for the feedback!
I figured it out using Scene.getNumNodes() and node.getProperty() which seems to be the only reliable way to grab all the properties/parameters whether they are associated with or not with your selected character.