Multiple extensions howto reference each other?

I want my COMP to have multiple extensions which can communicate with each other.
Let’s say I set up my extensions as such:

global op shortcut TEST
object1 op('./FooEXT').module.FooEXT(me)
name1 FOO
object2 op('./BarEXT').module.BarEXT(me)
name2 BAR

Let;s say inside each class I have a method called Test which prints out “foo” and “bar” respectively.

Now, if I open up textport:

op.TEST.ext.FOO.Test()
>>> Foo
op.TEST.ext.BAR.Test()
>>> Bar

But if I reference these extensions inside each other:

class FooEXT:
    def __init__(self, ownerComp):
		# The component to which this extension is attached
		self.ownerComp = ownerComp
        self.Bar = self.ownerComp.Ext.BAR

I get td.Error: Cannot use an extension during its initialization.

So how do I create such a cross reference? Is it considered a bad practice to do so?

You are on the right pass, but because you are refferencing the extension during the init-step you can not be 100% sure that the extensionobject actually exists or not, so it is forbidden. What you can do is to create a simple property lile this

@property
def Bar(self):
	return self.ownerComp.Ext.BAR

which then can just be used like a static property in your extensions via self.Bar

1 Like