Displays text in the Script Editor. You can use this function to display the contents of attributes and variables.
print(string text)
print(vector number)
print(float number)
print(int number)
print(array number)
text is either a string enclosed in quote marks or an attribute name or string variable containing text.
number is a number without the quote marks. Numerical arguments display as strings.
There is no returned value for this function.
Note the following display considerations.
- You can format displayed text with standard C language escape characters. For example, you can create a new line with “\n” or a tab character with “\t” in the argument.
- Displaying a floating point value shows the number many digits to the right of the decimal point, for example 0.3333333333.
- Insignificant 0 digits are truncated from floating point numbers. For example, floating point number 2.0 is displayed as 2.
- A vector appears with a space separating components and no double angle brackets. Each vector component has a floating point value with up to 10 digits to the right of the decimal point.
For example, a vector <<1.518876356, 0, -1.290387446>> appears in the Script Editor as this:
1.518876356 0 -1.290387446
- Arrays are formatted with each array element on a new line.
- You can use the + operator to join two strings in an argument:
"text1" + "text2"
This is displayed as:
text1text2
- You can also append a number to a string:
"text" + 1
This is displayed as:
text1
- You cannot use the + operator with a string array as arrays aren’t strings (though they can contain strings).
- If you assign a string to a variable that’s not a string data type, the following text appears if you display the variable:
Variable data type String assignment Data displayed float "3.14" 3.14 int "3.14" 3 vector "3.14" 3.14 0 0 float "pi is 3.14" 0, error message As shown in the last row of the table, if a variable is assigned a string that starts with a non-numerical character, Maya converts the string to 0.
Examples
print(time); print("\n");
The first statement displays the value of time. The second statement displays a new-line character after the value of time, so the time appears on a separate line in the Script Editor.
float $f = 3.14159; print($f);
Displays the floating point number 3.14159.
string $s = "Hello There"; print($s);
Displays the string Hello There.
vector $v; $v = <<1.2,2.3,3.4>>; print($v);
Displays the vector as 1.2 2.3 3.4.
string $a[]; $a = eval("ls -lights"); print($a+" are the lights in my scene.\n");
The print function causes an error message because you cannot use the + operator with a string array.