Part Fillet in python

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
mario52
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: Part Fillet in python

Post by mario52 »

Hi bernd
I found this discussion on a script using makeFillet
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Part Fillet in python

Post by bernd »

jmaustpc wrote:But you don't need to make it a face, if you set the option to make solid "true" then Part Extrude will create a solid from the wire. ...
Thats true for the GUI extrusion and works well. Could this option be set in python as well ? It would be the easiest soulution. :)

jreinhardt wrote:From what I read on the topological data scripting page the recommended procedure is to create a wire from edges straight edges and cirles. To create a wire, the edges have to be passed to the constructor in the correct order. ...
I did not know about the correct order. I'm gone check that as well.
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Part Fillet in python

Post by bernd »

May be one of you guys could bring light in my darkness or point me to some documentation. I'm using the simple Topo example.

That one is copied for Topological Data Scripting and some nice solid is created.

Code: Select all

from FreeCAD import Vector
import Part

V1 = Vector(0,10,0)
V2 = Vector(30,10,0)
V3 = Vector(30,-10,0)
V4 = Vector(0,-10,0)
VC1 = Vector(-10,0,0)
VC2 = Vector(40,0,0)

C1 = Part.Arc(V1,VC1,V4)
C2 = Part.Arc(V2,VC2,V3)
L1 = Part.Line(V1,V2)
L2 = Part.Line(V4,V3)

S1 = Part.Shape([C1,C2,L1,L2])
W = Part.Wire(S1.Edges)
F = Part.Face(W)
P = F.extrude(Vector(0,0,10))
Part.show(P)
The following only includes one circle in the shape and therefore the wire is not closed. I checked the correct order. It should be fine?!

Code: Select all

from FreeCAD import Vector
import Part

V1 = Vector(0,10,0)
V2 = Vector(30,10,0)
V3 = Vector(30,-10,0)
V4 = Vector(0,-10,0)
VC1 = Vector(-10,0,0)
VC2 = Vector(40,0,0)

r = 10
C1 = Part.makeCircle(r, V1, V4)
C2 = Part.makeCircle(r, V3, V2)

L1 = Part.Line(V2,V1)
L2 = Part.Line(V4,V3)

S1 = Part.Shape([C1,L2,C2,L1])
W = Part.Wire(S1.Edges)
F = Part.Face(W)
P = F.extrude(Vector(0,0,10))
Part.show(P)

The draft version is a closed wire created by the upgrade tool. Again only one circle is included.

Code: Select all

from FreeCAD import Vector
import Draft

V1 = Vector(0,10,0)
V2 = Vector(30,10,0)
V3 = Vector(30,-10,0)
V4 = Vector(0,-10,0)
VC3 = Vector(0,0,0)
VC4 = Vector(30,0,0)


pl=FreeCAD.Placement()
pl.Base = VC3
C1 = Draft.makeCircle(r,placement=pl,startangle=90,endangle=270)
pl.Base = VC4
C2 = Draft.makeCircle(r,placement=pl,startangle=270,endangle=90)

L1 = Draft.makeLine(V1,V2)
L2 = Draft.makeLine(V4,V3)

W = Draft.upgrade([C1,C2,L1,L2], delete=True)
#P = W.extrude(Vector(0,0,10))     # direct extrusion of the wire misses one circle

#F = Draft.upgrade(W, delete=True) # upgrade to a face does not work
#P = F.extrude(Vector(0,0,10))
jreinhardt
Posts: 329
Joined: Mon Sep 09, 2013 6:08 pm

Re: Part Fillet in python

Post by jreinhardt »

In your second example you are mixing Line and makeCircle, which I believe is not a good idea (but I have not checked in detail). Also the signature of makeCircle is different: first the radius, then the center, then the normal of the plane in which the circle is drawn and then start and end angle.

This is a working version of the second example:

Code: Select all

from FreeCAD import Vector
import Part

V1 = Vector(0,10,0)
V2 = Vector(30,10,0)
V3 = Vector(30,-10,0)
V4 = Vector(0,-10,0)
VC1 = Vector(0,0,0)
VC2 = Vector(30,0,0)

normal = Vector(0,0,1)

r = 10
C1 = Part.makeCircle(r,VC1,normal,90,270)
C2 = Part.makeCircle(r,VC2,normal,270,90)

L1 = Part.makeLine(V1,V2)
L2 = Part.makeLine(V3,V4)

W = Part.Wire([L1,C1,L2,C2])
F = Part.Face(W)
P = F.extrude(Vector(0,0,10))
Part.show(P)
BOLTS, standard parts library for FreeCAD Thread, Help with Translation
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Part Fillet in python

Post by jmaustpc »

bernd wrote:
jmaustpc wrote:But you don't need to make it a face, if you set the option to make solid "true" then Part Extrude will create a solid from the wire. ...
Thats true for the GUI extrusion and works well. Could this option be set in python as well ? It would be the easiest soulution. :)
I ran your script up to the line that fails, (i.e. removed the failed line), then used the GUI tool to extrude, then copied the output from the Python window into the script. Then ran the script again and it worked. You will of course have to refine the script, but this shows that it works in principle. I don't know enough about the subject to offer further detailed advise.

Jim
User avatar
shoogen
Veteran
Posts: 2823
Joined: Thu Dec 01, 2011 5:24 pm

Re: Part Fillet in python

Post by shoogen »

bernd wrote:
jmaustpc wrote:But you don't need to make it a face, if you set the option to make solid "true" then Part Extrude will create a solid from the wire. ...
Thats true for the GUI extrusion and works well. Could this option be set in python as well ? It would be the easiest solution. :)
It would be easier. But i don't think that such a change would be wise. It makes sense in the GUI to tip somebody (working on feature level) that he may want to get a solid. But somebody working on shape level should really understand the shape types. Calling "Part.Face(wire)" is not that hard.
Post Reply