Skip to content

Instantly share code, notes, and snippets.

@thehans
Created December 1, 2011 04:06
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thehans/1413481 to your computer and use it in GitHub Desktop.
Save thehans/1413481 to your computer and use it in GitHub Desktop.
Protractor script for FreeCAD, measures angle between two edges
from FreeCAD import Base
import math
class Protractor:
"""Reports the angle between two edges.
Select the edges and the result will be shown in Report View"""
def __init__(self):
self.firstEdge = None
Gui.Selection.addObserver(self)
FreeCAD.Console.PrintMessage("Select any 2 edges\n")
def addSelection(self, doc, obj, sub, pos):
o = App.getDocument(doc).getObject(obj)
if sub != '' and type(o) == Part.Feature:
e = getattr(o.Shape, sub)
if e.ShapeType == 'Edge':
if self.firstEdge is None:
self.firstEdge = e
else:
Gui.Selection.removeObserver(self)
d1 = e.Vertexes[0].Point.sub(e.Vertexes[1].Point)
d2 = self.firstEdge.Vertexes[0].Point.sub(self.firstEdge.Vertexes[1].Point)
angle = d1.getAngle(d2)
FreeCAD.Console.PrintMessage("Angle: %f\n" % math.degrees(angle))
if __name__ == "__main__":
Protractor()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment