Q100482: Using the Comp Script Command dialogue to run TCL or Python commands

Follow

SUMMARY

This article will cover the use of the Comp Script Command dialogue box within the Node Graph, to run single-line TCL or Python commands.

MORE INFORMATION

The Comp Script Command dialogue box is a quick method to run a single-line Python or TCL command directly into Nuke. This saves time when running a simple command that results is a returning value or action, by not needing to create longer Python scripts that require definitions. This is a good option if you only require a single operation to occur.

Below is shown how the Comp Script Command dialogue box can be used with the TCL command of getenv, to set an environment variable. The NUKE_PATH environment variable which stores the path location of the Nuke directory, will be used in the following example:

1. With the cursor hovering in the Node Graph, press the ‘x’ key. This will bring up the Comp Script Command dialogue box.

tcl.PNG

2. In the Command text box enter the following snippet and click ‘OK’.
getenv NUKE_PATH

3. A new dialog will appear returning the current value of the NUKE_PATH environment variable.

result.PNG

NOTE: If you do not currently have an environment variable set, you will receive a dialog letting you know it is undefined. 

error.JPG

The above example is used to display the value of an environment variable. This can be used to create and relay back many single-line commands.

Additional usage examples:

  • Using TCL: Checking the amount of independant Read nodes used within the script and the script’s location:

script_info

  • Using Python: Creating a Node with preset values within the Node Graph:

nuke.nodes.Blur(name="Big Blur", size=10)

A dialog will return the values of all knobs that have been set.

  • Using Python: Altering an existing Nodes value, based upon its class the Node Graph: 

[node.knob("size").setValue(100) for node in nuke.allNodes("Blur")]

         After altering the value, a Boolean statement will be returned via a dialog that allows confirming or denying the change.


FURTHER READING

For more information on Python commands, TCL commands and environment variables please refer to the documentation linked below:

Python Developers Guide

Nuke TCL Functions

Environment Variables List

 

    We're sorry to hear that

    Please tell us why