Datasmith のインポート プロセス中に、unreal.DatasmithSceneElement オブジェクトを使用してシーンのオブジェクトに関するメタデータを取得できます。次の関数の詳細については、「Python API リファレンス」 を参照してください。
get_all_metadata(object_class) Retrieves an array of all metadata objects recorded for all objects in the Datasmith Scene.
get_all_objects_and_values_for_key(key, object_class) Retrieves a list of all objects in the Datasmith Scene that have a specified key.You'll also get a list of all values recorded for that key across all those objects.
get_metadata_for_object(object) Retrieves all metadata assigned to a specified object.
get_metadata_value_for_key(object, key) Retrieves the value of a specified key assigned to a specified object.
get_metadata_keys_and_values_for_value(object, string_to_match) Retrieves all keys on a specified object whose value matches the second parameter.
key_name = "name"
remove_keyword = "Clutch"
meshes_to_skip = set([])
# Get all scene elements that have the "name" key.
objects_and_values = ds_scene_in_memory.get_all_objects_and_values_for_key(key_name, unreal.DatasmithMeshActorElement)
objects = objects_and_values[0]
values = objects_and_values[1]
# Iterate through them looking for ones whose value matches a keyword
for index, value in enumerate(values):
if remove_keyword in value:
print("removing actor named: " + value)
# Remove the mesh actor element from the scene, and put the mesh element in a list to remove later
mesh_actor = objects[index]
mesh = mesh_actor.get_mesh_element()
meshes_to_skip.add(mesh)
ds_scene_in_memory.remove_mesh_actor(mesh_actor)
# Remove all the meshes we don't need to import.
for mesh in meshes_to_skip:
mesh_name = mesh.get_element_name()
print("removing mesh named " + mesh_name)
ds_scene_in_memory.remove_mesh(mesh)
上記の Get Datasmith User Data ノードおよび Get All Datasmith User Data ノードでは、Datasmith ユーザー データ オブジェクトのリファレンスを返します。このオブジェクトには、オブジェクトの Datasmith のメタデータを構成するすべてのキーと値/ペアのマップである、メタデータと呼ばれるアクセス可能な変数が 1 つあります。このタイプのオブジェクトを操作するには、出力ピンをドラッグして、[Variables (変数)] > [Get Metadata (メタデータの取得)] を選択します。
Datasmith のインポート プロセスが完了したら、unreal.DatasmithContentLibrary クラスを使用して、すべてのアクタまたは選択したアクタのメタデータにアクセスできます。次の関数の詳細については、「Python API リファレンス」 を参照してください。
get_all_datasmith_user_data(object_class) Retrieves the full list of all metadata objects for all Actors in the current Level.
get_all_objects_and_values_for_key(key, object_class) Retrieves a list of all Actors in the current Level that have a specified key in their Datasmith metadata.You'll also get a list of all values recorded for that key across all those objects.
get_datasmith_user_data(object) Retrieves a metadata object that contains all key-value pairs recorded for the specified Actor, so that you can iterate through them yourself.
get_datasmith_user_data_keys_and_values_for_value(object, string_to_match) Retrieves all keys on the specified Actor that have the value you specify in the second parameter.Use this node if you know the value you're looking for, but not the name of the key.
get_datasmith_user_data_value_for_key(object, key) Retrieves the value of the metadata with the specified key assigned to the specified Actor.
import unreal
new_actor_name = "Exterior Walls"
metadata_key = "Type"
metadata_value = "Wall:Exterior"
meshes_to_join = set([])
# Iterate through the Actors in the current Level
all_actors = unreal.EditorLevelLibrary.get_all_level_actors()
for actor in all_actors:
# Retrieve the value of this Actor's Datasmith metadata for the key set above, if any
actor_value = unreal.DatasmithContentLibrary.get_datasmith_user_data_value_for_key(actor, metadata_key)
# If the key exists, and its value contains a keyword set above, add the Actor to a list
if actor_value and metadata_value in actor_value:
print("found a matching actor: " + actor_value)
meshes_to_join.add(actor)
# Join all Actors that were found above into a single Actor with many components
options = unreal.EditorScriptingJoinStaticMeshActorsOptions(destroy_source_actors=True, new_actor_label=new_actor_name, rename_components_from_source=True)
unreal.EditorLevelLibrary.join_static_mesh_actors(meshes_to_join, options)
print "Merged all actors!"