Why I can't write to named Constant CHOP channels?

Hello all,
I have a Constant CHOP with 2 named channels (myChan1, myChan2).

I can read by code from this Constant with this simple code

print(op('Constant1')['myChan1'])

but why I can’t write to it in the in the same way, e.g.

op('Constant1')['myChan1'] = 0

because I get this error: "td.tdError: Can only assign parameter objects. Value:None Type:<class 'NoneType'>"
?

Many thanks for your help!

Hi,

I am no expert in that matter but i think this is a limitation related to TD internal logic and the way it generates things. There may be a way to achieve it this way but only using a script CHOP (see Vals member in the channel class).

In any other cases you will need to use the parameter way
op(‘Constant1’)[‘myChan1’].par.const0value = 0

1 Like

I don’t understand the logic behind this behaviour, but I see. Many thanks!

I see the benefit of calling the name of a channel as a setter. Anyway i could be wrong. The best answer will undoubtedly come from a TD team member.

Maybe because in the underlying function they didn’t create a setter but just a getter?..

Yes probably, but if this is the case there must be an underlying good reason for that.

FYI, the reason for this is that the first method is working with a “CHOP Channel” which generally can NOT be “set” with python - only “got”. Whereas the second method is not actually working with a “CHOP Channel” but instead a “Parameter” - and all parameters are generally “settable” and “gettable”.

The key thing to note is that the Constant CHOP is special in that for every “constant” that you create in the Constant CHOP, it will (behind the scenes) create a new CHOP channel that will use the evaluated value of the value parameter for that constant.

Unfortunately you can’t easily reference then by their name parameters in this way for numerous reasons - like the name you enter could be changed if it is a duplicate. Also the name parameter supports pattern expansion to create many channels from one constant.

If you want to create “constant” channels that you can reference via names instead of having to remember which const#value goes with which name, I beleive the recommended method is to use Custom Parameters, and you could actually just make a Base COMP that has all your named custom parameters (accessible by op('BaseCOMP_Constant').par.Mycustomname = 0 for example) and inside, a Parameter CHOP that will by default create CHOP Channels for every custom parameter of the enclosing COMP.

If you internally connect that Parameter CHOP to an Out CHOP, and then you will have your own highly customizable “Constant CHOP” including the ability to set default values and custom ranges for the sliders instead of the default zero to one range in a Constant CHOP.