Getting an operator by relative path in python

Whats a good way to get an operator in relation to another one by a relative path? Meaning ‘…’ translates to parent, ‘myop’ to the op myop on the same level etc? I cannot use the op(‘myop’).op(relativePath) as this will work for a … path, but not for an absolute path looking at the same level.
Right now I’m using a dummy OP parameter, set it to the relative path and use the eval() function to get the propper component, but this seems abit arround the block.

1 Like

Let me know if this is accurate understanding or not - you want to find the op ref to an operator, that is a sibling of another operator in a certain parent level?

If I’m following correctly - what I do is this usually:


Hmm, not quite.
When I use op.relativePath to get a relative path from one operator to another, it will be returned in the same manner as in an op-refference operator.
When I am now in an extension, it is not always possible to get the operator in relation to the original operator.
Lets imagine I have the path … (pointing at a parent) and constant1 (pointing to an op on the same level).
In my python script I cannot use the op(‘originOp’).op( relativePath ) as, for constant1, this will look inside my originOp. I could use op(‘originOp’).parent().op(relativePath), which works for that case, but I can no longer feed it the … relative path to the parent as this will be the same as parent(2).

I can get arround that using a parameter as the middle ground as here the relative paths work without problems, but I’m wondering if there is another way arround that.

Also, the paths are user generated and the relation can be whatever the user wants it to be, so hardcoding is not an option :slight_smile:

1 Like

I’m interested in a better system for this as well. Would you mind putting together a small example network showing the sticky points for you and maybe a simple version of what you’re trying to let users do?

1 Like

In the past I’ve had success with this sort of thing using “internal operators” parameters

So let’s say you specify your root COMP/tox to be ‘Root’, you can access it from any descendent op as iop.Root.op(‘relative/path/to/…’). Alternatively check out the “parent shortcut” param

This isn’t perfect since it relies on op hierarchy to work; worst case scenario you could maybe expose a global variable at runtime using python extensions?

Hoi Benjamin, thanks for the suggestions.
Sadly both will not work in this case as usin iop.Root.op(‘relative_path’) has the same problem as using directly op(‘my_op’).op(‘relative_path’) as it will resolve inside of my_op. The parent shortcut is also not usable in this situation as I need a way to convert from op(‘my_op’).relativePath( op(‘relative_op’) ) back to the relative op.