Go to: Synopsis. Return value. Flags. Python examples.

Synopsis

connectControl( string attribute... , [fileName=boolean], [index=uint], [preventOverride=boolean])

Note: Strings representing object names and arguments must be separated by commas. This is not depicted in the synopsis.

connectControl is undoable, NOT queryable, and NOT editable.

This command attaches a UI widget, specified as the first argument, to one or more dependency node attributes. The attributes/nodes don't have to exist yet, they will get looked up as needed. With no flag specified, this command works on these kinds of controls: floatField, floatScrollBar, floatSlider, intField, intScrollBar, intSlider, floatFieldGrp, intFieldGrp, checkBox, radioCollection, and optionMenu. With the index flag, It will also work on the individual components of all other groups.

This command sets up a two-way connection between the control and the (first-specified) attribute. If this first attribute is changed in any way, the control will be appropriately updated to match its value.

Summary: if you change the control, ALL the connected attributes change. If you change the FIRST attribute attached to the control, then the control will change.

NOTE: the two-way connection will not be established if the attributes do not exist when the connectControl command is run. If the user later uses the control, the connection will be established at that time.

To effectively use connectControl with radioCollections and optionMenus, you must attach a piece of data to each radioButton and menuItem. This piece of data (an integer) can be attached using the data flag in the radioButton and menuItem commands. When the button/item is selected, the attribute will be set to the value of its data. When the attribute is changed, the collection (or optionMenu) will switch to the item that matches the new attribute value. If no item matches, it will be left unchanged.

There are some specialized controls that have connection capability (and more) built right into them. See attrFieldSliderGrp, attrFieldGrp, and attrColorSliderGrp. Using these classes can be easier than using connectControl.

Return value

None

Flags

fileName, index, preventOverride
Long name (short name) Argument types Properties
index(index) uint create
This flag enables you to pick out a sub-control from a group that contains a number of different controls. For example, you can connect one field of a floatFieldGrp. You must count each member of the group, including any text labels that may exist. For example, if you have a check box group with a label, the label will count as index 1, and the first check box as index 2. (Indices are 1-based)
fileName(fi) boolean create
This flag causes the connection to be treated as a filename, and the conversion from internal to external filename representation is made as the data is copied. This only applies to connections to Tfield controls.
preventOverride(po) boolean create
If true, this flag disallows overriding the control's attribute via the control's right mouse button menu.

Flag can appear in Create mode of command Flag can appear in Edit mode of command
Flag can appear in Query mode of command Flag can have multiple arguments, passed either as a tuple or a list.

Python examples

import maya.cmds as cmds

sphereNames = cmds.sphere()
sphereName = sphereNames[0]
window = cmds.window()
cmds.columnLayout()
cmds.text( l='X Value:' )
cmds.floatField( 'xx' )
cmds.connectControl( 'xx', '%s.tx' % sphereName )
cmds.text( l='Visibility' )
cmds.checkBox( 'vis' )
cmds.connectControl( 'vis', '%s.visibility' % sphereName )
cmds.floatFieldGrp( 'rot', l='Rotation:', numberOfFields=3 )
# index 1 would be the text label
cmds.connectControl( 'rot', '%s.rx' % sphereName, index=2 )
cmds.connectControl( 'rot', '%s.ry' % sphereName, index=3 )
cmds.connectControl( 'rot', '%s.rz' % sphereName, index=4 )
cmds.showWindow( window )

# Connecting two attributes to a single control
#
cmds.window()
cmds.columnLayout()
cmds.floatSlider( 'slider' )
cmds.showWindow()

cmds.polySphere()
cmds.polyCube()
cmds.move( 0, 2, 0 )
cmds.connectControl( 'slider', 'pCube1.tx', 'pSphere1.tx' )