LoginSignup
2
3

More than 1 year has passed since last update.

UE4のVisual DataprepをPythonから実行してみる

Posted at

UE4.27.2でpythonスクリプトでDataprepAssetを実行してみました。

本当はDataprepAssetInstanceで親DataprepAssetで公開されたパラメータ※を指定して実行したかったのですがまだサポートされてないそうなので直接DataprepAssetを使用しています。
※ Dataprep Editor の右上にある[Settings] パネルの [Parameterization] セクションで表示されるもの

DataprepAssetのパラメータ指定では直接各アクションのノードを指定してパラメータを指定しています。
値を指定したパラメータがリンクして公開されているとリンクされているノードのパラメータ全てに適用されるようです。

pythonスクリプト
# -*- coding: utf-8 -*-
import unreal

def get_step(dataprep_asset, action_index, step_index):
  action = unreal.EditorDataprepAssetLibrary.get_action(dataprep_asset, action_index)
  step = unreal.EditorDataprepAssetLibrary.get_step_object(action, step_index)
  return step

# マップ読み込み
unreal.EditorLoadingAndSavingUtils.load_map("default")

# DataprepAsset取得
asset_data = unreal.EditorAssetLibrary.find_asset_data("/Game/Dataprep/DataprepAsset")
asset = asset_data.get_asset()
dataprep_asset = unreal.DataprepAsset.cast(asset)
print(dataprep_asset)

# Producerクリア
count = unreal.EditorDataprepAssetLibrary.get_producers_count(dataprep_asset)
for i in range(0, count):
  unreal.EditorDataprepAssetLibrary.remove_producer(dataprep_asset, i)

# Producer追加、Input設定
producer = unreal.EditorDataprepAssetLibrary.add_producer_automated(dataprep_asset, unreal.DatasmithFileProducer)
file_producer = unreal.DatasmithFileProducer.cast(producer)
file_producer.set_editor_property("file_path", "c:\\model.udatasmith")

# Consumer設定
consumer = unreal.EditorDataprepAssetLibrary.get_consumer(dataprep_asset)
print(consumer.get_level_name())
print(consumer.get_target_content_folder())
consumer.set_level_name_automated("dataprepmap")
consumer.set_target_content_folder_automated("/Game/Dataprep")

# パラメータ設定
step = get_step(dataprep_asset, 0, 0)
step.set_editor_property("max", unreal.Vector(1,2,3))

step = get_step(dataprep_asset, 7, 0)
step.set_editor_property("user_string", "test")

step = get_step(dataprep_asset, 7, 1)
step.set_editor_property("min", unreal.Vector(3,4,5))

# 実行
result = unreal.EditorDataprepAssetLibrary.execute_dataprep(dataprep_asset, unreal.DataprepReportMethod.STANDARD_LOG,  unreal.DataprepReportMethod.STANDARD_LOG)
print(result)

unreal.EditorLoadingAndSavingUtils.save_dirty_packages(True, True)

ue4cliを使うと以下のようにコマンドラインでスクリプトの実行、ライティングビルドができました。

ue4 run dataprep.uproject -ExecutePythonScript="i:\dataprep.py"
ue4 run -Run=ResavePackages -Map=/Game/default -IgnoreChangeList -BuildLighting -Quality=Preview -MapsOnly -ProjectOnly -AllowCommandletRendering
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3