Using Python variables when accessing OP parameters

Hi there,

I’m currently trying to implement a parameter bind workflow within my GUI by using the external Drag/Drop Callback function implemented in Container COMPs. I certainly managed the drag kind of part but I’m a little stuck with the drop functionality.

That’s the current code within the ‘onDropGetResults(comp, info)’ area:

nameDrop = comp.parent().name
module = comp.parent(3)

if any(par.name == str(nameDrop[:-1] + '1') for par in module.customPars):
	locationDrop = [module.par.str(nameDrop + '1'), module.par.str(nameDrop + '2')]
else:
	locationDrop = [module.par.nameDrop]

print(locationDrop)

locationDrop = info['dragItems']
#debug('\nonDropGetResults comp:', comp.path, '- info:\n', info)
return {'droppedOn': comp}

With this I’m getting an error when declaring ‘locationDrop’ within the if statement as the object ‘module’ (which is a Base COMP with a bunch of custom parameters) has no attribute/parameter ‘nameDrop’. When I print(nameDrop) though I’m getting back the correct parameter name as shown in the Textport.

Is it possible to use variables after op(‘x’).par. at all?

I’m really new to Python so please forgive me any dumb questions… Any help would be greatly appreciated!

Greetings

Hey, no, it wouldn’t work like that. You need to use function called setattr it will look something like this: setattr(module.par, str(nameDrop+‘2’), value)

If I understood this correctly, than you might want to access parameter using dictionary:

op('base').par['MyFloat'] = 3.5

When searching for key based on combination of some variables and strings, you can use f-strings to easily get parameter name you are after.

module.par[f'{nameDrop} 1']

Is this what you are looking for?

Sorry for the late reply, I didn’t find the time to come back to this sooner.

This here did the trick for me: module.par[nameDrop]

Thanks for all the hints!