diff --git a/Source/UnrealEnginePython/Private/Blueprint/UEPyEdGraph.cpp b/Source/UnrealEnginePython/Private/Blueprint/UEPyEdGraph.cpp index 6f75053ba..a3e53b7c5 100644 --- a/Source/UnrealEnginePython/Private/Blueprint/UEPyEdGraph.cpp +++ b/Source/UnrealEnginePython/Private/Blueprint/UEPyEdGraph.cpp @@ -381,6 +381,127 @@ PyObject *py_ue_graph_add_node(ue_PyUObject * self, PyObject * args) Py_RETURN_UOBJECT(node); } +PyObject *py_ue_graph_remove_node(ue_PyUObject * self, PyObject * args) +{ + + ue_py_check(self); + + PyObject *py_node_class; + int x = 0; + int y = 0; + + char *metadata = nullptr; + PyObject *py_data = nullptr; + + if (!PyArg_ParseTuple(args, "O|iisO:graph_remove_node", &py_node_class, &x, &y, &metadata, &py_data)) + { + return nullptr; + } + + UEdGraph *graph = ue_py_check_type(self); + if (!graph) + return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraph"); + + UObject *u_obj = ue_py_check_type(py_node_class); + if (!u_obj) + return PyErr_Format(PyExc_Exception, "argument is not a UObject"); + + UEdGraphNode *node = nullptr; + + if (UClass *u_class = Cast(u_obj)) + { + if (!u_class->IsChildOf()) + { + return PyErr_Format(PyExc_Exception, "argument is not a child of UEdGraphNode"); + } + node = NewObject(graph, u_class); + node->PostLoad(); + } + else + { + node = Cast(u_obj); + if (node) + { + if (node->GetOuter() != graph) + + node->Rename(*node->GetName(), graph); + } + } + + if (!node) + return PyErr_Format(PyExc_Exception, "argument is not a supported type"); + + graph->RemoveNode(node); + + if (UBlueprint *bp = Cast(node->GetGraph()->GetOuter())) + { + FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(bp); + } + + Py_RETURN_NONE; +} + +PyObject *py_ue_graph_reconstruct_node(ue_PyUObject * self, PyObject * args) +{ + + ue_py_check(self); + + PyObject *py_node_class; + int x = 0; + int y = 0; + + char *metadata = nullptr; + PyObject *py_data = nullptr; + + if (!PyArg_ParseTuple(args, "O|iisO:graph_reconstruct_node", &py_node_class, &x, &y, &metadata, &py_data)) + { + return nullptr; + } + + UEdGraph *graph = ue_py_check_type(self); + if (!graph) + return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraph"); + + UObject *u_obj = ue_py_check_type(py_node_class); + if (!u_obj) + return PyErr_Format(PyExc_Exception, "argument is not a UObject"); + + UEdGraphNode *node = nullptr; + + if (UClass *u_class = Cast(u_obj)) + { + if (!u_class->IsChildOf()) + { + return PyErr_Format(PyExc_Exception, "argument is not a child of UEdGraphNode"); + } + node = NewObject(graph, u_class); + node->PostLoad(); + } + else + { + node = Cast(u_obj); + if (node) + { + if (node->GetOuter() != graph) + + node->Rename(*node->GetName(), graph); + } + } + + if (!node) + return PyErr_Format(PyExc_Exception, "argument is not a supported type"); + + //graph->RemoveNode(node); + node->ReconstructNode(); + + if (UBlueprint *bp = Cast(node->GetGraph()->GetOuter())) + { + FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(bp); + } + + Py_RETURN_NONE; +} + PyObject *py_ue_graph_add_node_dynamic_cast(ue_PyUObject * self, PyObject * args) { diff --git a/Source/UnrealEnginePython/Private/Blueprint/UEPyEdGraph.h b/Source/UnrealEnginePython/Private/Blueprint/UEPyEdGraph.h index 03061426b..e0fd0fe69 100644 --- a/Source/UnrealEnginePython/Private/Blueprint/UEPyEdGraph.h +++ b/Source/UnrealEnginePython/Private/Blueprint/UEPyEdGraph.h @@ -16,6 +16,9 @@ PyObject *py_ue_graph_add_node(ue_PyUObject *, PyObject *); PyObject *py_ue_graph_add_node_dynamic_cast(ue_PyUObject *, PyObject *); PyObject *py_ue_graph_add_node_event(ue_PyUObject *, PyObject *); +PyObject *py_ue_graph_reconstruct_node(ue_PyUObject *, PyObject *); +PyObject *py_ue_graph_remove_node(ue_PyUObject *, PyObject *); + PyObject *py_ue_graph_get_good_place_for_new_node(ue_PyUObject *, PyObject *); PyObject *py_ue_node_pins(ue_PyUObject *, PyObject *); diff --git a/Source/UnrealEnginePython/Private/UEPyModule.cpp b/Source/UnrealEnginePython/Private/UEPyModule.cpp index 993828a86..66aab749b 100644 --- a/Source/UnrealEnginePython/Private/UEPyModule.cpp +++ b/Source/UnrealEnginePython/Private/UEPyModule.cpp @@ -664,6 +664,9 @@ static PyMethodDef ue_PyUObject_methods[] = { { "graph_add_node_event", (PyCFunction)py_ue_graph_add_node_event, METH_VARARGS, "" }, { "graph_get_good_place_for_new_node", (PyCFunction)py_ue_graph_get_good_place_for_new_node, METH_VARARGS, "" }, + { "graph_reconstruct_node", (PyCFunction)py_ue_graph_reconstruct_node, METH_VARARGS, "" }, + { "graph_remove_node", (PyCFunction)py_ue_graph_remove_node, METH_VARARGS, "" }, + { "node_pins", (PyCFunction)py_ue_node_pins, METH_VARARGS, "" }, { "node_get_title", (PyCFunction)py_ue_node_get_title, METH_VARARGS, "" }, { "node_find_pin", (PyCFunction)py_ue_node_find_pin, METH_VARARGS, "" },