import math import Draft box = App.getDocument("AlignBox").getObject("Box") line = App.getDocument("AlignBox").getObject("Line") Xaxis= FreeCAD.Vector((1,0,0)) P1 = line.Shape.Vertex1.Point P2 = line.Shape.Vertex2.Point angle = Xaxis.getAngle(P2 - P1) * 180 / math.pi normal = Xaxis.cross(P2 - P1) Draft.rotate(box,-angle,P1,normal,False)