Skip to content

Commit

Permalink
added get_asset_identifier_referencers()
Browse files Browse the repository at this point in the history
  • Loading branch information
rdeioris committed Nov 28, 2018
1 parent c2901db commit d5386c3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
38 changes: 33 additions & 5 deletions Source/UnrealEnginePython/Private/UEPyEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,18 +639,19 @@ PyObject *py_unreal_engine_create_asset(PyObject * self, PyObject * args)
PyObject *py_unreal_engine_get_asset_referencers(PyObject * self, PyObject * args)
{
char *path;
int depency_type = (int)EAssetRegistryDependencyType::All;

if (!PyArg_ParseTuple(args, "s:get_asset_referencers", &path))
if (!PyArg_ParseTuple(args, "s|i:get_asset_referencers", &path, &depency_type))
{
return NULL;
return nullptr;
}

if (!GEditor)
return PyErr_Format(PyExc_Exception, "no GEditor found");

FAssetRegistryModule& AssetRegistryModule = FModuleManager::GetModuleChecked<FAssetRegistryModule>("AssetRegistry");
TArray<FName> referencers;
AssetRegistryModule.Get().GetReferencers(UTF8_TO_TCHAR(path), referencers);
AssetRegistryModule.Get().GetReferencers(UTF8_TO_TCHAR(path), referencers, (EAssetRegistryDependencyType::Type) depency_type);

PyObject *referencers_list = PyList_New(0);
for (FName name : referencers)
Expand All @@ -660,11 +661,38 @@ PyObject *py_unreal_engine_get_asset_referencers(PyObject * self, PyObject * arg
return referencers_list;
}

PyObject *py_unreal_engine_get_asset_identifier_referencers(PyObject * self, PyObject * args)
{
char *path;
int depency_type = (int)EAssetRegistryDependencyType::All;

if (!PyArg_ParseTuple(args, "s|i:get_asset_identifier_referencers", &path, &depency_type))
{
return nullptr;
}

if (!GEditor)
return PyErr_Format(PyExc_Exception, "no GEditor found");

FAssetRegistryModule& AssetRegistryModule = FModuleManager::GetModuleChecked<FAssetRegistryModule>("AssetRegistry");
TArray<FAssetIdentifier> referencers;
AssetRegistryModule.Get().GetReferencers(FAssetIdentifier::FromString(UTF8_TO_TCHAR(path)), referencers, (EAssetRegistryDependencyType::Type) depency_type);

PyObject *referencers_list = PyList_New(0);
for (FAssetIdentifier identifier : referencers)
{
PyList_Append(referencers_list, PyUnicode_FromString(TCHAR_TO_UTF8(*identifier.ToString())));
}
return referencers_list;
}


PyObject *py_unreal_engine_get_asset_dependencies(PyObject * self, PyObject * args)
{
char *path;
int depency_type = (int)EAssetRegistryDependencyType::All;

if (!PyArg_ParseTuple(args, "s:get_asset_dependencies", &path))
if (!PyArg_ParseTuple(args, "s|i:get_asset_dependencies", &path, &depency_type))
{
return NULL;
}
Expand All @@ -674,7 +702,7 @@ PyObject *py_unreal_engine_get_asset_dependencies(PyObject * self, PyObject * ar

FAssetRegistryModule& AssetRegistryModule = FModuleManager::GetModuleChecked<FAssetRegistryModule>("AssetRegistry");
TArray<FName> dependencies;
AssetRegistryModule.Get().GetDependencies(UTF8_TO_TCHAR(path), dependencies);
AssetRegistryModule.Get().GetDependencies(UTF8_TO_TCHAR(path), dependencies, (EAssetRegistryDependencyType::Type) depency_type);

PyObject *dependencies_list = PyList_New(0);
for (FName name : dependencies)
Expand Down
1 change: 1 addition & 0 deletions Source/UnrealEnginePython/Private/UEPyEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ PyObject *py_unreal_engine_create_material_instance(PyObject *, PyObject *);
PyObject *py_unreal_engine_allow_actor_script_execution_in_editor(PyObject *, PyObject *);

PyObject *py_unreal_engine_get_asset_referencers(PyObject *, PyObject *);
PyObject *py_unreal_engine_get_asset_identifier_referencers(PyObject *, PyObject *);
PyObject *py_unreal_engine_get_asset_dependencies(PyObject *, PyObject *);

PyObject *py_unreal_engine_open_editor_for_asset(PyObject *, PyObject *);
Expand Down
1 change: 1 addition & 0 deletions Source/UnrealEnginePython/Private/UEPyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ static PyMethodDef unreal_engine_methods[] = {
{ "sync_browser_to_assets", py_unreal_engine_editor_sync_browser_to_assets, METH_VARARGS, "" },

{ "get_asset_referencers", py_unreal_engine_get_asset_referencers, METH_VARARGS, "" },
{ "get_asset_identifier_referencers", py_unreal_engine_get_asset_identifier_referencers, METH_VARARGS, "" },
{ "get_asset_dependencies", py_unreal_engine_get_asset_dependencies, METH_VARARGS, "" },

{ "rename_asset", py_unreal_engine_rename_asset, METH_VARARGS, "" },
Expand Down

0 comments on commit d5386c3

Please sign in to comment.