Publishing an Asset
The methods for publishing an Asset in a custom Asset Management System are createAssetAndPath() and postCreateAsset().
createAssetAndPath() creates or updates an asset entry, given a collection of fields and an asset type. It returns the ID of the asset, which resolves to a valid file path. It is invoked prior to writing an asset. The fields passed to createAssetAndPath() may be the result of a decomposed Asset ID stored as a parameter on a node.
Both createAssetAndPath() and postCreateAsset() are used by Katana mechanisms that write assets. The Asset ID returned from createAssetAndPath() is used to create the fields passed to postCreateAsset(). The result from postCreateAsset() is used from that point onward (such as in the File > Open Recent menu or in any references to that asset ID in the current scene):
assetFields1 = assetPlugin.getAssetFields(assetId, True) id1 = assetPlugin.createAssetAndPath(..., assetFields1, ...) [Write Katana project file, for example] assetFields2 = assetPlugin.getAssetFields(id1, True) id2 = assetPlugin.postCreateAsset(..., assetFields2, ...)
This is done to allow a temporary file path to be used for the write operation. The LookFileBake node and the Render node use these methods.
createAssetAndPath()
The arguments for createAssetAndPath() are:
• txn
The Asset Transaction (implementation optional). Can be used to group create/publish operations together into one cancelable operation. This transaction is created via the createTransaction method.
• assetType
A string representing which of the supported asset types is published. See Asset Types and Contexts for a list of the asset types, and contexts.
• fields
A dictionary of strings containing the asset fields that represent the location of the asset. These are typically produced by de-serializing an Asset ID stored as a parameter on a node (such as a LookFileBake node). These fields are based on the Asset ID returned by createAssetAndPath().
• args
A dictionary containing additional information about what asset type to create. For example, should we increment the asset version? Is it an image, is it a Katana file? This is populated directly by the caller of createAssetAndPath() and varies with the asset type.
• createDirectory
A Boolean indicating that a new directory for the asset needs to be created.
createAssetAndPath() should return the Asset ID of the newly created asset. This may be different to the serialized Asset ID representation of the fields passed in. For example, if createAssetAndPath() were to versionUp the asset the returned Asset ID would likely be different to the serialized fields passed in. The returned Asset ID can be stored as a parameter on the node using this plug-in (if it is being used by a node).
The important arguments are assetType, fields and args. There are no rules for how the args dictionary is populated. It depends on the calling context and the Asset Type that createAssetAndPath() was invoked for.
postCreateAsset()
postCreateAsset() is invoked after Katana has finished writing to an asset file and is used to finalize the publication of the asset.
The args dictionary for this type contains:
• txn
The Asset Transaction.
• assetType
A string representing which of the supported asset types is published. See Asset Types and Contexts for a list of the asset types, and contexts.
• fields
The fields that represent the location of the asset. These fields are the identical to those given to createAssetAndPath().
• args
A dictionary of strings containing additional information about what asset type to create. For example, should we increment the asset version? If it is an image, what resolution should it be?
Examples
Selecting File > Version Up and Save triggers createAssetAndPath() to be invoked with an args dictionary, in which the versionUp and publish keys are set to ’True’. This results in a different Asset ID to that of the serialized fields passed in. versionUp indicates that a new version of the asset should be published.
Selecting File > Save triggers createAssetAndPath(), invoked with versionUp and publish set to False, unless a custom asset browser has been written. In that case, versionUp and publish are based on the values returned from the getExtraOptions() method of a custom browser class. See Configuring the Asset Browser for more on this.