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()?
Need some help about Part.makeRevolution(Curve)
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
-
- Posts: 162
- Joined: Wed Feb 01, 2012 3:29 am
Re: Need some help about Part.makeRevolution(Curve)
Try doing it from the Gui while recording a macro...
The resultant script should give you some clues.
The resultant script should give you some clues.
Re: Need some help about Part.makeRevolution(Curve)
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.jonasthomas wrote:Try doing it from the Gui while recording a macro...
The resultant script should give you some clues.
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.
Re: Need some help about Part.makeRevolution(Curve)
You are right! This is a strong limitation and must be extended to shapes.but the Part.makeRevolution() only accepts Curve as its parameter.
Re: Need some help about Part.makeRevolution(Curve)
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.You are right! This is a strong limitation and must be extended to shapes.
This is not necessary when using revolve().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?
A valid sketch must always be a list of closed wire. Here is a way how you can do it: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,
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)
Re: Need some help about Part.makeRevolution(Curve)
It works! Thanks for your help!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)