How to create a parametrized elliptical rod/cylinder?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Mr.T
Posts: 5
Joined: Thu Sep 24, 2015 6:43 pm

How to create a parametrized elliptical rod/cylinder?

Post by Mr.T »

Hi,

I am trying to create a parametrized elliptical rod/cylinder.

At the moment, I have managed to script it as follows:

Code: Select all

import FreeCAD as App
import Part
import Sketcher

doc = App.newDocument()

sketch = doc.addObject("Sketcher::SketchObject", "Sketch")

# parameters
h=5
w=2
L=10

# create object
S1=App.Vector(0, h/2, 0)
S2=App.Vector(-w/2, 0, 0)
C=App.Vector(0, 0, 0)
sketch.addGeometry(Part.Ellipse(S1, S2, C), False)

body = doc.addObject('PartDesign::Body','Body')

pad = body.newObject('PartDesign::Pad','Pad')
pad.Profile = sketch
pad.Length = L

doc.recompute()
But I would like to turn it into a parametrized object to make editing easier, by using something like this:
https://wiki.freecad.org/Scripted_objects

How can I do this?

I looked into the DistanceBolt example here, but cannot find an ellipctical replacement for makeCircle.
I would also still need to find a way to close the faces after extrusion.
jfc4120
Posts: 448
Joined: Sat Jul 02, 2022 11:16 pm

Re: How to create a parametrized elliptical rod/cylinder?

Post by jfc4120 »

See if this post helps: viewtopic.php?p=578314
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: How to create a parametrized elliptical rod/cylinder?

Post by edwilliams16 »

Code: Select all

import Part
doc = App.ActiveDocument
ell = doc.addObject("Part::Ellipse","Ellipse")
ell.MajorRadius=4.0000
ell.MinorRadius=2.0000
f = doc.addObject('Part::Extrusion','Extrude')
f.Base = ell
f.DirMode = "Normal"
f.LengthFwd = 10.0
f.LengthRev = 0.0
f.Solid = True
doc.recompute()
is one way. Create via the Part WB and look at the python console output.

EDIT
Another way, at the topological level :

Code: Select all

import Part
e1 = Part.Ellipse()
e1.MajorRadius = 4
e1.MinorRadius = 2
e1.Center = App.Vector(0,0,0)
face = Part.Face(Part.Wire(e1.toShape()))
height = 10
Part.show(face.extrude(height * App.Vector(0,0,1)),'Elliptical Cylinder')
Post Reply