Skip to content

Commit 24143a2

Browse files
author
rdeioris
committed
added open_editor_for_asset, close_editor_for_asset and close_all_asset_editors
1 parent e67ef8f commit 24143a2

File tree

5 files changed

+57
-5
lines changed

5 files changed

+57
-5
lines changed

Source/UnrealEnginePython/Private/UEPyAnimSequence.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "UnrealEnginePythonPrivatePCH.h"
22
#include "Animation/AnimSequence.h"
3+
#include "Animation/BlendSpaceBase.h"
34

45
PyObject *py_ue_anim_sequence_get_skeleton(ue_PyUObject * self, PyObject * args) {
56
ue_py_check(self);
@@ -13,7 +14,7 @@ PyObject *py_ue_anim_sequence_get_skeleton(ue_PyUObject * self, PyObject * args)
1314
Py_INCREF(Py_None);
1415
return Py_None;
1516
}
16-
17+
1718
ue_PyUObject *ret = ue_get_python_wrapper((UObject *)skeleton);
1819
if (!ret)
1920
return PyErr_Format(PyExc_Exception, "uobject is in invalid state");

Source/UnrealEnginePython/Private/UEPyAnimSequence.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
#include "UnrealEnginePython.h"
66

7-
PyObject *py_ue_anim_sequence_get_skeleton(ue_PyUObject *, PyObject *);
7+
PyObject *py_ue_anim_sequence_get_skeleton(ue_PyUObject *, PyObject *);

Source/UnrealEnginePython/Private/UEPyEditor.cpp

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "Editor/ContentBrowser/Public/IContentBrowserSingleton.h"
2020
#include "Runtime/Engine/Classes/EdGraph/EdGraphPin.h"
2121
#include "Runtime/Engine/Classes/EdGraph/EdGraphSchema.h"
22+
#include "Toolkits/AssetEditorManager.h"
2223

2324

2425
PyObject *py_unreal_engine_get_editor_world(PyObject * self, PyObject * args) {
@@ -554,8 +555,10 @@ PyObject *py_unreal_engine_delete_asset(PyObject * self, PyObject * args) {
554555
TArray<UObject *> objects;
555556
objects.Add(u_object);
556557

557-
if (ObjectTools::ForceDeleteObjects(objects, show_confirmation) < 1) {
558-
return PyErr_Format(PyExc_Exception, "unable to delete asset %s", path);
558+
if (ObjectTools::DeleteObjects(objects, show_confirmation) < 1) {
559+
if (ObjectTools::ForceDeleteObjects(objects, show_confirmation) < 1) {
560+
return PyErr_Format(PyExc_Exception, "unable to delete asset %s", path);
561+
}
559562
}
560563

561564
Py_INCREF(Py_None);
@@ -578,7 +581,7 @@ PyObject *py_unreal_engine_delete_object(PyObject * self, PyObject * args) {
578581

579582
TArray<UObject *> objects_to_delete;
580583
objects_to_delete.Add(u_object);
581-
584+
582585

583586
if (py_bool && PyObject_IsTrue(py_bool)) {
584587
if (ObjectTools::ForceDeleteObjects(objects_to_delete, false) < 1) {
@@ -788,6 +791,47 @@ PyObject *py_unreal_engine_get_selected_assets(PyObject * self, PyObject * args)
788791
return assets_list;
789792
}
790793

794+
PyObject *py_unreal_engine_open_editor_for_asset(PyObject * self, PyObject * args) {
795+
PyObject *py_obj;
796+
797+
if (!PyArg_ParseTuple(args, "O:open_editor_for_asset", &py_obj)) {
798+
return NULL;
799+
}
800+
801+
UObject *u_obj = ue_py_check_type<UObject>(py_obj);
802+
if (!u_obj)
803+
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
804+
if (FAssetEditorManager::Get().OpenEditorForAsset(u_obj)) {
805+
Py_INCREF(Py_True);
806+
return Py_True;
807+
}
808+
Py_INCREF(Py_False);
809+
return Py_False;
810+
}
811+
812+
PyObject *py_unreal_engine_close_editor_for_asset(PyObject * self, PyObject * args) {
813+
PyObject *py_obj;
814+
815+
if (!PyArg_ParseTuple(args, "O:close_editor_for_asset", &py_obj)) {
816+
return NULL;
817+
}
818+
819+
UObject *u_obj = ue_py_check_type<UObject>(py_obj);
820+
if (!u_obj)
821+
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
822+
FAssetEditorManager::Get().CloseAllEditorsForAsset(u_obj);
823+
824+
Py_INCREF(Py_None);
825+
return Py_None;
826+
}
827+
828+
PyObject *py_unreal_engine_close_all_asset_editors(PyObject * self, PyObject * args) {
829+
FAssetEditorManager::Get().CloseAllAssetEditors();
830+
831+
Py_INCREF(Py_None);
832+
return Py_None;
833+
}
834+
791835
PyObject *py_unreal_engine_set_fbx_import_option(PyObject * self, PyObject * args) {
792836
PyObject *obj;
793837

Source/UnrealEnginePython/Private/UEPyEditor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ PyObject *py_unreal_engine_allow_actor_script_execution_in_editor(PyObject *, Py
8181
PyObject *py_unreal_engine_get_asset_referencers(PyObject *, PyObject *);
8282
PyObject *py_unreal_engine_get_asset_dependencies(PyObject *, PyObject *);
8383

84+
PyObject *py_unreal_engine_open_editor_for_asset(PyObject *, PyObject *);
85+
PyObject *py_unreal_engine_close_editor_for_asset(PyObject *, PyObject *);
86+
PyObject *py_unreal_engine_close_all_asset_editors(PyObject *, PyObject *);
87+
8488
// transactions
8589
PyObject *py_unreal_engine_begin_transaction(PyObject *, PyObject *);
8690
PyObject *py_unreal_engine_cancel_transaction(PyObject *, PyObject *);

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ static PyMethodDef unreal_engine_methods[] = {
144144
{ "get_content_dir", py_unreal_engine_get_content_dir, METH_VARARGS, "" },
145145
{ "convert_relative_path_to_full", py_unreal_engine_convert_relative_path_to_full, METH_VARARGS, "" },
146146
#if WITH_EDITOR
147+
{ "open_editor_for_asset", py_unreal_engine_open_editor_for_asset, METH_VARARGS, "" },
148+
{ "close_editor_for_asset", py_unreal_engine_close_editor_for_asset, METH_VARARGS, "" },
149+
{ "close_all_asset_editors", py_unreal_engine_close_all_asset_editors, METH_VARARGS, "" },
147150
{ "allow_actor_script_execution_in_editor", py_unreal_engine_allow_actor_script_execution_in_editor , METH_VARARGS, "" },
148151
{ "get_editor_world", py_unreal_engine_get_editor_world, METH_VARARGS, "" },
149152
{ "editor_get_selected_actors", py_unreal_engine_editor_get_selected_actors, METH_VARARGS, "" },

0 commit comments

Comments
 (0)