A most Basic Question. How to Print a variable [Solved]

MorgalothMorgaloth Posts: 12

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

  • Richard HaseltineRichard Haseltine Posts: 55,071

    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

  • MorgalothMorgaloth Posts: 12

    Thank you Richard! That worked perfectly. It should make understanding what I'm doing a lot easier.

  • Syrus_DanteSyrus_Dante Posts: 983

    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.

    print("The offsets are: nXoffset[%1] nYoffset[%2]"
    	.arg(nXoffset)
    	.arg(nYoffset));

    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:

    print("The offsets are: nXoffset[" + nXoffset + "]", "nYoffset[" + nYoffset + "]");

    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.

    print("Node: %1 | Name: %2 | Label: %3"	
    	.arg(aTemplate.length+1, 3)	//fieldWidth=3 stands for a margin spaces of three digits eg. __5, __7, _15, 156
    	.arg(sName, 20)	//fieldWidth=20 for names - right alignment
    	.arg(sLabel) );

    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:

    print("two new-lines at the end\n\n");
    print("will add an empty line");

     

  • MorgalothMorgaloth Posts: 12

    Thanks for all the new info SD. I'll have to play around with it when the time comes.

Sign In or Register to comment.