Code: Select all
obj = FreeCADGui.Selection.getSelection()[0]
shp = obj.Shape
center = shp.BoundBox.Center
m = FreeCAD.Matrix()
m.move(center * -1)
movedShape = shp.transformGeometry(m)
new_obj = App.ActiveDocument.addObject('Part::Feature', obj.Name)
new_obj.Shape = movedShape
Using the GUI sketch move tool does not center it to the origin but rather makes it start from it.
It may not seem essential to do this kind of manual centering since a constraint would assist anyway but it would ease a number of cases.