How to reference a par by its name

Looked through this documentation page and didn’t see it, figured I’d ask here in case I’m missing it.

How can I reference a parameter by the name I’ve given it (via script), instead of name0?

I know I can do op('constant1').par.name0 to get its name. But I have a constant CHOP with numerous entries in it, so it’d make my script, which is trying to set values for those constant CHOP entries, a lot more legible if I could do what I intuitively thought might be something like op('constant1').par('myNamedParam').value0.

Is there a way to do this or must I stick with the generic name0, value0?

A par describes a single parameter, the par collection shows you how to access it.

@ben shouldn’t there be a link from the par class page to the ParCollection class page ? most people start looking on the par page when they look for that info

1 Like

Thanks @alphamoonbase , so if I wanted to assign a value to the param how would that work?

op('constant1').par['myNamedParam'] ← Evaluated by python as ‘NoneType’, cannot assign int, string etc to it

The following guesses don’t seem to be it:

op('constant1').par['myNamedParam'].value0
op('constant1').par['myNamedParam'].val
op('constant1').par['myNamedParam'].default

Parameter names are all lower case except for custom parameters which start with a capitalized letter

Without being in front of TD I believe in case of a constant CHOP it would be
op(‘constant1’).par[‘value0’] = 123

Thanks @Achim, that does work, but the issue doesn’t seem to have been addressed then, as it’s still using the generic value0 to reference the parameter rather than the name I’d given it (in this case, myNamedParam; see screenshot below for clarification):
Screenshot_85

… In the meantime I guess I’ll work on getting the intellisense-like support up and running soon, which would probably help a ton with minor syntax questions like this in the future.

That’s how the constant CHOP works.

You could alternatively create a base COMP with custom Parameters and use a parameter CHOP to get those into CHOPs

Then you can use
op(„base1“).par.Mycustomparname = 123
or
op(„base1“).par[„Mycustomparname“] = 123

To set values

I think we’re getting bogged down in the peculiarity of the Constant CHOP whose purpose is to put the name in one parameter name0… and the value in another parameter, value0, which then creates a CHOP channel with the name in name0, and the value in value0.

This is entirely different from custom parameters, where you are creating one parameter with a name and a value, and no channels.

So, as Achim says, instead of using the Constant CHOP (I use it less and less over time), you can create a Base COMP and add custom parameters to it. Then you can use it the way you describe. If you want the parameters to generate a CHOP with channels, you can use the Parameter CHOP.

Achim, I added clarification here: Par Class - Derivative

( Pro Tip: I use this form of parameters inside components for even simpler access: Internal Parameters - Derivative )

2 Likes