Access and manage asset databases that contain assets which are exposed by the Asset Browser.
Assets are organized in asset databases and multiple databases can be connected to a running Cinema 4D instance, where each database contains at least the metadata for its assets. Asset databases can also contain caches for their stored data as preview thumbnails and downloaded content. Databases can be added in the Asset Browser section of the Preferences dialog of Cinema 4D, mounting them into Cinema 4D, and making both their primary data, the delivered content, and the associated metadata available in the Asset Browser and Asset API. Asset databases can be enabled or disabled: A disabled database will not contribute its assets and their metadata to the pool of assets accessible by the Asset Browser, but it will still be visible as a mounted database in asset database overview in the Asset Browser and in the Asset Browser Preferences.
The logical interface for asset databases are asset repositories which provide access to assets stored within databases. Each asset in a repository has an identifier which makes it an addressable entity. Repositories can represent one or multiple databases and allow either read and write access or read access only. An asset repository can have multiple bases, which are references to other repositories, and thereby access content from these other repositories. Within such asset repository with bases an asset identifier can occur multiple times, once in the main repository and once in each of its bases. In search operations for such duplicate asset identifiers the main repository takes then precedence over the bases unless specified differently. Asset identifiers can also be duplicated over asset versions, as assets with different versions are all stored under the same asset identifier but a different version identifier. The only way to uniquely identify an asset is therefore by searching both for the asset identifier and version of an asset.
There are three important premade repositories provided by Cinema 4D which bundle up other repositories: The builtin repository which contains the assets that are built into Cinema 4D. The application repository which includes the former and contains most of the atomic assets as for example builtin node templates. And finally the user preferences repository, a common entry point for asset searches, which contains both the builtin and application repository, as well as the content of the asset database shipped with Cinema 4D in the form of objects, materials, scenes and more. Databases added by the user will also be part of the user preferences repository. Additionally, each Cinema 4D project can have its own dedicated repository which is being loaded and stored with that scene file.
An asset database is represented by a AssetDatabaseStruct, containing the the Url of the database and if the database is active or not. The interface AssetDataBasesInterface provides the ability to mount and unmount databases, clear database caches, as well as to find repositories for a specific database. The databases shipped with Cinema 4D cannot be unmounted and are also not exposed as AssetDatabaseStruct instances. The logical interface to access assets in databases is AssetRepositoryInterface. It represents an asset repository which can wrap one or multiple asset databases and provides means to read, write and search for assets. Assets within an asset repository are represented as AssetDescriptionInterface references, containing all the metadata that describe an asset.
For asset access usually one of the larger application provided asset repositories is being used. Either the application repository or more often the user preferences repository which contains most of the asset content. They can be accessed with GetApplicationRepository and GetUserPrefsRepository. The application repository is read only, while the user preferences repository grants both read and write access to the asset descriptions managed by it.
Assets repositories can be searched with the methods AssetRepositoryInterface::FindAssets and AssetRepositoryInterface::FindLatestAsset. The former allows to search with complex search operations for a set of assets, while the latter searches for a singular asset with a known asset identifier. Assets can be stored in an asset repository with the method AssetRepositoryInterface::StoreAsset and erased with the method AssetRepositoryInterface::EraseAsset. Repositories also provide the ability to react to events that occur on them, as for example assets being stored, erased or updated. This is realized through Observables attached to an asset repository to which users can attach their observer delegates. When an event occurs on the repository the observable is related to, all its observer delegates will be called with the data relevant to the event; for example the old and new metadata on a metadata update event.
Articles | Asset API | Provide content as reusable assets served with the Cinema 4D Asset Browser. |
Entity Creation | Explains the managed memory environment of the maxon API with interfaces and references. | |
Observables | Explains the concept of observables and observers, used to bind multiple delegates to an event. | |
Important API Entities | AssetDataBasesInterface | Provides means to access and handle asset databases. |
AssetDatabaseStruct | Represents an asset database over its Url and other attributes. | |
AssetRepositoryInterface | Provides access to the assets of one or multiple asset databases wrapped by an asset repository. | |
AssetDescriptionInterface | Represents an asset over its metadata in an asset repository. | |
AssetManagerInterface | Provides limited control over the Asset Manager. | |
SDK Plugins | Asset API Examples | Showcases basic interactions with the Asset API to modify asset databases and their content. |
Examples | Add User Databases | Add an asset database to the running Cinema 4D instance. |
Remove User Databases | Remove an asset database from the running Cinema 4D instance. | |
Activate User Databases | Activate an asset database attached to the running Cinema 4D instance. | |
Deactivate User Databases | Deactivate an asset database attached to the running Cinema 4D instance. | |
Access User Databases | Access all user databases attached to the running Cinema 4D instance. | |
Create Repositories for User Databases | Create repositories for specific user databases to speed up search operations. | |
Access Important Repositories | Access the important builtin, application, user preferences and active document repositories. | |
Attach Observers to Repositories | Attach observers to a repository to react to new assets being added or the metadata of assets being modified. | |
Detach Observers from Repositories | Detach observers from a repository which previously have been attached. | |
Store Assets | Store an asset instance in a repository. | |
Copy Assets | Copy assets with all their data and metadata. | |
Erase Assets | Permanently remove assets and their metadata from an asset database. | |
Perform Simple Asset Searches | Perform simple search operations for one or multiple assets in an asset repository. | |
Perform Filtered Asset Searches | Perform filtered search operations for a set of assets over their metadata attributes. | |
Perform Sorted Asset Searches | Perform a search operation for a set of assets with the assets being sorted by their metadata attributes. |
The examples shown here are all related to the "Databases" category in the Asset API Examples plugin. With the plugin you can run these examples to see their output. Each example shown here has a link bar at its bottom, linking to the code on GitHub, as well as to a calling context on GitHub. A calling context is a function which showcases how to gather the required inputs for that specific example and is targeted at users who want to know how to carry out a specific task in more detail. The context link is named "How to call this example ...".
Adds an asset database to the running Cinema 4D instance.
If the given directory does contain already an asset database, the added database will wrap around this data. If not, the necessary data for a new database will be created within the given directory. If the given url is already mounted as a database, that database will be returned.
Attempts to remove a user databases from of the running Cinema 4D instance.
Will raise an error if the given url is not a mounted database.
Activates a user database to make its assets accessible.
Activated databases will appear as checked in the Asset Browser section of the Cinema 4D Preferences dialog and their assets will become available in the Asset Browser.
Deactivates a user database to make its assets inaccessible.
Deactivated databases will appear as unchecked in the Asset Browser section of the Cinema 4D Preferences dialog and their assets will become unavailable in the Asset Browser.
Accesses the data structures representing the user asset databases.
The accessed AssetDatabaseStruct instances only contain meta information about the user databases, not the content of these databases. See AccessImportantRepositories for how to access the repositories of the application databases.
Creates repositories for a passed collection of databases.
The function CreateRepositoryFromUrl used in this example can also be used to create a repository and its underlying database from scratch when the provided Url points to location where no database has been established yet. See Access User Databases for how to access the AssetDatabaseStruct instances for the user databases.
Accesses the builtin, application, user preferences and active document repositories.
The user preferences repository plays a central role as it contains most of the content which is accessible with the Asset Browser and therefor the usual choice for searching for assets or adding assets when there is no dedicated user database available.
Attaches observers for both a new asset being created and new metadata being stored to the respective observables of the passed repository.
An Observable is an entity that invokes one or multiple delegate functions, called observers, when a specific event has occurred. This example attaches an observer to each of the observables ObservableAssetStored and ObservableMetaDataStored associated with an asset repository. The observers attached in this example only report the changes that have been carried out and do nothing else. There are more observables attached to an asset repository as shown here; with which asset deletion, update and download events can be caught among other things.
Attempts to detach the observers qualified by the passed in observer data from the passed repository.
This example can only be understood in the context of the example Attach Observers to Repositories. It will attempt to remove the observers that have been attached by the other example from the respective observables.
Stores an asset instance in a repository.
Assets can be stored in a repository with the method AssetRepositoryInterface::StoreAsset. But this form of creating and storing assets is usually only required for minor asset types as keywords, categories and custom third party asset types. The core asset types for scenes, materials, objects, nodes, and image and movie files have convenience functions which simplify the process of creating assets of that type and StoreAsset is not required in these cases. See Asset Types for more information on asset types and how to create and load them. The example shown here is identical to the example Create Category Assets in the asset types documentation.
Copies the passed asset into the passed repository.
Attempts to derive a matching asset identifier prefix from the asset identifier of the asset to copy and modifies the name of the new asset to indicate that it has been copied.
Removes the passed asset from the passed repository permanently.
Performs a search operation for an asset by its type, id or version.
Performs a filtered search evaluating the metadata of the searched assets while searching.
Search operations can be filtered more granularly with a delegate passed for the value receiver of the search operation, allowing to in- or exclude assets from the search results over their metadata.
Performs a search operation for a set of assets with the assets being sorted by their name and version attributes.
The sorting is realized with the type SortedArray. This can technique can be combined with both the simple and filtered asset search approach. Shown here is only a sorted simple search, where a sorted array takes place of the value receiver.