Need some help about Part.makeRevolution(Curve)

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
willa8004
Posts: 12
Joined: Sat Oct 26, 2013 12:19 pm

Need some help about Part.makeRevolution(Curve)

Post by willa8004 »

Hello everyone! I'm new to FreeCAD. I have some experience of using C++ and OpenCASCADE to develop some simple 3D modeling software.

I want to write a Python script to created a parametric object, but I stucked with the Part.makeRevolution(). I want to make a revolution body from a sketch, but the Part.makeRevolution() only accepts Curve as its parameter. I have searched the API documentation, but I still have no idea about how to convert Sketch object to Curve object, and I even don't know how to create Curve object from a list of Edge objects. Does anyone have some ideas about that?

Another thing is, the revolve angle that I needed is usually smaller than 360 degree, but if the revolution is based on a sketch or a curve, I guess what I finally get will be a shell of a tube or something. What I really need is a solid, so, when I was developing with C++ and OpenCASCADE, I always call BRepPrimAPI_MakeRevol with a TopoDS_Face object builed with TopoDS_Wire, and I will get a solid instead of a shell. I'm also have to using a Face object to get a extruded solid with FreeCAD. So, how can I get a solid from Part.makeRevolution()?
jonasthomas
Posts: 162
Joined: Wed Feb 01, 2012 3:29 am

Re: Need some help about Part.makeRevolution(Curve)

Post by jonasthomas »

Try doing it from the Gui while recording a macro...
The resultant script should give you some clues.
willa8004
Posts: 12
Joined: Sat Oct 26, 2013 12:19 pm

Re: Need some help about Part.makeRevolution(Curve)

Post by willa8004 »

jonasthomas wrote:Try doing it from the Gui while recording a macro...
The resultant script should give you some clues.
Thanks for your response. I have tried this, it will give me a set of "Part::Revolution" or "PartDesign::Revolution" objects which is not what I need.

First, I want to create a custom parametric object, so I don't want to see some objects other my custom type of object. If I use addObject("PartDesign::Revolution","Revolution") or addObject("Part::Revolution","Revolution"), it will have new items in the model tree, and that is what I don't want.

Second, in fact, I really had tried this in my Python script, and I got another problem. My parametric object needs to do some boolean operation to a set of revolved shape and extruded shape. When I'm using addObject("PartDesign::Revolution","Revolution") or addObject("Part::Revolution","Revolution") in my Python modeling functions, the Shape property of the "PartDesign::Revolution" or "Part::Revolution" object will not updated until I call the FreeCAD.ActiveDocument.recompute(). But, if I call the recompute(), my modeling function will fall into a endless recursion of itself. That is because, when I call the recompute(), not only the "PartDesign::Revolution" or "Part::Revolution" object will be recompute, but my modeling functions will also be called by FreeCAD, and then, my modeling function will call recompute() again... I do have a workaround for this, but it is ugly and unsafe. So, I really need a better solution.
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Need some help about Part.makeRevolution(Curve)

Post by wmayer »

but the Part.makeRevolution() only accepts Curve as its parameter.
You are right! This is a strong limitation and must be extended to shapes.
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Need some help about Part.makeRevolution(Curve)

Post by wmayer »

You are right! This is a strong limitation and must be extended to shapes.
I had a look at the interface of BRepPrimAPI_MakeRevolution which is used in makeRevolution() and it only accepts a geometric curve but not a shape. There is the similar class BRepPrimAPI_MakeRevol (as you mentioned in the 1st post) that we use in the revolve() method of a topo shape object. So, I won't extend makeRevolution() as said before.
but I still have no idea about how to convert Sketch object to Curve object, and I even don't know how to create Curve object from a list of Edge objects. Does anyone have some ideas about that?
This is not necessary when using revolve().
Another thing is, the revolve angle that I needed is usually smaller than 360 degree, but if the revolution is based on a sketch or a curve, I guess what I finally get will be a shell of a tube or something. What I really need is a solid, so, when I was developing with C++ and OpenCASCADE,
A valid sketch must always be a list of closed wire. Here is a way how you can do it:

Code: Select all

sketch = ...
wires = sketch.Shape.Wires
# sort the wires so that the contour is the first item in the list (you can use e.g. the diagonal length of the bounding box as criterion)
...
# creates a face
face = Part.Face(wires) 
# base point of the rotation axis
pos = App.Vector(...)
# direction of the rotation axis
vec = App.Vector(...)
angle = 360
solid = face.revolve(pos, vec, angle)
Part.show(solid)
willa8004
Posts: 12
Joined: Sat Oct 26, 2013 12:19 pm

Re: Need some help about Part.makeRevolution(Curve)

Post by willa8004 »

wmayer wrote: A valid sketch must always be a list of closed wire. Here is a way how you can do it:

Code: Select all

sketch = ...
wires = sketch.Shape.Wires
# sort the wires so that the contour is the first item in the list (you can use e.g. the diagonal length of the bounding box as criterion)
...
# creates a face
face = Part.Face(wires) 
# base point of the rotation axis
pos = App.Vector(...)
# direction of the rotation axis
vec = App.Vector(...)
angle = 360
solid = face.revolve(pos, vec, angle)
Part.show(solid)
It works! Thanks for your help! :D
Post Reply