Part Fillet in python
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Part Fillet in python
How to script the Part Fillet in python?
PartFillet --> http://www.freecadweb.org/wiki/index.ph ... art_Fillet --> no python scripting example
PartDesignFillet --> http://www.freecadweb.org/wiki/index.ph ... ign_Fillet --> python scripting example
Bernd
PartFillet --> http://www.freecadweb.org/wiki/index.ph ... art_Fillet --> no python scripting example
PartDesignFillet --> http://www.freecadweb.org/wiki/index.ph ... ign_Fillet --> python scripting example
Bernd
Re: Part Fillet in python
Part and PartDesign GUI commands produce parametric Objects. The Python code in the wiki, creates a nonparametric Object.bernd wrote:How to script the Part Fillet in python?
PartFillet --> http://www.freecadweb.org/wiki/index.ph ... art_Fillet --> no python scripting example
PartDesignFillet --> http://www.freecadweb.org/wiki/index.ph ... ign_Fillet --> python scripting example
Bernd
Re: Part Fillet in python
Ok it ist what I need, but I have problems to find the edge I would like to fillet, ...shoogen wrote:Part and PartDesign GUI commands produce parametric Objects. The Python code in the wiki, creates a nonparametric Object.
I'm trying to make a i-beam for BOLTS of jreinhardt. I stick with makeing the fillet of an ibeam in python. The problem ist to find the right edges.
Code: Select all
from FreeCAD import Vector
from Part import makeBox
import Part
import PartDesign
h=270
b=248
tf=32
tw=18
r=21
l=1000
box1 = makeBox(b,tf,l)
box1.translate(Vector(0,(h-tf),0))
box2 = makeBox(b,tf,l)
box3 = makeBox(tw,(h-2*tf),l)
box3.translate(Vector((b/2),tf,0))
beam = box1.fuse(box2).fuse(box3)
Part.show(beam)
Re: Part Fillet in python
There are basically two ways.
1. You can look up look the edge indices in the GUI and hope that when the script runs again, they the edges will have the same order. This might work for yourself, but as soon as you upgrade the OCCT version you will have to test your script again. And you should definitely not distribute a scritp using such assumption.
2. You can try to find the edge using geometric properties. In which axis does it expand? Does it have a certain length? and so on. I think danielfalk has done it this way in the past.
3. Sometime in the future there should be the possibility to name edges.
1. You can look up look the edge indices in the GUI and hope that when the script runs again, they the edges will have the same order. This might work for yourself, but as soon as you upgrade the OCCT version you will have to test your script again. And you should definitely not distribute a scritp using such assumption.
2. You can try to find the edge using geometric properties. In which axis does it expand? Does it have a certain length? and so on. I think danielfalk has done it this way in the past.
3. Sometime in the future there should be the possibility to name edges.
Re: Part Fillet in python
Thanks shoogen for the fast answer. Attached is a file which shows what I would like to archive.
I tried the first one allready. If the script is used the nr. are 6, 17, 23, 33 but I am not able to do the fillets using python. But as you mentioned this should not be done in a distributed script.
bernd
I tried the first one allready. If the script is used the nr. are 6, 17, 23, 33 but I am not able to do the fillets using python. But as you mentioned this should not be done in a distributed script.
bernd
- Attachments
-
- screen.jpg (21.15 KiB) Viewed 4602 times
-
- hem240_with_fillets.fcstd
- (7.61 KiB) Downloaded 139 times
Re: Part Fillet in python
Int the Gui the edges are counted starting from one, but indexing in python starts at zero.
The lines seem to be easy to identify they are in the direction of the length of the beam.And they are pretty close to the center, compared to the ones that don't have to get filleted.
But maybe it makes more sense to create your beam by extruding a profile rather than filleting an object. This way you could insert arcs instead of line segments.
The lines seem to be easy to identify they are in the direction of the length of the beam.And they are pretty close to the center, compared to the ones that don't have to get filleted.
But maybe it makes more sense to create your beam by extruding a profile rather than filleting an object. This way you could insert arcs instead of line segments.
Re: Part Fillet in python
If i would have done the Topological Data Scripting Translation already as I mentioned on German Forum a while ago, I may would not have problems creating the beam ...
I still have problems to create the fillets ... They do not show up ...
But
The cicles are on the right place, they are just not included in the shape
EDIT
If I use the GUI tool, Draft upgrade on all created shaps I am able to create a wire and thus a face which can be extruded.
I still have problems to create the fillets ... They do not show up ...
Code: Select all
from FreeCAD import Vector
from Part import Line
from Part import makeCircle
import Part
h=270
b=248
tf=32
tw=18
r=21
l=1000
LF1 = Line( Vector(-b/2,-h/2,0), Vector(b/2,-h/2,0))
LF2 = Line( Vector(b/2,-h/2,0), Vector(b/2,(-h/2+tf),0))
LF3 = Line( Vector(b/2,(-h/2+tf),0), Vector((tw/2+r),(-h/2+tf),0))
LF4 = Line( Vector((-tw/2-r),(-h/2+tf),0), Vector(-b/2,(-h/2+tf),0))
LF5 = Line( Vector(-b/2,(-h/2+tf),0), Vector(-b/2,-h/2,0))
UF1 = Line( Vector(-b/2,h/2,0), Vector(b/2,h/2,0))
UF2 = Line( Vector(b/2,h/2,0), Vector(b/2,(h/2-tf),0))
UF3 = Line( Vector(b/2,(h/2-tf),0), Vector((tw/2+r),(h/2-tf),0))
UF4 = Line( Vector((-tw/2-r),(h/2-tf),0), Vector(-b/2,h/2-tf,0))
UF5 = Line( Vector(-b/2,(h/2-tf),0), Vector(-b/2,h/2,0))
W1 = Line( Vector(-tw/2,(-h/2+tf+r),0), Vector(-tw/2,(h/2-tf-r),0))
W2 = Line( Vector(tw/2,(-h/2+tf+r),0), Vector(tw/2,(h/2-tf-r),0))
R1 = makeCircle(r, Vector((-tw/2-r),(h/2-tf-r),0), Vector(0,0,1), 0, 90)
R2 = makeCircle(r, Vector((tw/2+r),(h/2-tf-r),0), Vector(0,0,1), 90, 180)
R3 = makeCircle(r, Vector((-tw/2-r),(-h/2+tf+r),0), Vector(0,0,1), 270, 0)
R4 = makeCircle(r, Vector((tw/2+r),(-h/2+tf+r),0), Vector(0,0,1), 180,270)
S = Part.Shape([LF1, LF2, LF3, LF4, LF5, UF1, UF2, UF3, UF4, UF5, W1, W2, R1, R2, R3, R4])
Part.show(S)
Code: Select all
Part.show(R1)
Part.show(R2)
Part.show(R3)
Part.show(R4)
EDIT
If I use the GUI tool, Draft upgrade on all created shaps I am able to create a wire and thus a face which can be extruded.
Last edited by bernd on Mon Feb 10, 2014 11:13 pm, edited 2 times in total.
Re: Part Fillet in python
I'm gone miss something with the
As soon as I use one of these I'm not able to create a face which I could extrude.
I tried to use the Draft Workbench to create the ibeam as wellIt fails at the last command, but using the GUI tool Draft.upgrade a face is created for shape of wbeam ?!?
The ibeam seams an easy task, but its just to hard for myself ...
Code: Select all
Part.makeCircle
Draft.makeCircle
I tried to use the Draft Workbench to create the ibeam as well
Code: Select all
from FreeCAD import Vector
import Draft
h=270
b=248
tf=32
tw=18
r=21
l=1000
PLF = [Vector((-tw/2-r),(-h/2+tf),0),
Vector(-b/2,(-h/2+tf),0),
Vector(-b/2,-h/2,0),
Vector(b/2,-h/2,0),
Vector(b/2,(-h/2+tf),0),
Vector((tw/2+r),(-h/2+tf),0)]
PUF = [Vector(tw/2+r,(h/2-tf),0),
Vector(b/2,(h/2-tf),0),
Vector(b/2,h/2,0),
Vector(-b/2,h/2,0),
Vector(-b/2,(h/2-tf),0),
Vector((-tw/2-r),(h/2-tf),0)]
LF = Draft.makeWire(PLF)
UF = Draft.makeWire(PUF)
WL = Draft.makeLine(Vector(-tw/2,(-h/2+tf+r),0), Vector(-tw/2,(h/2-tf-r),0))
WR = Draft.makeLine(Vector(tw/2,(-h/2+tf+r),0), Vector(tw/2,(h/2-tf-r),0))
pl=FreeCAD.Placement()
pl.Base = Vector((-tw/2-r),(h/2-tf-r))
R1 = Draft.makeCircle(r,placement=pl,startangle=0,endangle=90)
pl.Base = Vector((tw/2+r),(h/2-tf-r))
R2 = Draft.makeCircle(r,placement=pl,startangle=90,endangle=180)
pl.Base = Vector((-tw/2-r),(-h/2+tf+r),0)
R3 = Draft.makeCircle(r,placement=pl,startangle=270,endangle=0)
pl.Base = Vector((tw/2+r),(-h/2+tf+r),0)
R4 = Draft.makeCircle(r,placement=pl,startangle=180,endangle=270)
wbeam = Draft.upgrade([LF, UF, WL, WR, R1, R2, R3, R4], delete=True)
fbeam = Draft.upgrade([wbeam], delete=True)
The ibeam seams an easy task, but its just to hard for myself ...
-
- Posts: 329
- Joined: Mon Sep 09, 2013 6:08 pm
Re: Part Fillet in python
I did not look into this in detail, but I made an obervation that could be related to the problem:
Part.Line gives a object of type <type 'Part.GeomLineSegment'>, while Part.makeCircle gives <type 'Part.TopoShape'>. I could imagine that these do not mix well, but that the draft upgrade tool has conversion logic in place, which makes it work. I think makeCircle and makeLine are the ones we should use.
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 only figured the correct order and orientation out for the lower part, then I got stuck in coordinates without a piece of paper to draw.
So I guess it should look roughly like this
Part.Line gives a object of type <type 'Part.GeomLineSegment'>, while Part.makeCircle gives <type 'Part.TopoShape'>. I could imagine that these do not mix well, but that the draft upgrade tool has conversion logic in place, which makes it work. I think makeCircle and makeLine are the ones we should use.
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 only figured the correct order and orientation out for the lower part, then I got stuck in coordinates without a piece of paper to draw.
So I guess it should look roughly like this
Code: Select all
from FreeCAD import Vector
from Part import makeCircle, makeLine
import Part
h=270
b=248
tf=32
tw=18
r=21
l=1000
LF1 = makeLine( Vector(-b/2,-h/2,0), Vector(b/2,-h/2,0))
LF2 = makeLine( Vector(b/2,-h/2,0), Vector(b/2,(-h/2+tf),0))
LF3 = makeLine( Vector(b/2,(-h/2+tf),0), Vector((tw/2+r),(-h/2+tf),0))
LF4 = makeLine( Vector((-tw/2-r),(-h/2+tf),0), Vector(-b/2,(-h/2+tf),0))
LF5 = makeLine( Vector(-b/2,(-h/2+tf),0), Vector(-b/2,-h/2,0))
#make orientation consistent
LF4.reverse()
LF5.reverse()
#...
w = Part.makeWire([LF4, LF5, LF1, LF2, LF3]) # here the arcs and other edges have to be added in the right order ...
#the wire needs to be closed for that to work
#f = Part.Face(w)
#beam = f.extrude(Vector(0,0,l))
Part.show(w)
Re: Part Fillet in python
I don't know how useful this is a but an observation ...bernd wrote:It fails at the last command, but using the GUI tool Draft.upgrade a face is created for shape of wbeam ?!?
I tried your script and like you said it worked up until the last line where you try to make the wire "Draft Upgrade" into a face.
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.
Jim