Macro Solid Sweep/fr: Difference between revisions

From FreeCAD Documentation
m (Robot: Automated text replacement (-https://sourceforge.net/apps/phpbb/free-cad +http://forum.freecadweb.org))
(Updating to match new version of source page)
Line 1: Line 1:
{{Macro|Icon=Text-x-python|Name=Solid Sweep|Description=Creates a solid by sweeping a profile from a trajectory.|Author=Normandc}}
=Macro Balayage solide=


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.
{{Macro/fr|Icon=Text-x-python|Name=Balayage solide|Name/fr=Balayage solide|Description=Créé un solide en balayant un profil le long d'une trajectoire.|Author=Normandc}}


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.
Cette macro créé un solide en balayant un profil le long d'une trajectoire, les deux éléments ayant précédemment été sélectionnés dans la vue 3D. Les éléments 2D peuvent être créés à l'aide des outils existants de l'interface graphique de FreeCAD.


[[File:Solid_sweep.png‎|500px|A few examples of sweeping all using the same oblong section and three kinds of trajectory.]]
Il est à noter que le solide généré ne sera '''pas''' paramétrique. Si vous décidez de modifier le profil ou la trajectoire, vous devrez exécuter la macro à nouveau.


=== How to use ===
[[File:Solid_sweep.png‎|500px|Quelques exemples de balayages utilisant une même section oblongue et trois types de trajectoires.]]
* 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.


=== Utilisation ===
=== Supported 2D elements ===
* Wires
* [[Image:Sketcher_NewSketch.png|32px]] [[Sketcher Workbench|Sketches]]
* [[Image:Draft_BSpline.png]] [[Draft BSpline]]
* 2D primitives from the ''Parametric → Create Primitives...'' menu (circle, helix)


=== Tips ===
* Créer deux éléments 2D, un pour la section et l'autre pour la trajectoire, selon les types listés ci-dessous.
* The section has to be a closed profile or the result will not be a solid.
* Sélectionner soit dans l'arborescence de projet, soit dans la vue 3D, en premier lieu la trajectoire, et ensuite la section. Attention, l'ordre de sélection est important!
* The section does not need to be located on the trajectory, but it's preferable that it be normal (perpendicular) to the trajectory.
* Ouvrir le gestionnaire Macro, sélectionner la macro et cliquer sur « Lancer ».
* 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.
* Un objet '''Balayage''' sera créé dans l'arborescence de projet.
* 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.


=== Éléments 2D supportés ===
=== The script ===

* Filaires
* [[Image:Sketcher_NewSketch.png|32px]] [[Sketcher Workbench/fr|Esquisses]]
* [[Image:Draft_BSpline.png]] [[Draft BSpline/fr|BSplines]]
* Primitives 2D depuis le menu ''Paramétrique → Créer des primitives...'' (cercle, hélice)

=== Conseils ===

* La section doit être un profil fermé sinon la forme résultante ne sera pas solide.
* La section n'a pas besoin d'être située sur la trajectoire, mais il est préférable qu'elle lui soit normale (perpendiculaire).
* La trajectoire peut indifféremment être un profil ouvert ou fermé (cercle, ou une suite de segments de lignes et d'arcs) mais tous les éléments doivent être tangents, sinon le résultat pourrait être inattendu. Par exemple, une trajectoire avec des coins carrés comme un rectangle ne produira pas un solide.
* S'il y a un nœud dans la forme résultante, modifiez la macro et changez la valeur ''isFrenet'' à 0 (zéro), puis essayez à nouveau.
* Réglez la variable ''makeSolid'' à 0 (zéro) pour obtenir une forme non solide faite de surfaces avec des extrémités ouvertes.

=== Le script ===


<syntaxhighlight>
<syntaxhighlight>
Line 37: Line 32:
from FreeCAD import Base
from FreeCAD import Base


# prendre les objets selectionnes, avec la 1ere selection pour trajectoire et la 2eme pour la section a balayer
# pick selected objects, where 1st selection is the trajectory and the 2nd is the section to sweep
s = FreeCADGui.Selection.getSelection()
s = FreeCADGui.Selection.getSelection()
try:
try:
Line 48: Line 43:
section = Part.Wire([shape2])
section = Part.Wire([shape2])


# create a Part object into the active document
# creer un objet Balayage dans le document actif
myObject=App.ActiveDocument.addObject("Part::Feature","Balayage")
myObject=App.ActiveDocument.addObject("Part::Feature","Sweep")


# declarer la variable makeSolid pour creer un solide, changer valeur a 0 pour creer des surfaces
makeSolid = 1
makeSolid = 1
isFrenet = 1
# l'utilite de la valeur isFrenet est inconnue, changer a 0 si le resultat est bizarre
isFrenet = 0


# Create the 3D shape and set it to the Part object
# Creer la forme 3D et l'assigner a l'objet Balayage
Balayage = Part.Wire(traj).makePipeShell([section],makeSolid,isFrenet)
Sweep = Part.Wire(traj).makePipeShell([section],makeSolid,isFrenet)
myObject.Shape = Balayage
myObject.Shape = Sweep</pre>
</syntaxhighlight>
</syntaxhighlight>


=== Remerciements ===
=== Credits ===
Thanks to [[User:Wmayer|Wmayer]] for his help in writing this script.

Merci à [[User:Wmayer|Wmayer]] sans l'aide de qui je n'aurais pu rédiger ce script.


Deux exemples d'utilisation peuvent être consultés dans [http://forum.freecadweb.org/viewtopic.php?f=8&t=1222&start=50#p11120 cette discussion du forum (en anglais)], ainsi que des liens de téléchargement des fichiers FCStd. En utilisant une hélice comme trajectoire, un balayage solide peut être utilisé pour créer un filet de vis.
Two examples of uses can be found in [http://forum.freecadweb.org/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 | {{en|Macro_Solid_Sweep}} {{es|Macro_Solid_Sweep/es}} }}

Revision as of 17:05, 24 December 2013

File:Text-x-python Solid Sweep

Description
Creates a solid by sweeping a profile from a trajectory.

Author: Normandc
Author
Normandc
Download
None
Links
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.

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.
  • 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</pre>

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.

Other languages: