Skip to content

Commit 32a02ef

Browse files
authored
Merge pull request #741 from flavatron/edgraph_add_func
Adding edgraph functions reconstruct_node() and remove_node()
2 parents b36a654 + bc4b791 commit 32a02ef

File tree

3 files changed

+127
-0
lines changed

3 files changed

+127
-0
lines changed

Source/UnrealEnginePython/Private/Blueprint/UEPyEdGraph.cpp

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,127 @@ PyObject *py_ue_graph_add_node(ue_PyUObject * self, PyObject * args)
381381
Py_RETURN_UOBJECT(node);
382382
}
383383

384+
PyObject *py_ue_graph_remove_node(ue_PyUObject * self, PyObject * args)
385+
{
386+
387+
ue_py_check(self);
388+
389+
PyObject *py_node_class;
390+
int x = 0;
391+
int y = 0;
392+
393+
char *metadata = nullptr;
394+
PyObject *py_data = nullptr;
395+
396+
if (!PyArg_ParseTuple(args, "O|iisO:graph_remove_node", &py_node_class, &x, &y, &metadata, &py_data))
397+
{
398+
return nullptr;
399+
}
400+
401+
UEdGraph *graph = ue_py_check_type<UEdGraph>(self);
402+
if (!graph)
403+
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraph");
404+
405+
UObject *u_obj = ue_py_check_type<UObject>(py_node_class);
406+
if (!u_obj)
407+
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
408+
409+
UEdGraphNode *node = nullptr;
410+
411+
if (UClass *u_class = Cast<UClass>(u_obj))
412+
{
413+
if (!u_class->IsChildOf<UEdGraphNode>())
414+
{
415+
return PyErr_Format(PyExc_Exception, "argument is not a child of UEdGraphNode");
416+
}
417+
node = NewObject<UEdGraphNode>(graph, u_class);
418+
node->PostLoad();
419+
}
420+
else
421+
{
422+
node = Cast<UEdGraphNode>(u_obj);
423+
if (node)
424+
{
425+
if (node->GetOuter() != graph)
426+
427+
node->Rename(*node->GetName(), graph);
428+
}
429+
}
430+
431+
if (!node)
432+
return PyErr_Format(PyExc_Exception, "argument is not a supported type");
433+
434+
graph->RemoveNode(node);
435+
436+
if (UBlueprint *bp = Cast<UBlueprint>(node->GetGraph()->GetOuter()))
437+
{
438+
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(bp);
439+
}
440+
441+
Py_RETURN_NONE;
442+
}
443+
444+
PyObject *py_ue_graph_reconstruct_node(ue_PyUObject * self, PyObject * args)
445+
{
446+
447+
ue_py_check(self);
448+
449+
PyObject *py_node_class;
450+
int x = 0;
451+
int y = 0;
452+
453+
char *metadata = nullptr;
454+
PyObject *py_data = nullptr;
455+
456+
if (!PyArg_ParseTuple(args, "O|iisO:graph_reconstruct_node", &py_node_class, &x, &y, &metadata, &py_data))
457+
{
458+
return nullptr;
459+
}
460+
461+
UEdGraph *graph = ue_py_check_type<UEdGraph>(self);
462+
if (!graph)
463+
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraph");
464+
465+
UObject *u_obj = ue_py_check_type<UObject>(py_node_class);
466+
if (!u_obj)
467+
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
468+
469+
UEdGraphNode *node = nullptr;
470+
471+
if (UClass *u_class = Cast<UClass>(u_obj))
472+
{
473+
if (!u_class->IsChildOf<UEdGraphNode>())
474+
{
475+
return PyErr_Format(PyExc_Exception, "argument is not a child of UEdGraphNode");
476+
}
477+
node = NewObject<UEdGraphNode>(graph, u_class);
478+
node->PostLoad();
479+
}
480+
else
481+
{
482+
node = Cast<UEdGraphNode>(u_obj);
483+
if (node)
484+
{
485+
if (node->GetOuter() != graph)
486+
487+
node->Rename(*node->GetName(), graph);
488+
}
489+
}
490+
491+
if (!node)
492+
return PyErr_Format(PyExc_Exception, "argument is not a supported type");
493+
494+
//graph->RemoveNode(node);
495+
node->ReconstructNode();
496+
497+
if (UBlueprint *bp = Cast<UBlueprint>(node->GetGraph()->GetOuter()))
498+
{
499+
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(bp);
500+
}
501+
502+
Py_RETURN_NONE;
503+
}
504+
384505
PyObject *py_ue_graph_add_node_dynamic_cast(ue_PyUObject * self, PyObject * args)
385506
{
386507

Source/UnrealEnginePython/Private/Blueprint/UEPyEdGraph.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ PyObject *py_ue_graph_add_node(ue_PyUObject *, PyObject *);
1616
PyObject *py_ue_graph_add_node_dynamic_cast(ue_PyUObject *, PyObject *);
1717
PyObject *py_ue_graph_add_node_event(ue_PyUObject *, PyObject *);
1818

19+
PyObject *py_ue_graph_reconstruct_node(ue_PyUObject *, PyObject *);
20+
PyObject *py_ue_graph_remove_node(ue_PyUObject *, PyObject *);
21+
1922
PyObject *py_ue_graph_get_good_place_for_new_node(ue_PyUObject *, PyObject *);
2023

2124
PyObject *py_ue_node_pins(ue_PyUObject *, PyObject *);

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,9 @@ static PyMethodDef ue_PyUObject_methods[] = {
664664
{ "graph_add_node_event", (PyCFunction)py_ue_graph_add_node_event, METH_VARARGS, "" },
665665
{ "graph_get_good_place_for_new_node", (PyCFunction)py_ue_graph_get_good_place_for_new_node, METH_VARARGS, "" },
666666

667+
{ "graph_reconstruct_node", (PyCFunction)py_ue_graph_reconstruct_node, METH_VARARGS, "" },
668+
{ "graph_remove_node", (PyCFunction)py_ue_graph_remove_node, METH_VARARGS, "" },
669+
667670
{ "node_pins", (PyCFunction)py_ue_node_pins, METH_VARARGS, "" },
668671
{ "node_get_title", (PyCFunction)py_ue_node_get_title, METH_VARARGS, "" },
669672
{ "node_find_pin", (PyCFunction)py_ue_node_find_pin, METH_VARARGS, "" },

0 commit comments

Comments
 (0)