Remus Avram Posted September 20, 2016 Report Share Posted September 20, 2016 Hi all, I have a simple hook added to FTRACK_CONNECT_PLUGIN_PATH: import ftrack_api class TestAction(object): identifier = "test_action" label = "Test Action" def __init__(self, session): super(TestAction, self).__init__() self.session = session def register(self): self.session.event_hub.subscribe('topic=ftrack.action.discover and source.user.username={0}'.format(self.session.api_user), self.discover) self.session.event_hub.subscribe('topic=ftrack.action.launch and source.user.username={0} and data.actionIdentifier={1}'.format(self.session.api_user, self.identifier), self.launch) def discover(self, event): items = [{'label': self.label, 'actionIdentifier': self.identifier}] return {'items': items} def launch(self, event): print "Launching the App" def register(session, **kw): if not isinstance(session, ftrack_api.Session): return session = ftrack_api.Session() action = TestAction(session) action.register() When I run ftrack_connect_package, unfortunately, this hook is not registered. If I replace the register method from the class with this: def register(self): import ftrack ftrack.EVENT_HUB.subscribe('topic=ftrack.action.discover and source.user.username={0}'.format(self.session.api_user), self.discover) ftrack.EVENT_HUB.subscribe('topic=ftrack.action.launch and source.user.username={0} and data.actionIdentifier={1}'.format(self.session.api_user, self.identifier), self.launch) the hook is registered to ftrack-connect. Is it possible to register the hook to ftrack-connect using only the ftrack_api module? Link to comment Share on other sites More sharing options...
natasha Posted September 21, 2016 Report Share Posted September 21, 2016 Try this instead def register(session, **kw): if not isinstance(session, ftrack_api.Session): return action = TestAction(session) action.register() session = ftrack_api.Session() register(session) session.event_hub.wait() Link to comment Share on other sites More sharing options...
Remus Avram Posted September 21, 2016 Author Report Share Posted September 21, 2016 Hi natasha, thanks for your answer! Unfortunately, if I use this session.event_hub.wait() it's waiting there forever. It's not starting the ftrack-connect ui anymore. Link to comment Share on other sites More sharing options...
natasha Posted September 21, 2016 Report Share Posted September 21, 2016 Sorry, I thought you were launching the action from command line. Try adding your action to FTRACK_EVENT_PLUGIN_PATH instead? This code works for me. import ftrack_api class TestAction(object): identifier = "test_action" label = "Test Action" def __init__(self, session): super(TestAction, self).__init__() self.session = session def register(self): self.session.event_hub.subscribe('topic=ftrack.action.discover and source.user.username={0}'.format(self.session.api_user), self.discover) self.session.event_hub.subscribe('topic=ftrack.action.launch and source.user.username={0} and data.actionIdentifier={1}'.format(self.session.api_user, self.identifier), self.launch) def discover(self, event): items = [{'label': self.label, 'actionIdentifier': self.identifier}] return {'items': items} def launch(self, event): print "Launching the App" return { 'success': True, 'message': 'Action launched successfully.' } def register(session, **kw): if not isinstance(session, ftrack_api.Session): return action = TestAction(session) action.register() Link to comment Share on other sites More sharing options...
Remus Avram Posted September 21, 2016 Author Report Share Posted September 21, 2016 Thanks natasha for your help! Now it works for me, too! It would be awesome if this example is added to the Ftrack Connect Action documentation. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.