How to add multiple tasks under one item when publishing

Hey all,

I’m working on a publishing plugin for shotgun toolkit and could use some help to figure out a way to make things a little easier for animators to figure out what they’re publishing. For each character in our scene, we may have 1-4 different alembic files that need to be generated - skin, cloth, hair, etc. Currently when I use the toolkit to create items, they each get created as a single item. What I’d like to do is create subtasks under each character for each item that needs to be exported.

Notice in the image on the left, dev_corban:model and dev_corban:model_cloth are both alembic files that need to be published for the character. I can’t quite figure out how to get what I really want which is image on the right… where each alembic file is a task of item corban.

This is a snippet of code that creates the items on the left:

for model in models_to_export:

  # make a nice name
  name = model.split(':')[-1]

  # create the item
  item = parent_item.create_item(
    "maya.session.character",
    "Character",
    (char_name + ':' + name )
  )

I tried the following, but I’m sure I’m missing something:

# create character item
item = parent_item.create_item(
   "maya.session.character",
    "Character",
    char_name
  )

# now define each of the exported models
for model in models_to_export:
  # make a nice name
  name = model.split(':')[-1]

  # create the export item
  export_item = item.create_item(
    "file.alembic",
    "Alembic Export",
    name
  )

But it doesn’t do anything other than create the top parent_item… I’m sure I’m missing something simple, but any help would be greatly appreciated.

Thanks!
-Jason

1 Like

What you’ve described modifying is the collector, which creates the Character node. The leaves of this tree in the ui are publish plugins, which take all collected items and decide whether they can do something with it. They are located in separate hooks.

For each export you will have an additional publish plugin.

You should read up here: https://developer.shotgunsoftware.com/tk-multi-publish2/index.html

You might reconsider your desired organization to resemble the left picture more, because each character part will probably be a separate collected item (e.g. from specially prepared scene objects), and not a separate publish plugin.
Under each collected you will have “export alembic, publish to shotgun”.
This is just closer to how the publish api works, of course all sorts of variations are possible.

3 Likes

Oops! Yes, you are right - I’m modifying the collector to identify the items that will need to be published.

I could leave it as it is with the image on the left - but I worry that the number of items being published will be quite long - with up to 4 items per character, and who knows how many props… that list could be huge.

1 Like

Hi @Shhlife,

A visual way to think about what @mmoshev said is that if something has the expand icon (triangle) on it, it is an item. If it’s under an item and doesn’t have an expand icon it, it is a plugin.

Inside the collector you define what items you want to see. Then each plugin decides whether it should show up under that item or not. On the right hand side of your image you have one item and multiple plugins per character.

You should be able to get the publisher to look the way you want as long as you have a finite number of possibilities for your tasks. If you only have the 4 options (model, skin, cloth, hair), then you can:

  1. Update the collector to create a single item per character. There will be no child items.
  2. Create 4 separate publish plugins that are responsible for their respective sub asset.
  - name: "Alembic Export: Model"
    hook: "{self}/publish_file.py:{config}/tk-multi-publish2/basic/maya_export_model.py"
    settings: {}
  - name: "Alembic Export: Cloth"
    hook: "{self}/publish_file.py:{config}/tk-multi-publish2/basic/maya_export_cloth.py"
    settings: {}
    ...
  1. Update the accept method of the plugins to check the character in the scene and only accept the item if the corresponding sub asset exists
#maya_export_cloth.py
def accept(self, settings, item):
    return {
        "accepted": self._cloth_exists(char_name),
        "checked": True
    }

If you decide to keep things as they are on the left image, you can try making the UI a little easier to look at when there are lots of items by setting item.expanded = False in the collector. This is especially useful when you only have one publish plugin registered per item.

By the way, without seeing your setup it’s hard to tell what the issue is with your attempt to create a hierarchy but my guess is that you don’t have any publish plugins that accept an item of type file.alembic. If that is the case, there will be no tasks created under that item and the publisher UI hides any items that do not have any children. So your collector is probably fine. You just need to set up your publish plugins correctly before you can see the child items. Fixing this setup and adding in the item.expand = False is probably the best solution.

2 Likes

Ahhhhh that helps me grok the process much more - I was assuming that I needed one plugin per item - but I can have
Multiple publish plugins per item. That makes it totally clear, thank you!

1 Like

Thanks for providing more clarity to my answer.

I’d still go with the “regular” approach of having an item per asset, with multiple plugins under it - e.g. publish to shotgun, export, submit to farm.
The reason is better modularity and separation of concern. Also more in sync with how the publish system works.
You could achieve a limited amount of interaction between publish plugins by setting stuff in the item properties - publish paths, etc.

For more complex behaviour you’d have to create new plugins, though. It all depends on your needs.

1 Like