A most Basic Question. How to Print a variable [Solved]
Morgaloth
Posts: 23
I'm trying to learn daz scripting, I've worked with JS before, though it's been awhile. Seeing the results of variable along the way has always helped me understand whats going on. I have used a lot of the examples and broke them down, but a problem I run into is when I do something as as simple as:
var node = null;
node = Scene.getPrimarySelection()
print (node);
The printed result is :
[object Object]
rather than Genisis8Female, or whatever I have selected. I know its got a value, because I can manipulate it with If statements correctly.
Anyone have any idea if this is normal behavior or what I've done wrong?
Post edited by Morgaloth on
Comments
You need node.getLabel(), I think. Complex objects, such as a node, can't simply be printed. Rob points out this set of sample scripts http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/start#nodes
Thank you Richard! That worked perfectly. It should make understanding what I'm doing a lot easier.
Hi Morgaloth,
I've learned a new thing about print(); recently. First if you want to print the variable has to be of type string or number. In examples you often see something like this where the values gets printend in between the text with the placeholders %1, %2, %3 and the variables in the .arg() method.
But you can also write it like this where the comma will add a space and the pluss will add the next variable of type number or "string" without a space:
In my PowerPose Templates generator script I've also used the second argument in the .arg() method called fieldWith for numbers and strings to get a better listing of the bones.
You can also use new-line "\n" and tabstop "\t" for text formatting in the print function. The print function does a new-line by itself by the next call but if you want to add an empty line within a print function you can write it like this:
Thanks for all the new info SD. I'll have to play around with it when the time comes.