I don't see why not. It currently returns Py::None, but that could easily be the python object. Here is the current code:
Code: Select all
Py::Object show(const Py::Tuple& args)
{
PyObject *pcObj = 0;
char *name = "Shape";
if (!PyArg_ParseTuple(args.ptr(), "O!|s", &(TopoShapePy::Type), &pcObj, &name))
throw Py::Exception();
App::Document *pcDoc = App::GetApplication().getActiveDocument();
if (!pcDoc)
pcDoc = App::GetApplication().newDocument();
TopoShapePy* pShape = static_cast<TopoShapePy*>(pcObj);
Part::Feature *pcFeature = static_cast<Part::Feature*>(pcDoc->addObject("Part::Feature", name));
// copy the data
pcFeature->Shape.setValue(pShape->getTopoShapePtr()->getShape());
pcDoc->recompute();
return Py::None();
}
I think if the last line was:
it would work, but I need to compile and test it.
I think also to modernize the first line should be:
Edit: this seems to work:
Code: Select all
return Py::Object(pcFeature->getPyObject());
Edit #2. I guess this should be:
Code: Select all
return Py::asObject(pcFeature->getPyObject());
to avoid a memory leak.