diff --git a/src/Mod/Sketcher/App/SketchObjectPy.xml b/src/Mod/Sketcher/App/SketchObjectPy.xml index 3972336965..717ed48e15 100644 --- a/src/Mod/Sketcher/App/SketchObjectPy.xml +++ b/src/Mod/Sketcher/App/SketchObjectPy.xml @@ -53,6 +53,11 @@ Rename a constraint of the sketch + + + copy another sketch's geometry and constraints + + add a link to an external geometry to use it in a constraint diff --git a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp index b6aa9a5529..6e73ef0b6b 100644 --- a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp +++ b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp @@ -374,6 +374,41 @@ PyObject* SketchObjectPy::renameConstraint(PyObject *args) Py_Return; } +PyObject* SketchObjectPy::carbonCopy(PyObject *args) +{ + char *ObjectName; + PyObject *construction = Py_True; + if (!PyArg_ParseTuple(args, "s|O!:Give an object", &ObjectName, &PyBool_Type, &construction)) + return 0; + + Sketcher::SketchObject* skObj = this->getSketchObjectPtr(); + App::DocumentObject * Obj = skObj->getDocument()->getObject(ObjectName); + + if (!Obj) { + std::stringstream str; + str << ObjectName << " does not exist in the document"; + PyErr_SetString(PyExc_ValueError, str.str().c_str()); + return 0; + } + // check if this type of external geometry is allowed + if (!skObj->isExternalAllowed(Obj->getDocument(), Obj) && (Obj->getTypeId() != Sketcher::SketchObject::getClassTypeId())) { + std::stringstream str; + str << ObjectName << " is not allowed for a carbon copy operation in this sketch"; + PyErr_SetString(PyExc_ValueError, str.str().c_str()); + return 0; + } + + // add the external + if (skObj->carbonCopy(Obj, PyObject_IsTrue(construction) ? true : false) < 0) { + std::stringstream str; + str << "Not able to add the requested geometry"; + PyErr_SetString(PyExc_ValueError, str.str().c_str()); + return 0; + } + + Py_Return; +} + PyObject* SketchObjectPy::addExternal(PyObject *args) { char *ObjectName;