diff --git a/src/Mod/Sketcher/App/SketchObjectPy.xml b/src/Mod/Sketcher/App/SketchObjectPy.xml
index 9314b262ff..5554dc1c0f 100644
--- a/src/Mod/Sketcher/App/SketchObjectPy.xml
+++ b/src/Mod/Sketcher/App/SketchObjectPy.xml
@@ -419,7 +419,13 @@ If there is no such constraint an exception is raised.
-
+
+
+
+ Prints the commands that should be executed to recreate the Geometry and Constraints of the present sketch (excluding any External Geometry).
+
+
+
diff --git a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp
index c9628e54e1..4151b5a422 100644
--- a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp
+++ b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp
@@ -36,6 +36,8 @@
#include
#include
+#include "PythonConverter.h"
+
// inclusion of the generated files (generated out of SketchObjectSFPy.xml)
#include "SketchObjectPy.h"
@@ -1766,6 +1768,40 @@ PyObject* SketchObjectPy::autoRemoveRedundants(PyObject* args)
Py_Return;
}
+PyObject* SketchObjectPy::toPythonCommands(PyObject* args)
+{
+ if (!PyArg_ParseTuple(args, ""))
+ return nullptr;
+
+ auto sketch = this->getSketchObjectPtr();
+
+ std::string geometry = PythonConverter::convert("ActiveSketch", sketch->Geometry.getValues());
+ std::string constraints =
+ PythonConverter::convert("ActiveSketch", sketch->Constraints.getValues());
+
+ auto geometrymulti = PythonConverter::multiLine(std::move(geometry));
+ auto constraintmulti = PythonConverter::multiLine(std::move(constraints));
+
+ size_t numelements = geometrymulti.size() + constraintmulti.size();
+
+ Py::Tuple tuple(numelements);
+
+ std::size_t i = 0;
+
+ for (const auto& str : geometrymulti) {
+ tuple.setItem(i, Py::String(str));
+ i++;
+ }
+
+ for (const auto& str : constraintmulti) {
+ tuple.setItem(i, Py::String(str));
+ i++;
+ }
+
+ return Py::new_reference_to(tuple);
+}
+
+
Py::List SketchObjectPy::getMissingPointOnPointConstraints() const
{
std::vector constraints =