diff --git a/src/Mod/Mesh/App/MeshPyImp.cpp b/src/Mod/Mesh/App/MeshPyImp.cpp index 4172e471c..a2dde83b3 100644 --- a/src/Mod/Mesh/App/MeshPyImp.cpp +++ b/src/Mod/Mesh/App/MeshPyImp.cpp @@ -1473,28 +1473,25 @@ PyObject* MeshPy::collapseFacets(PyObject *args) return 0; // NULL triggers exception // if no mesh is given - if (PyList_Check(pcObj)) { + try { + Py::Sequence list(pcObj); std::vector facets; - for (int i = 0; i < PyList_Size(pcObj); i++) { - PyObject *idx = PyList_GetItem(pcObj, i); + for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { #if PY_MAJOR_VERSION >= 3 - if (PyLong_Check(idx)){ - unsigned long iIdx = PyLong_AsLong(idx); + Py::Long idx(*it); + unsigned long iIdx = static_cast(idx); + facets.push_back(iIdx); #else - if (PyInt_Check(idx)){ - unsigned long iIdx = PyInt_AsLong(idx); + Py::Int idx(*it); + unsigned long iIdx = static_cast(idx); + facets.push_back(iIdx); #endif - facets.push_back(iIdx); - } - else { - Py_Error(Base::BaseExceptionFreeCADError, "list of integers needed"); - } } getMeshObjectPtr()->collapseFacets(facets); } - else { - Py_Error(Base::BaseExceptionFreeCADError, "List of Integers needed"); + catch (const Py::Exception&) { + return 0; } Py_Return; diff --git a/src/Mod/Mesh/App/MeshTestsApp.py b/src/Mod/Mesh/App/MeshTestsApp.py index d4834d27f..ee9a845fd 100644 --- a/src/Mod/Mesh/App/MeshTestsApp.py +++ b/src/Mod/Mesh/App/MeshTestsApp.py @@ -1,7 +1,12 @@ # (c) Juergen Riegel (juergen.riegel@web.de) 2007 LGPL import FreeCAD, os, sys, unittest, Mesh -import thread, time, tempfile, math +import time, tempfile, math +# http://python-kurs.eu/threads.php +try: + import _thread as thread +except: + import thread #---------------------------------------------------------------------------