Drag-and-Drop
TouchDesigner supports Drag-and-Drop functionality as a shortcut to complex import/export and copy/paste functionality. Drag-and-Drop functionality allows you to:
- Import TouchDesigner-readable files.
- Export data from TouchDesigner nodes to external applications.
- Copy and/or move nodes from one TouchDesigner network to another.
- Add TouchDesigner-readable file(s), Panel components or TouchDesigner nodes to open control panels.
Panel Components have options for Drag and Drop on their Drag page of parameters. These parameters can be used to inherit the Drag/Drop settings from the panel's parents, or to force Drag/Drop on or off.
Contents |
How Component Drag-and-Drop Works
- Anything dropped into a network that Allows Drop will be handled by the Network's Drop Script, regardless of whether you are dropping onto a node viewer, a control panel view, or a network editor in either list view or node view. No menu will popup. For the root network, the Drop script used is /sys/drop
- By default, Components Do Not Allow Drop.
- If a Component Does Not Allow Drop, you will only be able to drop things into it via the network editor list or node view. A menu may popup to give you a list of options.
- If the node being dropped has a Dropped Component or Drop Destination Script, then the Move option will not be available.
- A node that has a Dropped Component or Drop Destination Script will still drop as itself if you drop it onto parameters or Text DATs. It will save as a *.tox of itself if you drop it onto a windows desktop or folder.
A control panel view of a component cannot be dropped onto a windows desktop or folder
Drop Scripts - Text
A component's Drop Script would get run when you drop another component or an external file into that component.
Each component network can be set to allow dragging-and-dropping. In a component's parameter dialog, there is a Drag tab where you can modify the settings. You can set a components to use its parents settings, or to use custom scripts. By default, the settings of the root folder for Dragging is Do Not Allow Drag and for Dropping Do Not Allow Drop, with the default Drop Script specified at /sys/drop.
To set up your own Drop Script, set your component's parameter Drop to Allow Drop, and enter the path for the DAT specifying your Drop Script onto the Drop Script parameter. This DAT will be executed whenever something is dropped onto this component. The parameters passed to the Drop Script are:
- $arg0 - fullpath of this script
- $arg1 - dropped node name, chop channel or file name, depending on what is dropped
- $arg2 - x position in network coordinates when the mouse was released
- $arg3 - y position in network coordinates when the mouse was released
- $arg4 - the number of the item being dropped
- $arg5 - the total number of items being dropped
- $arg6 - the operator type or file extension
- $arg7 - the fullpath of the network or node the node or channel was dragged from, or the parent directory
- $arg8 - the network accepting this drop
Drop Script - Tables
If you want to process individual node types or file types, you can use a drop table. Specify a Table DAT in the drop script field. Touch will automatically look for 2 columns in the table. The first column should indicate the data type and the second should indicate the Text DAT that holds the script to process that data type. Touch will call the script for each data and with the above parameters. Here is a sample drop table:
chop chop_script handle chop nodes sop sop_script handle sop nodes channel channel_script handle channel data cmd cmd_script runs a .cmd file tox tox_script loads a .tox file
Columns are not limited to two, but only the first two columns will be used to process drops.
Drag Scripts
You can specify whether a component is allowed to be dragged. The default settings for root is Do Not Allow Drag. This means that you cannot click on the control panel view of a component and drag it to a network you can drop in. However, you will still be able to drag the Node View of that component and drop it.
There are a couple of ways to modify what operator will be dropped when you drag a Component. The Dropped Component parameter is the easiest way to specify an alternative operator to drop. Note that this alternative operator must exist, otherwise the component itself will be dropped. The alternative is only used when dropping onto a network or control panel. Text pasted via dragging and dropping, or files saved via dropping onto the desktop, will still use the original.
Drop Destination Scripts
A more flexible way to specify alternatives to drop, is to use the Drop Destination Script. If a Drop Destination Script is specified, a temporary network is created and the component (or the alternative operator specified in Dropped Component) is copied to this network. You can add or modify operators in this network. (Do not run commands that echo to the textport.)
Then echo a list of paths. Touch will look at the list of paths output by this script, and will copy them to the dropped network. A node path is specified relative to the current component when the script exits. If a node cannot be found for a string, Touch will assume that it is a file and dropped the string as a file into the drop network.
The arguments for the Destination Drop Script are:
- $arg0 - full path of script
- $arg1 - name of copy of component (or alternative operator specified in parameter Dropped Component)
- $arg2 - full path of temporary network (in /sys)
- $arg3 - name of component (or alternative operator specified in parameter Dropped Component)
- $arg4 - full path of component parent (where the drag came from) (or alternative operator parent)
- $arg5 - operator type of copy
A simple example:
# change to dropped component path cc $arg1 # return dropped component echo .
Drop Types
By default, dragging a component drops operators or file paths. If a drop destination script is specified, you can also add a DAT table with a list of return types that the drop destination script will provide. Return types can be one of the op types (COMP,TOP,CHOP,SOP,MAT,DAT), channel, or supported filetypes. For example, a DAT table containing just
jpg tiff top
will only let the component being dropped into know that it will only provide those 3 types. If the component being dropped into has a table of types and corresponding scripts, then you will only be able to drop if there is a matching type. i.e., if the drop script table looks like this:
top top_script
then only tops supplied by the drop destination script will be accepted by the component.
Using echo in scripts
Care should be taken when using echo in drag or drop scripts. These scripts all return a value, using echo will return a value from the script as well and may lead to unexpected results.
For example:
echo nodepath
echo $pargs
These examples will lead to a node being returned from the script. If dropping using a drop destination script, this will result in the node being copied to the drop destination.
Examples
A video example on how a drop script is used can be found on the forum page here. Another example can also be found here.
