Jason Evanko Posted September 6, 2022 Report Share Posted September 6, 2022 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 More sharing options...
Mattias Seebergs Posted September 7, 2022 Report Share Posted September 7, 2022 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 More sharing options...
Jason Evanko Posted October 11, 2022 Author Report Share Posted October 11, 2022 @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 More sharing options...
Mattias Seebergs Posted October 13, 2022 Report Share Posted October 13, 2022 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. Link to comment Share on other sites More sharing options...
Jason Evanko Posted October 13, 2022 Author Report Share Posted October 13, 2022 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 More sharing options...
Mattias Seebergs Posted October 21, 2022 Report Share Posted October 21, 2022 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 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