Rory Posted July 2, 2020 Report Share Posted July 2, 2020 Hi All, I am writing an action to create folder structures on disk based on some Ftrack details. I am trying to attach the action to a Shot. Below is a snippet of the 'discover' method. Why would the entity have to return true for 'task' to get Shot ? This works for Sequence and Shot but I am confused as to why the entityType to test is task and not shot ? def discover(self, event): '''Return action config if triggered on a single asset version.''' data = event['data'] '''If selection contains more than one item return early since this action can only handle a single version.''' # self.logger.info(event[]) selection = data.get('selection', []) self.logger.info('Got selection: {0}'.format(selection)) for item in selection: if item.get('entityType') == 'task': return { 'items': [{ 'label': self.label, 'description': self.description, 'actionIdentifier': self.identifier }] } Link to comment Share on other sites More sharing options...
Lorenzo Angeli Posted July 3, 2020 Report Share Posted July 3, 2020 Hi @Rory, if you want to write new actions I'd suggest having a look at our action handler. Regarding your question is because many of the Context entities comes from a common Task base entity (server side), if you want to properly identify have a look at the _get_entity_type method of the action handler. Hope it helps. L. Link to comment Share on other sites More sharing options...
Rory Posted July 3, 2020 Author Report Share Posted July 3, 2020 Thanks so much Lorenzo - Will take a look asap. Link to comment Share on other sites More sharing options...
Rory Posted July 7, 2020 Author Report Share Posted July 7, 2020 entity_type, entity_id = entities[0] entity = session.get('TypedContext', entity_id) entitytype = self._get_entity_type(entity) Hi Lorenzo, I get NoneType returned to entitytype here ? What am I missing ? Thanks Link to comment Share on other sites More sharing options...
Lorenzo Angeli Posted July 7, 2020 Report Share Posted July 7, 2020 Hi @Rory, if you look a the action handler, the entity needed to be passed in is the original one coming from the event, there's no need to try to build the entity from the session. hope it helps. L. Link to comment Share on other sites More sharing options...
Rory Posted July 7, 2020 Author Report Share Posted July 7, 2020 def discover(self, session, entities, event): '''Return True if we can handle the discovery.''' # TODO: Modify to fit your needs. # Example, only allow a single asset version as selection. if len(entities) != 1: return #entity_type, entity_id = entities[0] entityt = self._get_entity_type(entities[0]) if entityt != 'Shot': return return True So from the Handler example - this seems correct ?- using the incoming entities ? But that still doesn't work ? Link to comment Share on other sites More sharing options...
Lorenzo Angeli Posted July 8, 2020 Report Share Posted July 8, 2020 hi @Rory here a simple example to translate the entities using the action handler as base class: from ftrack_action_handler.action import BaseAction import ftrack_api class TestAction(BaseAction): label = 'Test Action' identifier = 'com.ftrack.test.action' description = 'Simple test action' def validate_selection(self, entities, event): if not entities: return False results = self._translate_event( self.session, event ) if not results : return False for (entity_type, entity_id) in results[0]: resolved_entity= self.session.get(entity_type, entity_id) print resolved_entity, resolved_entity.entity_type return True def discover(self, session, entities, event): return self.validate_selection(entities, event) def launch(self, session, entities, event): return { 'success': True, 'message': u'Done.' } def register(api_object, **kw): '''Register hook with provided *api_object*.''' if not isinstance(api_object, ftrack_api.session.Session): return action = TestAction(api_object) action.register() hope it helps. L. Link to comment Share on other sites More sharing options...
Rory Posted July 21, 2020 Author Report Share Posted July 21, 2020 Thanks so much - great help Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now