Set operator parameter using a variable in python

I got stuck the other night trying to set an operator’s parameter using stored operator and parameter names in python.

For instance:

operator = ‘constant1’
parameter = ‘value0’
op(operator).par.parameter = 1

Also tried:
op(operator.par.(parameter) = 1

What’s the correct way to do this?

A lot harder than I thought to dig this up:

viewtopic.php?f=4&t=6043&p=22816&hilit=setattr#p22816

In your case you could do something like:

parameter = ‘value0’
state = 1
operator = ‘constant1’

setattr(op(operator).par, parameter, state)

2 Likes

Awesome! Thanks!

You can also take advantage of the OP.pars(string) function which returns a list of parameters that matches the string.
derivative.ca/wiki088/index. … ss#Methods

example:

opname = ‘geo1’
parname = ‘tx’
op(opname).pars(parname)[0].val = 1

Interesting, didn’t know about that one.