From 2bfc6301bc80c0344cbf13dbfe041fbd78cac93d Mon Sep 17 00:00:00 2001 From: mwganson Date: Sat, 18 Jul 2020 18:40:59 -0500 Subject: [PATCH] [Sketcher] add python command sketch.getGeoVertexIndex(int index) -- returns tuple (geoId, posId) of vertex at that index in the sketch. usage example: (geoId, posId) = App.ActiveDocument.Sketch.getGeoVertexIndex(int(Gui.Selection.getSelectionEx()[0].SubElementNames[0][6:])-1) --- src/Mod/Sketcher/App/SketchObjectPy.xml | 7 +++++++ src/Mod/Sketcher/App/SketchObjectPyImp.cpp | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Mod/Sketcher/App/SketchObjectPy.xml b/src/Mod/Sketcher/App/SketchObjectPy.xml index 451cc6160b..0082e13a0d 100644 --- a/src/Mod/Sketcher/App/SketchObjectPy.xml +++ b/src/Mod/Sketcher/App/SketchObjectPy.xml @@ -178,6 +178,13 @@ If there is no such constraint an exception is raised. + + + + (geoId, posId) = getGeoVertexIndex(index) - retrieve the GeoId and PosId of a point in the sketch + + + diff --git a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp index bdac073e1b..2736fdd9ea 100644 --- a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp +++ b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp @@ -941,6 +941,22 @@ PyObject* SketchObjectPy::movePoint(PyObject *args) } +PyObject* SketchObjectPy::getGeoVertexIndex(PyObject *args) +{ + int index; + if (!PyArg_ParseTuple(args, "i", &index)) + return 0; + + SketchObject* obj = this->getSketchObjectPtr(); + int geoId; + PointPos posId; + obj->getGeoVertexIndex(index, geoId, posId); + Py::Tuple tuple(2); + tuple.setItem(0, Py::Long(geoId)); + tuple.setItem(1, Py::Long(posId)); + return Py::new_reference_to(tuple); +} + PyObject* SketchObjectPy::getPoint(PyObject *args) { int GeoId, PointType;