Asset Library
Asset Library is how you access materials for use in your garments. Use the Asset Library API to create a library, add a collection to a library, add an asset to a collection, and so on.
For more information about the feature, please visit here.
To learn more about the rest of the API, please refer to Asset Library in the repository.
Sample Plugin
Sample plugin for the asset library is available here
Adding an Asset Library
Code Snippet
The library add function receives a JSON file (as a string) that contains all the library information.
Python C++ C#
Python
# assuming library_info is valid library info object asset_library_id = BwApi.AssetLibAdd(library_info)
C++
// assuming libraryInfo is valid library info object BwApiString* assetLibraryId = BwApiStringCreate(); BwApiAssetLibAdd(libraryInfo, assetLibraryId);
C#
// assuming libraryInfo is valid library info object string assetLibraryId; BwApi.AssetLibAdd(libraryInfo, out assetLibraryId);
Result
Updating an Asset Library
Code Snippet
The library add function receives a JSON file (as a string) that contains all the library information.
Python C++ C#
Python
# assuming library_info is valid library info object BwApi.AssetLibUpdate(asset_library_id, library_info)
C++
// assuming libraryInfo is valid library info object BwApiAssetLibUpdate(BwApiStringGet(assetLibraryId), libraryInfo)
C#
// assuming libraryInfo is valid library info object BwApi.AssetLibUpdate(assetLibraryId, libraryInfo);
Getting Asset Library information
Code Snippet
Python C++ C#
Python
library_info = BwApi.AssetLibGet(asset_library_id)
C++
BwApiString* libraryInfoJson = BwApiStringCreate(); BwApiAssetLibGet(BwApiStringGet(assetLibraryId), libraryInfoJson);
C#
BwApi.AssetLibGet(assetLibraryId, out libraryInfoJson);
Result
A JSON file (as a string) that contains all the asset library information.
Removing an Asset Library
Code Snippet
Python C++ C#
Python
BwApi.AssetLibRemove(asset_library_id)
C++
BwApiAssetLibRemove(BwApiStringGet(assetLibraryId));
C#
BwApi.AssetLibRemove(assetLibraryId);
Registering an Asset Library Event
You can register your plugin to be notified when certain asset library events happen.
The supported events are:
BW_API_EVENT_ASSET_LIB_INITIALIZE
BW_API_EVENT_ASSET_LIB_DOWNLOAD_ASSET
BW_API_EVENT_ASSET_LIB_OPEN_EXTERNAL_LINK - if registered, the external link is enabled
BW_API_EVENT_ASSET_LIB_REFRESH
Code Snippet
Python C++ C#
Python
class EventCallback(BwApi.CallbackBase):
def Run(self, garment_id, callback_id, data_string):
# callback for asset library initialazation
if (callbackId == 1){
# do some stuff here
}
return 1callback = EventCallback()def BwApiPluginInit():
funcId = BwApi.AssetLibEventRegister(callback, 1, BwApi.BW_API_EVENT_ASSET_LIB_INITIALIZE)
return 1C++
class CEventCallback : public BwApiCallbackBase
{
public:
virtual int Run(const char* garmentId, long callbackId, const char* dataString);
{
// callback for asset library initialazation
if (callbackId == 1){
// do some stuff here
}
return 1;
}
};CEventCallback callback;BW_PLUGIN_EXPORT int WINAPI BwApiPluginInit()
{
int funcId = 0;
BwApiEventRegister(&callback, 1, BW_API_EVENT_ASSET_LIB_INITIALIZE, &funcId);
return 1;
}C#
using BwPluginApi;
class EventCallback : CallbackBase
{
public override int Run(string garmentId, int callbackId, string dataString)
{
// callback for asset library initialazation
if (callbackId == 1){
// do some stuff here
}
}
}public static EventCallback callback = new EventCallback();class BwApiPlugin
{
public static int Init(string args)
{
int funcId = 0;
BwApi.EventRegister(callback, 1, EventType.BW_API_EVENT_ASSET_LIB_INITIALIZE, out funcId);
return 1;
}
}Adding a Collection to an Asset Library
Code Snippet
The asset library collection add function receives a JSON file (as a string) that contains all the collection's information. For more information, refer to the schema.
Python C++ C#
Python
BwApi.AssetLibCollectionAdd(asset_library_id, collection_json)
C++
BwApiAssetLibCollectionAdd(BwApiStringGet(assetLibraryId), collectionJson, &collectionId);
C#
BwApi.AssetLibCollectionAdd(assetLibraryId, collectionJson, out collectionId);
Result
After adding 5 collections:
Removing a Collection from an Asset Library
Code Snippet
Python C++ C#
Python
BwApi.AssetLibCollectionRemove(asset_library_id, collection_id)
C++
const char* collectionJson; BwApiAssetLibCollectionRemove(BwApiStringGet(assetLibraryId), collectionId);
C#
BwApi.AssetLibCollectionRemove(assetLibraryId, collectionId);
Result
Seams collection was removed:
Getting Asset ids from a Collection
Code Snippet
Python C++ C#
Python
asset_ids = BwApi.AssetLibCollectionAssetIds(asset_library_id, collection_id)
C++
BwApiVectorInt* assetIds = BwApiVectorIntCreate(); BwApiAssetLibCollectionAssetIds(BwApiStringGet(assetLibraryId), assetIds);
C#
BwApiVectorInt assetIds = new BwApiVectorInt(); BwApi.AssetLibCollectionAssetIds(assetLibraryId, assetIds);
Result
List of Asset ids that are linked to the given collection id
Adding an Asset to an Asset Library
Code Snippet
The asset library asset add function receives a JSON file (as a string) that contains all the asset's information. For more information, refer to the schema.
Python C++ C#
Python
# assuming asset_json contains the above asset object settings asset_id = BwApi.AssetLibAssetAdd(asset_library_id, asset_json)
C++
// assuming assetJson contains the above asset object BwApiAssetLibAssetAdd(BwApiStringGet(assetLibraryId), assetJson, &assetId);
C#
// assuming assetJson contains the above asset object BwApi.AssetLibAssetAdd(assetLibraryId, assetJson, out assetId);
Result
New asset id.
Note:
The asset won't be available on the UI until it will be added to a collection using BwApiAssetLibCollectionAssetAdd
You may add the asset to multiple collections
Removing an Asset from an Asset Library
Code Snippet
Python C++ C#
Python
BwApi.AssetLibAssetRemove(asset_library_id, asset_id)
C++
const char* collectionJson; BwApiAssetLibAssetRemove(BwApiStringGet(assetLibraryId), assetId);
C#
BwApi.AssetLibAssetRemove(assetLibraryId, assetId);
Adding an Asset to a Collection
Code Snippet
Python C++ C#
Python
BwApi.AssetLibCollectionAssetAdd(asset_library_id, collection_id, asset_id)
C++
const char* collectionJson; BwApiAssetLibCollectionAssetAdd(BwApiStringGet(assetLibraryId), collectionId, assetId);
C#
BwApi.AssetLibCollectionAssetAdd(assetLibraryId, collectionId, assetId);
Result
Removing an Asset from a Collection
Code Snippet
Python C++ C#
Python
BwApi.AssetLibCollectionAssetRemove(asset_library_id, collection_id, asset_id)
C++
const char* collectionJson; BwApiAssetLibCollectionAssetRemove(BwApiStringGet(assetLibraryId), collectionId, assetId);
C#
BwApi.AssetLibCollectionAssetRemove(assetLibraryId, collectionId, assetId);
Result
Getting Asset ids from an Asset Library
Code Snippet
Python C++ C#
Python
asset_ids = BwApi.AssetLibAssetIds(asset_library_id)
C++
BwApiVectorInt* assetIds = BwApiVectorIntCreate(); BwApiAssetLibAssetIds(BwApiStringGet(assetLibraryId), assetIds);
C#
BwApiVectorInt assetIds = new BwApiVectorInt(); BwApi.AssetLibAssetIds(assetLibraryId, assetIds);
Result
List of all asset ids within the given library.
Configuring Library Information
Configure library.json file with your library information. For more information, refer to the schema.