I wrote a really small macro that enables to move subobjects of any shape
It's really simple and have lots of limitation, but... it's funny
It parses the object geometry, understand which faces and edges have been selected, and recreates the ones that have to be modified.
Code: Select all
import Part
#Shape.ShapeType
vector = App.Vector(0,0,2)
def was_face_selected(face, selected_vertexes):
for v in face.Vertexes:
if was_vertex_selected(v, selected_vertexes):
return True
return False
def was_edge_selected(edge, selected_vertexes):
for v in edge.Vertexes:
if was_vertex_selected(v, selected_vertexes):
return True
return False
def was_vertex_selected(v, selected_vertexes):
for sv in selected_vertexes:
if v.X == sv.X and v.Y == sv.Y and v.Z == sv.Z:
return True
return False
def move_subshapes(vector):
sel=Gui.Selection.getSelectionEx()
objects={}
for s in sel:
if not s.Object.Name in objects:
objects[s.Object.Name]=[]
if s.SubObjects:
objects[s.Object.Name].extend(s.SubObjects)
for name in objects: # for each object
# collect all selected vertexes
selected_vertexes=[]
for se in objects[name]:
selected_vertexes.extend(se.Vertexes)
print(selected_vertexes)
# get the object and its shape
obj = App.ActiveDocument.getObject(name)
shape = obj.Shape.copy()
# check which face contains selected vertexes
selected_faces = []
non_selected_faces = []
i=1
for face in shape.Faces: # for every face
if was_face_selected(face, selected_vertexes):
selected_faces.append(str(i))
else:
non_selected_faces.append(face)
i += 1
print(selected_faces)
print(non_selected_faces)
new_faces = []
# obtain new faces from selected ones
for face_index in selected_faces:
face = obj.getSubObject("Face"+ face_index)
# check which edge has been touched
i=1
new_edges = []
for edge in face.OuterWire.Edges:
if edge.Curve.TypeId != 'Part::GeomLine':
print("command works only with straight edges")
return
if was_edge_selected(edge, selected_vertexes):
print("Face"+ face_index + " Touched edge index: "+ str(i) )
new_edge_vertexes = []
for v in edge.Vertexes:
if was_vertex_selected(v, selected_vertexes):
new_edge_vertexes.append((v.X + vector.x, v.Y + vector.y, v.Z + vector.z))
# to be added with the translation vector
else:
new_edge_vertexes.append((v.X, v.Y, v.Z))
e = Part.makeLine(new_edge_vertexes[0], new_edge_vertexes[1])
new_edges.append(e)
else:
print("Face"+ face_index + " Non touched edge index: "+ str(i) )
new_edges.append(edge)
i += 1
# create the new face
w = Part.Wire(new_edges)
f = Part.Face(w)
new_faces.append(f)
#Part.show(f)
new_faces.extend(non_selected_faces)
shell = Part.makeShell(new_faces)
solid = Part.makeSolid(shell)
Part.show(solid)
disp = App.Vector(10,0,0)
move_subshapes(disp)