User:Eriossoltero: Difference between revisions

From FreeCAD Documentation
(ajout de "|Icon=Text-x-python")
(macro in new page "Macro_Ellipse-Center+2Points" to remove the user from the page "Category:Macros")
 
Line 1: Line 1:
[[Macro_Ellipse-Center%2B2Points]]
{{Macro|Icon=Text-x-python|Name=Ellipse-Center+2Points|Description=Makes an ellipse by selecting three points (in this order): centre, major radius and minor radius|Author=anonymous}}


<syntaxhighlight>
<pre>
# Macro Begin: Ellipse-Center+2Points.FCMacro +++++++++++++++++++++++++++++++++++++++++++++++++
# Macro Begin: Ellipse-Center+2Points.FCMacro +++++++++++++++++++++++++++++++++++++++++++++++++
# http://freecad-tutorial.blogspot.com/2011/12/engine-9-poly-v-belt.html
# http://freecad-tutorial.blogspot.com/2011/12/engine-9-poly-v-belt.html
Line 29: Line 29:
myObject.Shape = ellipse.toShape()
myObject.Shape = ellipse.toShape()
# Macro End: Ellipse-Center+2Points.FCMacro +++++++++++++++++++++++++++++++++++++++++++++++++
# Macro End: Ellipse-Center+2Points.FCMacro +++++++++++++++++++++++++++++++++++++++++++++++++
</syntaxhighlight>
</pre>

{{languages | {{fr|User:Eriossoltero/fr}} }}

Latest revision as of 14:07, 25 December 2013

Macro_Ellipse-Center+2Points

# Macro Begin: Ellipse-Center+2Points.FCMacro +++++++++++++++++++++++++++++++++++++++++++++++++
# http://freecad-tutorial.blogspot.com/2011/12/engine-9-poly-v-belt.html
import Part, FreeCAD, math, PartGui, FreeCADGui
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 = FreeCADGui.Selection.getSelection()
try:
	sel1=s[0].Shape
	sel2=s[1].Shape
	sel3=s[2].Shape
except:
	print "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()
# Macro End: Ellipse-Center+2Points.FCMacro +++++++++++++++++++++++++++++++++++++++++++++++++