Forgot all about that. Sigh.
Finding the coordinate vector to subtract off the BaseFeature Placement is a case type statement
Something on these lines could be extended and bullet-proofed:
EDIT Dealt with Face and 3D selections.
I'm not sure I've covered all the cases of interest.
Code: Select all
selt = Gui.Selection.getSelectionEx()
if len(selt) != 1:
print('Select one vertex, edge or object')
else:
sel = selt[0]
if sel.HasSubObjects:
selected = sel.SubObjects[0]
if selected.ShapeType == 'Vertex':
shift = selected.Point
elif selected.ShapeType == 'Edge':
if selected.Curve.TypeId == 'Part::GeomCircle': #circles and arcs
shift = selected.Curve.Center
elif selected.Curve.TypeId == 'Part::GeomLine':
shift = (selected.valueAt(selected.FirstParameter) + selected.valueAt(selected.LastParameter))/2 # mid-point
else:
shift = App.Vector(0, 0, 0) # bail and do nothing
elif selected.ShapeType == 'Face':
shift = selected.CenterOfMass #center of face
else:
shift = App.Vector(0, 0, 0) # bail and do nothing
else:
if sel.ObjectName[0:11] == 'BaseFeature':
if sel.Object.Shape.ShapeType == 'Solid':
shift = sel.Object.Shape.CenterOfMass
elif sel.Object.Shape.ShapeType == 'Compound':
shift = sel.Object.Shape.SubShapes[0].CenterOfMass
#more cases?
else:
shift = App.Vector(0, 0, 0) # bail and do nothing
else:
shift = App.Vector(0, 0, 0) # bail and do nothing
#print(f'Shift = {shift}')
base = App.ActiveDocument.getObject(sel.ObjectName).Placement
base.move(-shift)
App.ActiveDocument.recompute()