Alican Posted November 2, 2019 Report Share Posted November 2, 2019 Hello all! I am trying to create multiple forms that open up consecutively and parse the values from one form and use it in the next one. Here is the Ftrack Hiearchy structure EpisodicS2└-- Episode1 └-- Sequence 1 <--- ( A ), ( B ) └-- Shot 1 └-- Task 1 <--- ( B ) └-- Task 2 <--- ( B ) └-- Task..10 I have created 2 forms. Form A and Form B. If I run the action on an Sequence type item it should open a Dialog Form A, and once that is submitted it should gather the values from Form A and popup another dialog, Form B. If I run the action on some selected tasks, instead of a Sequence, I would like it to skip Form A, and just open up Form B. If I run this action on Sequence, data['values'] does not show me the values from Form B, it just tries to grab the information from Form A. How can I update data['values'] so that it gets the values from Form B? This only works correctly if I run it on a task or selected tasks. But it does not work when I run it on a Sequence. In the example below, I have a line that prints data['values']. Inside the main_ui(). So I guess the question is how do I clear the data values from the first Dialog box? class LuxCIS(object): '''Custom action.''' label = 'Create CIS' identifier = 'create.cis' description = 'Creates a sequence CIS from selected items' icon = 'https://static.thenounproject.com/png/2160687-200.png' def __init__(self, session): '''Initialise action.''' super(LuxCIS, self).__init__() self.session = session self.logger = logging.getLogger( __name__ + '.' + self.__class__.__name__ ) self.template_files = [] def register(self): try: ftrack.EVENT_HUB.subscribe( 'topic=ftrack.action.discover and source.user.username={0}'.format( getpass.getuser() ), self.discover ) ftrack.EVENT_HUB.subscribe( 'topic=ftrack.action.launch and source.user.username={0} ' 'and data.actionIdentifier={1}'.format( getpass.getuser(), self.identifier ), self.launch ) except: self.session.event_hub.subscribe( 'topic=ftrack.action.discover', self.discover ) self.session.event_hub.subscribe( 'topic=ftrack.action.launch and data.actionIdentifier={0}'.format( self.identifier), self.launch ) 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. selection = data.get('selection', []) self.logger.info('Got selection: {0}'.format(selection)) #if len(selection) != 1 or selection[0]['entityType'] != 'assetversion': # return return { 'items': [{ 'label': self.label, 'description': self.description, 'actionIdentifier': self.identifier, 'icon': self.icon }] } def main_ui(self,event,items): #for i in self.items: print i, i['name'] #Get global ftrack settings for project and sequence from the first item #Get all information for each task and shot associated #populate a UI using the gathered information #master_dict = self.get_items(items) data = event['data'] ui = [{ 'value': '<hr>', 'type': 'label' },{ 'value': '<i><b>Hey poulate me! i found tasks!</b></i>', 'type': 'label' },{ 'label': 'My Enumerator', 'type': 'enumerator', 'name': 'my_enumerator', 'data': [ { 'label': 'Option 1', 'value': 'opt1' }, { 'label': 'Option 2', 'value': 'opt2' } ] },{ 'value': '<hr>', 'type': 'label' }] if 'values' in event['data']: # do something with values print data['values'] # This should now display the values from the second UI form. return { 'success':True, 'message':"Mission didn't fail unsuccesfully!"} return {'items':ui} def launch(self, event): '''Callback method for custom action.''' self.template_files = [] items=[] data = event['data'] selection = data.get('selection', []) session = ftrack_api.Session() template_files_dir = "L:/HAL/LUX_SLATE/nuke_templates" if os.path.isdir(template_files_dir): self.template_files = [i for i in os.listdir(template_files_dir) if i[-3:] == '.nk'] #gather shot items from selection for entity in selection: item = session.query('select id from TypedContext where id is {0}'.format(entity['entityId'])).first() items.append(item) #if just 1 item is selected if len(items) == 1: #If the single selected item is a sequence, get all the tasks under the sequence if items[0]['object_type']['name'] == 'Sequence': get_task_types = session.query('select name from Task where ancestors any(id="{0}")'.format(entity['entityId'])).all() task_types = [] for t in get_task_types: temp_t = {'label':t['name'], 'value':t['name']} if temp_t not in task_types: task_types.append(temp_t) cis_sequence_settings = [{ 'value': '<hr>', 'type': 'label' },{ 'value': '<i><b>What type of tasks should I create the CIS from?</b></i>', 'type': 'label' },{ 'label': 'Task Type', 'type': 'enumerator', 'value': task_types[0]['label'], 'name': 'cis_task_types', 'data': task_types },{ 'value': '<hr>', 'type': 'label' }] if 'values' in data: values = data['values'] task_type = values['cis_task_types'] items = session.query('select id from Task where name is "{1}" and ancestors any(id="{0}")'.format( entity['entityId'], task_type )).all() return self.main_ui(event, items) return {'items':cis_sequence_settings} #if the item is not a sequence, could be shot, task, etc.... or even project else: return self.main_ui(event, items) #if more than one item is selected else: return self.main_ui(event, items) def register(session, **kw): '''Register plugin.''' # Validate that session is an instance of ftrack_api.Session. If not, # assume that register is being called from an incompatible API # and return without doing anything. if not isinstance(session, ftrack_api.Session): # Exit to avoid registering this plugin again. return action = LuxCIS(session) action.register() if __name__ == '__main__': logging.basicConfig(level=logging.INFO) session = ftrack_api.Session() register(session) # Wait for events. session.event_hub.wait() Sorry for the convuluded question, let me know if there is anything I can clarify. Thank you very much in advance. Ali Link to comment Share on other sites More sharing options...
Jakub Trllo Posted November 2, 2019 Report Share Posted November 2, 2019 Hi, I think one pssibility is to use "hidden" item in interface items (http://ftrack.rtd.ftrack.com/en/stable/developing/actions.html#hidden), where you can store if you are in widget A or widget B so you can regonize from "values" of event which values are you procesing at the moment. Another possibility is to register multiple callbaks. Callback A will always trigger callback B but if item is Sequence then will trigger mid-widget. Example c ode in attachment (not tested nor runned!). Jakub example.py Link to comment Share on other sites More sharing options...
Alican Posted November 4, 2019 Author Report Share Posted November 4, 2019 Thank you for your reply Jakub. My problem was much simpler than I thought. I can have unlimited forms as I want, and its results always just updates the event['data']['values'] with the latest form. So once form a is done I just store the event['data']['values'] into a temp var. and then call it once i need to use it to populate the next form. Thanks! 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