How to Store Custom Metadata
CE.SDK allows you to store custom metadata in your scenes. You can attach metadata to your scene or directly to your individual design blocks within the scene. This metadata is persistent across saving and loading of scenes. It simply consists of key value pairs of strings. Using any string-based serialization format such as JSON will allow you to store even complex objects. Please note that when duplicating blocks their metadata will also be duplicated.
This example uses the headless CreativeEngine. See the Setup article for a detailed guide.
To get started right away, you can also access the
block API within a running CE.SDK instance via
Check out the APIs Overview to see that illustrated in more detail.
Working with Metadata#
We can add metadata to any design block using
setMetadata(block: number, key: string, value: string). This also includes the scene block.
We can retrieve metadata from any design block or scene using
getMetadata(block: number, key: string): string. Before accessing the metadata you check for its existence using
hasMetadata(block: number, key: string): boolean.
We can query all metadata keys from any design block or scene using
findAllMetadata(block: number): string. For blocks without any metadata, this will return an empty list.
If you want to get rid of any metadata, you can use
removeMetadata(block: number, key: string).
Metadata will automatically be saved and loaded as part the scene. So you don't have to worry about it getting lost or having to save it separately.