Macro Solid Sweep: Difference between revisions
(used <pre> </pre> tags to remove unwanted spaces in the script) |
(added French translation) |
||
Line 7: | Line 7: | ||
[[File:Solid_sweep.png|500px|A few examples of sweeping all using the same oblong section and three kinds of trajectory.]] |
[[File:Solid_sweep.png|500px|A few examples of sweeping all using the same oblong section and three kinds of trajectory.]] |
||
=== How to use === |
|||
* Create two 2D elements, one for the section and one for the trajectory, of the types listed below. |
* Create two 2D elements, one for the section and one for the trajectory, of the types listed below. |
||
Line 14: | Line 14: | ||
* A '''Sweep''' object will be created in the Project tree. |
* A '''Sweep''' object will be created in the Project tree. |
||
=== Supported 2D elements === |
|||
* Wires |
* Wires |
||
* [[Image:Sketcher_NewSketch.png|32px]] [[Sketcher Workbench|Sketches]] |
* [[Image:Sketcher_NewSketch.png|32px]] [[Sketcher Workbench|Sketches]] |
||
* [[Image:Draft_BSpline.png]] [[Draft BSpline]] |
* [[Image:Draft_BSpline.png]] [[Draft BSpline]] |
||
* 2D primitives from the '' |
* 2D primitives from the ''Parametric → Create Primitives...'' menu (circle, helix) |
||
=== Tips === |
|||
* The section has to be a closed profile or the result will not be a solid. |
* The section has to be a closed profile or the result will not be a solid. |
||
Line 29: | Line 29: | ||
* Setting the ''makeSolid'' variable to 0 (zero) in the macro will produce a set of surfaces with open ends. |
* Setting the ''makeSolid'' variable to 0 (zero) in the macro will produce a set of surfaces with open ends. |
||
=== The script === |
|||
<pre>import Part, FreeCAD, math, PartGui, FreeCADGui |
<pre>import Part, FreeCAD, math, PartGui, FreeCADGui |
||
Line 55: | Line 55: | ||
myObject.Shape = Sweep</pre> |
myObject.Shape = Sweep</pre> |
||
=== Credits === |
|||
Thanks to [[User:Wmayer|Wmayer]] for his help in writing this script. |
Thanks to [[User:Wmayer|Wmayer]] for his help in writing this script. |
||
Line 61: | Line 61: | ||
Two examples of uses can be found in [https://sourceforge.net/apps/phpbb/free-cad/viewtopic.php?f=8&t=1222&start=50#p11120 this forum topic], along with download links to the FCStd files. Using a helix as trajectory, a solid sweep can be used to create a bolt thread. |
Two examples of uses can be found in [https://sourceforge.net/apps/phpbb/free-cad/viewtopic.php?f=8&t=1222&start=50#p11120 this forum topic], along with download links to the FCStd files. Using a helix as trajectory, a solid sweep can be used to create a bolt thread. |
||
{{languages | }} |
{{languages | {{fr|Macro_Solid_Sweep/fr}} }} |
Revision as of 07:54, 4 December 2011
Description |
---|
Creates a solid by sweeping a profile from a trajectory. Author: Normandc |
Author |
Normandc |
Download |
None |
Links |
Macros recipes How to install macros How to customize toolbars |
Macro Version |
1.0 |
Date last modified |
None |
FreeCAD Version(s) |
None |
Default shortcut |
None |
See also |
None |
This macro creates a solid by sweeping a 2D profile along a trajectory previously selected in the 3D view. The 2D elements can be created through the regular tools in FreeCAD's GUI.
It should be noted that the resulting solid will not be parametric. If you decide to change your profile or trajectory, you'll need to run the macro again.
How to use
- Create two 2D elements, one for the section and one for the trajectory, of the types listed below.
- Select, either in the Project tree or in the 3D view, first the trajectory, then the profile. The order is important!
- Open the Macro manager, select the macro and click "Execute".
- A Sweep object will be created in the Project tree.
Supported 2D elements
- Wires
- Sketches
- Draft BSpline
- 2D primitives from the Parametric → Create Primitives... menu (circle, helix)
Tips
- The section has to be a closed profile or the result will not be a solid.
- The section does not need to be located on the trajectory, but it's preferable that it be normal (perpendicular) to the trajectory.
- The trajectory can either be an open or closed profile (circle, or line and arc segments) but all elements need to be tangent or the resulting shape will be unexpected. For example, a trajectory with straight corners like a rectangle will not produce a solid.
- If the solid gets twisted, edit the macro to change the isFrenet value to 0 (zero) and try again.
- Setting the makeSolid variable to 0 (zero) in the macro will produce a set of surfaces with open ends.
The script
import Part, FreeCAD, math, PartGui, FreeCADGui from FreeCAD import Base # pick selected objects, where 1st selection is the trajectory and the 2nd is the section to sweep s = FreeCADGui.Selection.getSelection() try: shape1=s[0].Shape shape2=s[1].Shape except: print "Wrong selection" traj = Part.Wire([shape1]) section = Part.Wire([shape2]) # create a Part object into the active document myObject=App.ActiveDocument.addObject("Part::Feature","Sweep") makeSolid = 1 isFrenet = 1 # Create the 3D shape and set it to the Part object Sweep = Part.Wire(traj).makePipeShell([section],makeSolid,isFrenet) myObject.Shape = Sweep
Credits
Thanks to Wmayer for his help in writing this script.
Two examples of uses can be found in this forum topic, along with download links to the FCStd files. Using a helix as trajectory, a solid sweep can be used to create a bolt thread.