135 lines
6.8 KiB
HTML
135 lines
6.8 KiB
HTML
<html><head><title>Macro EdgesToArc/fr</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><link type='text/css' href='wiki.css' rel='stylesheet'></head><body><h1>Macro EdgesToArc/fr</h1></div>
|
|
|
|
<div id="mw-content-text" lang="fr" dir="ltr" class="mw-content-ltr"><hr/><div class="mw-parser-output"><table class="fcinfobox wikitable ct" width="100%" style="float: right; width: 230px; margin-left: 10px;">
|
|
<tr>
|
|
<td class="ctTitle">
|
|
<h3><span class="mw-headline" id="EdgesToArc"><a href="https://www.freecadweb.org/wiki/index.php?title=File:Text-x-python.png" class="image"><img alt="Text-x-python.png" src="32px-Text-x-python.png" width="32" height="32" srcset="/wiki/images/2/2c/Text-x-python.png 1.5x" /></a> EdgesToArc</span></h3>
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">Description
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctEven left">Transforme les arêtes sélectionnées si possible en un Arc circulaire. Utile pour restaurer des arcs discrétisés.
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">Auteur
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctEven"><a href="https://www.freecadweb.org/wiki/index.php?title=User:Jreinhardt&action=edit&redlink=1" class="new" title="User:Jreinhardt (page does not exist)">Jreinhardt</a>
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">Liens
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctEven"><a href="https://www.freecadweb.org/wiki/index.php?title=Macros_recipes/fr" title="Macros recipes/fr">Recettes macros</a><br /><a href="https://www.freecadweb.org/wiki/index.php?title=How_to_install_macros/fr" title="How to install macros/fr">Comment installer une macro</a><br /><a href="https://www.freecadweb.org/wiki/index.php?title=Customize_Toolbars/fr" title="Customize Toolbars/fr">Comment ajouter une barre d'outils</a>
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">Version
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctEven macro-version">1.0
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">Date dernière modification
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctEven macro-date">2014-01-02
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctToc"><br /><div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
|
|
<ul>
|
|
<li class="toclevel-1"><a href="#EdgesToArc"><span class="tocnumber">1</span> <span class="toctext">EdgesToArc</span></a></li>
|
|
</ul>
|
|
</div>
|
|
|
|
</td></tr>
|
|
</table>
|
|
<p><br />
|
|
</p><p>Parfois, on rencontre des fils qui contiennent des arcs composés de petits segments de droites. Cela se produit souvent lorsque vous travaillez avec des fichiers provenant d'autres programmes. Cette macro permet de reconvertir relativement facilement ces arcs "discrétisés" en arcs circulaires. Cela réduit la taille du fichier et rend sa gestion plus facile.
|
|
</p><p>Pour utiliser cette macro, vous devez briser le fil en bords individuels à l'aide de la fonction <span style="background: #DDDDDD; border: 1px solid #888888; padding: 0px 5px 1px 5px;"><a href="https://www.freecadweb.org/wiki/index.php?title=File:Draft_Downgrade.png" class="image"><img alt="Draft Downgrade.png" src="16px-Draft_Downgrade.png" width="16" height="16" srcset="/wiki/images/thumb/8/86/Draft_Downgrade.png/24px-Draft_Downgrade.png 1.5x, /wiki/images/thumb/8/86/Draft_Downgrade.png/32px-Draft_Downgrade.png 2x" /></a> <a href="https://www.freecadweb.org/wiki/index.php?title=Draft_Downgrade/fr" title="Draft Downgrade/fr">Draft Downgrade</a></span>. Ensuite il suffit de sélectionner les segments que vous voulez convertir en arc circulaire et exécuter la macro. Vous avez besoin d'au moins deux segments pour exécuter la fonction.
|
|
</p><p>La macro va vérifier si les segments se situent tous sur un cercle commun (segments contigus) et s'arrêtera si ce n'est pas le cas. Sinon, un arc sera créé et les segments enlevés.
|
|
</p><p>En raison de petites erreurs dans les calculs, de la fonction <span style="background: #DDDDDD; border: 1px solid #888888; padding: 0px 5px 1px 5px;"><a href="https://www.freecadweb.org/wiki/index.php?title=File:Draft_Upgrade.png" class="image"><img alt="Draft Upgrade.png" src="16px-Draft_Upgrade.png" width="16" height="16" srcset="/wiki/images/thumb/b/be/Draft_Upgrade.png/24px-Draft_Upgrade.png 1.5x, /wiki/images/thumb/b/be/Draft_Upgrade.png/32px-Draft_Upgrade.png 2x" /></a> <a href="https://www.freecadweb.org/wiki/index.php?title=Draft_Upgrade/fr" title="Draft Upgrade/fr">Draft Upgrade</a></span> la macro peut parfois ne pas de reconstituer toutes les arêtes et arcs. Dans ce cas, la macro <a href="https://www.freecadweb.org/wiki/index.php?title=Macro_SuperWire/fr" title="Macro SuperWire/fr">Macro_SuperWire</a> offre un moyen plus robuste pour le faire.
|
|
</p><p><br />
|
|
</p>
|
|
<pre>import Draft
|
|
import FreeCADGui, FreeCAD
|
|
from FreeCAD import Base, Console
|
|
from math import atan2, pi, fabs
|
|
|
|
#This macro replaces a number of edges approximating a circular arc by a proper circular arc.
|
|
#It might be necessary to use the superwire macro to recombine the edges back to a wire, because of small errors in the calculations.
|
|
|
|
sel = FreeCADGui.Selection.getSelection()
|
|
if len(sel) < 2:
|
|
Console.PrintError("Too few edges are selected\n")
|
|
edges = [s.Shape for s in sel]
|
|
|
|
start_vertices = []
|
|
end_vertices = []
|
|
for edge in edges:
|
|
start_vertices.append(edge.Vertexes[0].Point)
|
|
end_vertices.append(edge.Vertexes[1].Point)
|
|
vertices = start_vertices + end_vertices
|
|
|
|
start,end,middle = None,None,None
|
|
|
|
#find start and end points
|
|
for edge in edges:
|
|
is_start = True
|
|
is_end = True
|
|
for point in end_vertices:
|
|
if edge.Vertexes[0].Point.distanceToPoint(point) < 1e-8:
|
|
is_start = False
|
|
|
|
for point in start_vertices:
|
|
if edge.Vertexes[1].Point.distanceToPoint(point) < 1e-8:
|
|
is_end = False
|
|
if is_start:
|
|
start = edge.Vertexes[0].Point
|
|
if is_end:
|
|
end = edge.Vertexes[1].Point
|
|
|
|
#find middle point, at least not too far away from the middle
|
|
|
|
for v in vertices:
|
|
ratio = v.distanceToPoint(start)/v.distanceToPoint(end)
|
|
if ratio > 0.5 and ratio < 2.:
|
|
middle = v
|
|
break
|
|
|
|
if middle is None:
|
|
Console.PrintError("Could not find suitable middle point\n")
|
|
|
|
arc = Part.ArcOfCircle(start,middle,end)
|
|
|
|
#Check circularity
|
|
circular = True
|
|
for v in vertices:
|
|
if fabs(v.distanceToPoint(arc.Center) - arc.Radius) > 1e-6:
|
|
Console.PrintError("Edges do not approximate a circular arc\n")
|
|
circular = False
|
|
break
|
|
|
|
if circular:
|
|
Part.show(arc.toShape())
|
|
for shape in sel:
|
|
FreeCAD.ActiveDocument.removeObject(shape.Name) </pre>
|
|
<div style="clear:both"></div>
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div><div class="printfooter">
|
|
Online version: "<a dir="ltr" href="https://www.freecadweb.org/wiki/index.php?title=Macro_EdgesToArc/fr&oldid=240412">http://www.freecadweb.org/wiki/index.php?title=Macro_EdgesToArc/fr&oldid=240412</a>"</div>
|
|
<div id="catlinks" class="catlinks" data-mw="interface"></div><div class="visualClear"></div>
|
|
</div>
|
|
</div>
|
|
<div id="mw-navigation">
|
|
<h2>Navigation menu</h2>
|
|
|
|
</body></html> |