expression within expression?

I want to link the value of a channel on a constant CHOP to a parameter like this

ext.Synth.Width

But i want the parameter to be linked to the parent’s name, which would look something like this:

ext.Synth. (me.parent().name)

But I don’t know how to evaluate a python expression inside of another expression. Is this possible?

Can you say a little more about what you’re up to? You can do this, but it’s pretty cumbersome to set up, and I’d bet that it’s more error prone than it’s actually worth.

The technique here would be to format a string, then use the eval() method to actually evaluate the python. For example:

eval('op("base_hello").{}'.format(me.name[5:]))

Here the actual name of the operator is eval_Width - we can strip off the eval_ with [5:] - this lets us skip into our string 5 characters to start. If we take a step back and just evaluate this expression:

'op("base_hello").{}'.format(me.name[5:])

we get:

op("base_hello").Width

Encapsulating this in an eval() call then evaluates this string to return the member set in the extension.

You can see how that all works here:
base_eval_example.tox (774 Bytes)

While technically possible, I would not use this approach in a project.

I am trying to make a “parameter grabber” component, that grabs an internal parameter so that I can perform CHOP stuff on it and export it to a parameter in my network. See the attached file for a demo of the parGrabbers and a possible solution i came up with using evaluate dats.
parGrabberExample.tox (1.97 KB)

Got it.

I guess the better question is: What problem are you trying to solve?

I don’t totally understand the benefit here yet, and it seems like a lot of work to fetch pars - are you looking for a way to make getting the pars themselves easier so you’re not writing out the expressions every time?

I just want to be sure that I understand what you’re after / trying to simplify.

I guess I’m trying to make it easier to link the value and the name of a channel moving through a string of CHOPs to an internal parameter.

If I use a constant CHOP, I have to type the expression “ext.Local.Speed” then type the name Speed, which isn’t implicit to the name of the par
Capture.PNG

This way, both the value and the name come from the name of the parameter I type in the box, plus I can add typical CHOP operations like math rerange in the custom parameters for easy access
Capture2.PNG

I think I’m a little lost here - wouldn’t the par need to exist before you could reference it by name? Maybe it’s worth making that into a menu that only displays pars that are available to choose?

viewtopic.php?f=17&t=8502&p=34088&hilit=dat+menu#p34088

Figuring out a menu driven by existing pars is exactly what my next step was, thanks!

I’ll post a video or a gif soon demonstrating my workflow and hopefully it will make more sense.

Sounds like maybe what you want is getattr, which lets you get a Python attribute via a string. So you want:

ext.Synth. (me.parent().name)

If I understand the problem, you’d do this:

getattr(ext.Synth, me.parent().name)

Search getattr Python docs for more detailed info.