Jump to content

Action on Shot


Rory

Recommended Posts

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

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

    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

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

  • 2 weeks later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...