Filter Pipeline Steps in tk-multi-workfiles2

Hi it seems that tk-multi-workfiles2 is ignoring the tracking settings per project and displaying all the steps from all projects.

I saw the step_filter_on setting but doesn’t seem to have an option to filter the steps?

Thanks!

3 Likes

Hi that seems to be the same as this?
https://community.shotgridsoftware.com/t/file-open-tool-about-display-extension-of-pipeline-step-items/6417/5

Yes it is! Thanks a lot, I’m actually doing what you describe in the other post.
Just wanted to be sure if forking the app was the only way : (

1 Like

I couldn’t : (
There is no way to access the tracking settings from the API isn’t? So I cant get a list of the available steps per project?

Or maybe there is a hidden field in the step entity that I can get to find this? I try with the following without success:

sg_steps = sg.find(
“Step”,
[[‘project.Project.id’, ‘is’, 12]],
[“code”, “entity_type”, “color”],
order=[{“field_name”: “code”, “direction”: “asc”}]
)

sg_steps = sg.find(
“Step”,
[[‘project’, ‘is’, {‘type’: ‘Project’, ‘id’: 12}]],
[“code”, “entity_type”, “color”],
order=[{“field_name”: “code”, “direction”: “asc”}]
)

2 Likes

Ah yes you are quite right, sorry about that, I don’t think I thought that through enough. It’s not actually possible right now via the API to get those visibility rules.
I can think of a workaround, and that would be to summariae the tasks on the project, and group by the step:

r = sg.summarize(entity_type='Task',
                 filters=[['project', 'is', {'type': 'Project', 'id': 89}]],
                 summary_fields=[{'field': 'id', 'type': 'count'}],
                 grouping=[{'field': 'step', 'type': 'exact', 'direction': 'asc'}])

steps = [g["group_value"] for g in r['groups']]

# now get the required fields:
step_id_filters = [["id", "is", s["id"]] for s in steps if s is not None]
filters = [{"filter_operator": "any", "filters": step_id_filters}]
sg_steps = sg.find("Step",
                   filters,
                   ["code", "entity_type", "color"],
                   order=[{"field_name": "code", "direction": "asc"}])

That might not be very performant if you have a lot of task though.

2 Likes

Actually that can be simplified a bit to remove an unnecessary extra list comprehension:

r = sg.summarize(entity_type='Task',
                 filters=[['project', 'is', {'type': 'Project', 'id': 89}]],
                 summary_fields=[{'field': 'id', 'type': 'count'}],
                 grouping=[{'field': 'step', 'type': 'exact', 'direction': 'asc'}])

# the summarize output looks like this:
# {'groups': [{'group_name': 'Design',
#              'group_value': {'id': 129,
#                              'name': 'Design',
#                              'type': 'Step',
#                              'valid': 'valid'},
#              'summaries': {'id': 3}},
#             {'group_name': 'Online',
#              'group_value': {'id': 2,
#                              'name': 'Online',
#                              'type': 'Step',
#                              'valid': 'valid'},
#              'summaries': {'id': 7}},
#              ...]


# Loop over the steps returned in the summarize and build a filter from them so we can query
# Shotgun for the additional required step fields.

step_id_filters = [["id", "is", g["group_value"]["id"]] for g in r['groups'] if g["group_value"] is not None]
filters = [{"filter_operator": "any", "filters": step_id_filters}]
sg_steps = sg.find("Step",
                   filters,
                   ["code", "entity_type", "color"],
                   order=[{"field_name": "code", "direction": "asc"}])
1 Like

Hi thanks a lot! this works perfectly!
I have some doubts; does summarizing all the tasks of the project is resource consuming? I guess it gets cached the first time and I don’t have to worry after?

1 Like

Yeah as I mentioned, it may not be very performant if you have a lot of tasks. Though the list does get cached for the rest of the session. It stores it to the class as a static var.

2 Likes

OK thanks for the info! I’ll leave it for a while like this to check performance.
Otherwise I might add my custom field somewhere in shotgun and pick it up from there.

Thanks again!

2 Likes