Tk-multi-publish2 how to register custom metadata to published item

Hey all,

is there a way to append or register custom metadata on publish?

What i want to do is to be able to read that custom metadata from the sg_publish_data argument in the

def execute_action(self, name, params, sg_publish_data):

function of a tk-multi-load2 actions hook module.

I was thinking to append metadata in my publish hook like this:

def publish(self, settings, item):
    item.properties["publish_kwargs"] = {"my_metadata_key": "my_metadata_value"}

My publish hook definition in env\includes\settings\tk-multi-publish2.yml looks something like this:

hook: "{self}/publish_file.py:{config}/tk-multi-publish2/blender/publish_base.py:{config}/tk-multi-publish2/blender/asset_publish_geometry.py"

As I am using {self}/publish_file.py I was expecting that the custom metadata would end up in the PublishedFile Entity because of those lines in publish_file.py:

def publish(self, settings, item):

        [...]

        # catch-all for any extra kwargs that should be passed to register_publish.
        publish_kwargs = self.get_publish_kwargs(settings, item)
        
        [...]
        
        # add extra kwargs
        publish_data.update(publish_kwargs)

But it didn’t work. Does anyone know what I am doing wrong or have an idea how to achieve this?

You can pass extra data that should go into fields on the PublishedFile entity record.
You don’t seem to be doing that.

Not sure where otherwise you expect this data to be recorded ifr not for a custom field?

Hey @Ricardo_Musch :slight_smile:
Thanks for your answer.
What I wanted to do is add this metadata on my item.properties in the publish(self, settings, item) function of my publish hook already.

In order that the standard publish_file.py hook that is located in the tk-multi-publish2 package picks up this metadata and registers it.

I found the solution in the meantime:
The publish_file.py uses the regular
sgtk.util.register_publish() function. And I found out that it passes "sg_fields": publish_fields to the register function. Which as I understand from the docs is the argument to register extra fields on the published entity.

If I want my custom metdata to end up in the sg_fields argument I have to append it to my item as item.properties["publish_fields"] = {"my_metadata_key": my_metadata_value}
because of this line of the publish_file.py module.

So far so good.

But then I got this error

tank.util.errors.ShotgunPublishError: Unable to complete publishing because of the following error: API create() PublishedFile.collection_name doesn't exist:
{"field_name"=>"collection_name", "value"=>"Test-Prop"}.

That this field does not exist on on my PublishedFile Entity.

So what I needed to do first was create this custom field for PublishedFiles.
image

I wasn’t aware you need to create all the fields first. I thought there is maybe like a standard metadata section of the PublishedFile entity in which you can just dump some metadata in dictionary form.

Hey Paul,

exactly thats where you need to be.

And no, each Entity in ShotGrid comes with a standard amount of fields.
If you want to register extra information you need to create extra fields to house that info.

You could instead of creating loads of fields also dump the data in dictionary form inside a text field on the published file

OR

dump the metadata to a json file and upload this to a custom metadata file field on the Published file to retrieve it later.

It depends on how much metadata you are recording, I would imagine text fields in the database have some kind of size limit.