Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions Source/UnrealEnginePython/Private/Blueprint/UEPyEdGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<UEdGraph>(self);
if (!graph)
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraph");

UObject *u_obj = ue_py_check_type<UObject>(py_node_class);
if (!u_obj)
return PyErr_Format(PyExc_Exception, "argument is not a UObject");

UEdGraphNode *node = nullptr;

if (UClass *u_class = Cast<UClass>(u_obj))
{
if (!u_class->IsChildOf<UEdGraphNode>())
{
return PyErr_Format(PyExc_Exception, "argument is not a child of UEdGraphNode");
}
node = NewObject<UEdGraphNode>(graph, u_class);
node->PostLoad();
}
else
{
node = Cast<UEdGraphNode>(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<UBlueprint>(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<UEdGraph>(self);
if (!graph)
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraph");

UObject *u_obj = ue_py_check_type<UObject>(py_node_class);
if (!u_obj)
return PyErr_Format(PyExc_Exception, "argument is not a UObject");

UEdGraphNode *node = nullptr;

if (UClass *u_class = Cast<UClass>(u_obj))
{
if (!u_class->IsChildOf<UEdGraphNode>())
{
return PyErr_Format(PyExc_Exception, "argument is not a child of UEdGraphNode");
}
node = NewObject<UEdGraphNode>(graph, u_class);
node->PostLoad();
}
else
{
node = Cast<UEdGraphNode>(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<UBlueprint>(node->GetGraph()->GetOuter()))
{
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(bp);
}

Py_RETURN_NONE;
}

PyObject *py_ue_graph_add_node_dynamic_cast(ue_PyUObject * self, PyObject * args)
{

Expand Down
3 changes: 3 additions & 0 deletions Source/UnrealEnginePython/Private/Blueprint/UEPyEdGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down
3 changes: 3 additions & 0 deletions Source/UnrealEnginePython/Private/UEPyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, "" },
Expand Down