Manage metadata
Manage asset metadata in Unity Asset Manager using the Python SDK, including how to create, update, and delete metadata fields.
읽는 시간 3분최근 업데이트: 일 년 전
Before you begin
To access any metadata from an asset, dataset or file, make sure the app has all the right accesses. Read more about managing Identity.
How do I...?
Create a metadata field definition
To create a metadata field, follow these steps:
- Create a object and fill in the necessary information.
CreateField - Call with the organization id and your
create_field_definitionobject. The possible forCreateFieldare:FieldDefinitionTypeBOOLEANSELECTIONNUMBERTEXTTIMESTAMPURLUSER
create_field = CreateFieldDefinition( key = "my_new_field", display_name = "My Field", type = unity_cloud.assets.FieldDefinitionType.SELECT, accepted_values = ["value1", "value2", "value3"], multiselection = False)unity_cloud.assets.create_field_definition(org_id = "0123456", create_field = create_field)
Update a metadata field definition
To update a metadata field, follow these steps:
- Create an object along with the information to update.
UpdateField - Call with the organization id and your
update_field_definition.UpdateFieldobject
update_field = UpdateFieldDefinition( key = "my_new_field", display_name = "My Field with a new name", accepted_values = ["value1", "value2", "value3", "value4"])unity_cloud.assets.update_field_definition(org_id = "0123456", update_field = create_field)
Add accepted values to a SELECT metadata field
To add accepted values to a metadata field of type , call with the new values.
SELECTadd_accepted_values_to_field_definitionThis action removes the necessity of calling with all the already existing values.
update_field_definitionunity_cloud.assets.add_accepted_values_to_field_definition(org_id = "0123456", field_key = "my_new_field", accepted_values = ["value5", "value6"])
Remove accepted values from a SELECT metadata field
To remove accepted values to a metadata field of type , call with the values you want removed.
SELECTremove_accepted_values_from_field_definitionThis action removes the necessity of calling with the values you want to keep.
update_field_definitionunity_cloud.assets.remove_accepted_values_from_field_definition(org_id = "0123456", field_key = "my_new_field", accepted_values = ["value5", "value6"])
Delete a metadata field definition
To delete a metadata field, call delete_field_definition with its organization id and field key.
unity_cloud.assets.delete_field_definition(org_id = "0123456", field_key = "my_new_field")
List all field definitions
To retrieve all metadata field from an organization, call with the organization id and whether or not you want deleted field included in the list.
list_field_definitions- (Optional) Add the parameter name_sorting_order to sort the results alphabetically either in ascending or descending.
- (Optional) Add the parameter to limit the amount of results returned. Leave it unchanged or set it to 0 to return everything.
limit_to - (Optional) Add the parameter to specify the number of collection to skip in the results. Use in combination with limit_to to page through results.
skip
fields = unity_cloud.assets.list_field_definitions( org_id = "0123456", include_deleted = False, name_sorting_order = SortingOrder.ASCENDING, limit_to = 10, skip = 0)
Get a field definition
To retrieve a metadata field from an organization, call with the organization id and the key of the field.
get_field_definitionfield = unity_cloud.assets.get_field_definition(org_id = "0123456", field_key = "my_new_field")
Manage metadata
When managing dictionaries, make sure the dictionaries have existing metadata field keys and consistent values according to their type.
MetadataFor a field with a type, accepted_values can either be a string or an array of strings. This distinction depends on the value set for multiselection:
SELECT- If set to , the
TRUEis an array of strings.accepted_values - If set to , the
FALSEis a string.accepted_values
- Use the following code sample to create an entity:
metadata = dict()metadata["Language"] = "C#"asset_creation = AssetCreation( name = "your-asset-name", description = "your-asset-description", type = unity_cloud.assets.asset_type.MODEL_3D, metadata = metadata)
- Use the following code sample to update an entity:
metadata = dict() metadata["Language"] = "C#" asset_update = AssetUpdate( name = "your-asset-name", metadata = metadata )
- Use the following code sample to fetch an entity's metadata:
asset_metadata = unity_cloud.assets.get_asset_metadata( org_id = "012345", project_id = "1234abcd-ab12-cd34-ef56-123456abcdef", asset_id = "0123456789", keys = [])asset_prog_language = asset_metadata["Language"]dataset_metadata = unity_cloud.datasets.get_dataset_metadata( org_id = "012345", project_id = "1234abcd-ab12-cd34-ef56-123456abcdef", asset_id = "0123456789", dataset_id = "0123456789", keys = [])file_Metadata = unity_cloud.files.get_file_metadata( org_id = "012345", project_id = "1234abcd-ab12-cd34-ef56-123456abcdef", asset_id = "0123456789", dataset_id = "0123456789", cloud_file_path = PurePosixPath("path/to/file.ext"), keys = [])