__Name__ = 'Ellipse Center + 2 Points'
__Comment__ = ''
__Author__ = 'Eriossoltero'
__Version__ = ''
__Date__ = ''
__License__ = 'LGPL-2.0-or-later'
__Web__ = 'http://freecad-tutorial.blogspot.com/2011/12/engine-9-poly-v-belt.html'
__Wiki__ = ''
__Icon__ = ''
__Help__ = ''
__Status__ = ''
__Requires__ = ''
__Communication__ = ''
__Files__ = ''

import FreeCAD as app
import FreeCADGui as gui
import Part, PartGui
from FreeCAD import Base

# get the selected objects, with first selection for the trajectory and second for the section
# Adapted from:
# http://freecad-tutorial.blogspot.com/2011/12/engine-9-poly-v-belt.html
s = gui.Selection.getSelection()
try:
    sel1 = s[0].Shape
    sel2 = s[1].Shape
    sel3 = s[2].Shape
except:
    app.Console.PrintError('Wrong selection')

pt_center = sel1.Point
pt_radmay = sel2.Point
pt_radmen = sel3.Point

# create Part object in the current document
myObject = app.ActiveDocument.addObject('Part::Feature', 'Ellipse')

# create a shape and assign it to the current document
ellipse = Part.Ellipse(pt_radmay, pt_radmen, pt_center)
myObject.Shape = ellipse.toShape()
