pymel.core.windows.connectControl

static windows.connectControl(*args, **kwargs)

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 indexflag, It will also work on the individual components of all other groups. This command sets up a two-way connectionbetween 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 connectControlcommand is run. If the user later uses the control, the connection will be established at that time. To effectively use connectControlwith 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 dataflag in the radioButtonand menuItemcommands. 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.

Flags:
Long name (short name) Argument Types Properties
fileName (fi) bool ../../../_images/create.gif
 

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.

index (index) int ../../../_images/create.gif
 

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)

preventOverride (po) bool ../../../_images/create.gif
 

If true, this flag disallows overriding the control’s attribute via the control’s right mouse button menu. Flag can have multiple arguments, passed either as a tuple or a list.

Derived from mel command maya.cmds.connectControl

Example:

import pymel.core as pm

sphereNames = pm.sphere()
sphereName = sphereNames[0]
window = pm.window()
pm.columnLayout()
# Result: ui.ColumnLayout('window1|columnLayout20') #
pm.text( l='X Value:' )
# Result: ui.Text('window1|columnLayout20|text2') #
pm.floatField( 'xx' )
# Result: ui.FloatField('window1|columnLayout20|xx') #
pm.connectControl( 'xx', '%s.tx' % sphereName )
pm.text( l='Visibility' )
# Result: ui.Text('window1|columnLayout20|text3') #
pm.checkBox( 'vis' )
# Result: ui.CheckBox('window1|columnLayout20|vis') #
pm.connectControl( 'vis', '%s.visibility' % sphereName )
pm.floatFieldGrp( 'rot', l='Rotation:', numberOfFields=3 )
# Result: ui.FloatFieldGrp('window1|columnLayout20|rot') #
# index 1 would be the text label
pm.connectControl( 'rot', '%s.rx' % sphereName, index=2 )
pm.connectControl( 'rot', '%s.ry' % sphereName, index=3 )
pm.connectControl( 'rot', '%s.rz' % sphereName, index=4 )
pm.showWindow( window )

# Connecting two attributes to a single control
#
pm.window()
# Result: ui.Window('window2') #
pm.columnLayout()
# Result: ui.ColumnLayout('window2|columnLayout21') #
pm.floatSlider( 'slider' )
# Result: ui.FloatSlider('window2|columnLayout21|slider') #
pm.showWindow()

pm.polySphere()
# Result: [nt.Transform(u'pSphere1'), nt.PolySphere(u'polySphere1')] #
pm.polyCube()
# Result: [nt.Transform(u'pCube1'), nt.PolyCube(u'polyCube1')] #
pm.move( 0, 2, 0 )
pm.connectControl( 'slider', 'pCube1.tx', 'pSphere1.tx' )

Previous topic

pymel.core.windows.confirmDialog

Next topic

pymel.core.windows.control

Core

Core Modules

Other Modules

This Page