Jump to content

Print out selected task name


Jason Evanko

Recommended Posts

Hey all! I'm trying to write a quick little action that would print out the selected task name at the top of the page when launched and I'm having some trouble getting that variable and was wondering how I would get that specific one? I'm able to loop through all active projects and get that variable with self.sessions and a for loop with projects but I can't seem to isolate just the active project or any of the tasks inside that project. 

 

 

Thanks so much!

 

Link to comment
Share on other sites

Hi Jason!

What you are looking for is the `selection` variable, I had a little snippet doing something similar that I've modified slightly for you below. It's not complete but it does at least show the concept. Hope this helps!

 

    def launch(self, session, entities, event):
        selection = event['data']['selection']

        if len(selection) == 1:
            entity = selection[0]
            task = None
            
            try:
                task = session.query(
                    f'Task where id is \"{entity["entityId"]}\"'
                ).one()
            except Exception as e:
                return {
                    'success': False,
                    'message': 'An error occurred.'
                }
                
            if task:
                return {
                    'success': True,
                    'message': f'Task name: {task["name"]}'
                }

        return False

 

Link to comment
Share on other sites

  • 1 month later...

@Mattias Seebergsonce I removed the session and entities arguments that worked perfectly! Thanks so much for the quick answer there! I do have a follow up though, I'm essentially trying to make a little tool that will loop through every shot that has a task on it to create a folder. I tried changing that 'Task where id is' is section to 'Shot...' and adding a shot = None variable however that doesn't quite seem to work. do I need to set the selection to the show before getting the context of the shots since right now its going all the way down to the task level? Or should it be able to back track to the shot level with the task selected? 

 

Thanks again!

Link to comment
Share on other sites

9 hours ago, Mattias Seebergs said:

Not sure I follow with the 'shots = None' variable, shots do have a `children` property if that helps? If you could share a minimal example and explain a bit more what you are aiming to do, then I'd be happy to help further.

for sure! Heres a snippet of the "launch" function but I might break it up into multiple functions so its cleaner. 

 

 

         def launch(self, event):
       
        selection = event['data']['selection']
        path = 'C:\\project\\test\\'
        if len(selection) == 1:
            entity = selection[0]
            task = None
            shot = None
            projects = None
            try:
                projects = self.session.query(
                    f'Project where id is \"{entity["entityId"]}\"'
                ).one()
                task = self.session.query(
                    f'Task where id is \"{entity["entityId"]}\"'
                ).one()
                

                 os.makedirs(path + projects['name'] + shot['name'])
            except Exception as e:
                return {
                    'success': False,
                    'message': 'An error occurred.'
                }
                
            if task:
                return {
                    'success': True,
                    'message': f'Shot name: {shot["name"]}'
                }
        return False

 

 

 

essentially what I'm trying to have it do here is once I select a shot that has a task in it it will create a folder with the name of that shot and task inside of it. Eventually I want to be able to select the project as a whole and have it create a folder for each shot that has a task assigned to it but one step at a time haha

Link to comment
Share on other sites

Sorry for the delay on this, Jason. I didn't fully understand the queries there so I thought I'd help you with a query that simply returns all shots that have at least one task on it:

shots = session.query(
    'Shot where children any (object_type.name is "Task") '
    f'and project_id is "<project_id>"'
).all()

You could get the ID of the project from the selection in the previous example. Next step from here would be to just iterate over those shots and do the disk operations.

Hope this helps!

Link to comment
Share on other sites

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...