Help with python and constant chops

Hi all

I have a constant chop with 40 values , i can read thoses values buy different ways
as an example for channel 0 :

op(“constant”).par.value0
or
op(“constant”)[0]
or
op(“constant”)[0][0]

but for writting, only

op(“constant”).par.value0 = 5 works fine

As i have a function with index and many channels it would help a lot if i could write :

op(“constant”)[index][0] = myValue.

Othewise i have about 40 times to write
if index == 0 :
op(“constant”).par.value0 = value
if index == 1 :
op(“constant”).par.value1 = value
if index == 2 :
op(“constant”).par.value2 = value

thanks all

You can use setattr to do the job. You basically make a variable for the operator name, the parameter you want to change, and the value you want to set it to.

[code]opName = ‘constant1’
parmName = ‘value0’
value = 0.6

setattr(op(opName).par, parmName, value)[/code]

Then you’d just have to iterate through or assign the parmNames and values as you need.

1 Like