function getDisplayAsPercent not working?
I'm trying to get all sliders/properties for a character, I get a list of the changed ones, and I also want to see if the slider is displayed as a percentage or not.
But when I try to call getDisplayAsPercent on a DzFloatProperty it gives me an error:
TypeError: Result of expression 'p.getDisplayAsPercent' [undefined] is not a function.
But I've checked the object and is a DzFloatProperty also, printed all its methods with below function and getDisplayAsPercent appears in the list.
function getMethods(obj) { var result = []; for (var id in obj) { try { if (typeof(obj[id]) == "function") { result.push(id + ": " + obj[id].toString()); } } catch (err) { result.push(id + ": inaccessible"); } } return result;}
For reference this is the code I'm running in the IDE Script Pane:
(function () { function getGroupProperties(oGROUP, bTRAVERSE, bRECURSE) { var aProperties = new Array(); if (!oGROUP) { return aProperties; } else { const nPROPERTIES = oGROUP.getNumProperties(); for (var i = 0; i < nPROPERTIES; i++) { aProperties.push(oGROUP.getProperty(i)); } if (bRECURSE) { aProperties = aProperties.concat(getGroupProperties(oGROUP.getFirstChild(), bTRAVERSE, bRECURSE)); } if (bTRAVERSE) { aProperties = aProperties.concat(getGroupProperties(oGROUP.getNextSibling(), bTRAVERSE, bRECURSE)); } } return aProperties; } function getNodeProperties(oNODE, bTRAVERSE, bRECURSE) { const oPROPERTY_GROUP_TREE = oNODE.getPropertyGroups(); const oPROPERTY_GROUP = oPROPERTY_GROUP_TREE.getFirstChild(); return getGroupProperties(oPROPERTY_GROUP, bTRAVERSE, bRECURSE); } function run() { const oNODE = Scene.getPrimarySelection(); if (oNODE) { const aPROPERTIES = getNodeProperties(oNODE, true, true); } else { return; } for (var i = 0; i < aPROPERTIES.length; i++) { p = aPROPERTIES[i]; if (p.isNumeric()) { pMax = p.getMax(); pDef = p.getDefaultValue(); pMin = p.getMin(); pVal = p.getValue(); //here it gives error pPercent = p.getDisplayAsPercent(); if (p.getDefaultValue() != p.getValue()) { print(p.getLabel()+": "+pVal+(pPercent?"%":"")); } } } return null; } run();})();
Code above is licensed as: https://creativecommons.org/licenses/by/3.0/
Original code by: Rob Whisenant from http://docs.daz3d.com/doku.php/artzone/wiki/user/rbtwhiz/technotes/daz_script/node_properties/start
Some minor changes to get the percent style display.
Comments
That appears to be one of Rob's sample scripts - please make sure you adhere to the license terms. http://docs.daz3d.com/doku.php/artzone/wiki/user/rbtwhiz/technotes/daz_script/node_properties/start , of which http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/properties/node_properties/start is a newer and more robust version.
Edited some mistake I had in the code above, for the sake of clarity.
But tried the new code you linked (as newer and more robust) by adding a similar line:
And I still get same error:
Script Error: Line 186
TypeError: Result of expression 'oProperty.getDisplayAsPercent' [undefined] is not a function.
Stack Trace: ()@:186
So why it tells me that getDisplayAsPercent is not a function when I know it is?
You still need to adhere to the license, which is given on the page with the script.
You are checking p.isNumeric() and assuming if true that the property is a DzFloatProperty. This is incorrect.
If you only want float properties here you should check p.inherits ('DzFloatProperty') instead.
That works, though the main point is to link back to the original.
In addition to what Omniflux points out, the script you are taking as source is for the older version of the scripting engine from Daz Studio 1/2 and it has some differences - for one thing, the const keyword is not supported. Some of your variables also have scope issues you need to be careful with, as it can lead to unplanned changes to value.