[Maya / Python ] Linking an intField and intSlider together for simultaneous updating

What is the best way to connect a intSlider to an intField and the other way around. So That if I change the slider the number in the intField changes or when I change the intField value the slider moves to the correct position.

This is what I’ve got so far:


def updateSpacingSlider(item):
    ...

def updateSpacingField(spacingField):
    spacingField.setValue(pm.intSlider('spacingS', query=True, value=True))

with pm.rowColumnLayout(numberOfColumns=3, columnWidth=[1,90]):
    spacingField = pm.intField('spacingF', width=80, minValue=1, maxValue=20, value=gridSpacing, changeCommand=updateSpacingSlider)
    spacingSlider = pm.intSlider('spacingS', minValue=1, maxValue=20, value=gridSpacing, changeCommand=updateSpacingField, spacingField))

Not sure what to put in the updateSpacingSlider since the slider is not defined yet :frowning:

Cheers,
Olivier

dont use a separate intslider and field but instead use the intSliderGrp, which is a combination of a label, a field and a intslider in one, with the field and int slider already synced to each other.

also why wouldnt the slider be defined by the time that command runs?

also if you still wanted to take your approach why query the value from the UI elements, i can only assume the controls are meant to change some variable or node attribute so why not query what the UI controls effect instead