Skip to content

Commit da126b9

Browse files
author
Roberto De Ioris
committed
added command_apply for materials
1 parent a601633 commit da126b9

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

Source/UnrealEnginePython/Private/MaterialEditorUtilities/UEPyFMaterialEditorUtilities.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,55 @@ static PyObject *py_ue_paste_nodes_here(PyObject *cls, PyObject * args)
2727
Py_RETURN_NONE;
2828
}
2929

30+
static PyObject *py_ue_update_material_after_graph_change(PyObject *cls, PyObject * args)
31+
{
32+
PyObject *py_graph;
33+
34+
if (!PyArg_ParseTuple(args, "O:update_material_after_graph_change", &py_graph))
35+
return nullptr;
36+
37+
UEdGraph *Graph = ue_py_check_type<UEdGraph>(py_graph);
38+
if (!Graph)
39+
{
40+
return PyErr_Format(PyExc_Exception, "argument is not a UEdGraph");
41+
}
42+
43+
FMaterialEditorUtilities::UpdateMaterialAfterGraphChange(Graph);
44+
Py_RETURN_NONE;
45+
}
46+
47+
static PyObject *py_ue_command_apply(PyObject *cls, PyObject * args)
48+
{
49+
PyObject *py_material;
50+
51+
if (!PyArg_ParseTuple(args, "O:command_apply", &py_material))
52+
return nullptr;
53+
54+
UMaterial *Material = ue_py_check_type<UMaterial>(py_material);
55+
if (!Material)
56+
{
57+
return PyErr_Format(PyExc_Exception, "argument is not a UMaterial");
58+
}
59+
60+
IAssetEditorInstance *Instance = FAssetEditorManager::Get().FindEditorForAsset(Material, false);
61+
if (!Instance)
62+
{
63+
return PyErr_Format(PyExc_Exception, "unable to retrieve editor for UMaterial");
64+
}
65+
66+
IMaterialEditor *MaterialEditor = (IMaterialEditor *)Instance;
67+
68+
MaterialEditor->GetToolkitCommands()->ExecuteAction(FMaterialEditorCommands::Get().Apply.ToSharedRef());
69+
70+
Py_RETURN_NONE;
71+
72+
}
73+
3074

3175
static PyMethodDef ue_PyFMaterialEditorUtilities_methods[] = {
3276
{ "paste_nodes_here", (PyCFunction)py_ue_paste_nodes_here, METH_VARARGS | METH_CLASS, "" },
77+
{ "update_material_after_graph_change", (PyCFunction)py_ue_update_material_after_graph_change, METH_VARARGS | METH_CLASS, "" },
78+
{ "command_apply", (PyCFunction)py_ue_command_apply, METH_VARARGS | METH_CLASS, "" },
3379
{ NULL } /* Sentinel */
3480
};
3581

Source/UnrealEnginePython/Private/MaterialEditorUtilities/UEPyFMaterialEditorUtilities.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#if WITH_EDITOR
66

77
#include "Editor/MaterialEditor/Public/MaterialEditorUtilities.h"
8+
#include "Editor/MaterialEditor/Public/MaterialEditorActions.h"
9+
#include "Editor/UnrealEd/Public/Toolkits/AssetEditorManager.h"
10+
#include "Editor/MaterialEditor/Public/IMaterialEditor.h"
811

912
typedef struct
1013
{

0 commit comments

Comments
 (0)