FreeCAD-Doc/localwiki/Macro_EdgesToArc-cs.html
2018-07-19 18:47:02 -05:00

136 lines
6.4 KiB
HTML

<html><head><title>Macro EdgesToArc/cs</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/cs</h1></div>
<div id="mw-content-text" lang="cs" 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 macro-description">Replaces the selected Edges by a circular Arc if possible. Useful for restoring discretized arcs.
</td></tr>
<tr>
<th class="ctOdd">Author
</th></tr>
<tr>
<td class="ctEven macro-author"><a href="https://www.freecadweb.org/wiki/index.php?title=User:Jreinhardt&amp;action=edit&amp;redlink=1" class="new" title="User:Jreinhardt (page does not exist)">Jreinhardt</a>
</td></tr>
<tr>
<th class="ctOdd">Links
</th></tr>
<tr>
<td class="ctEven"><a href="Macros_recipes.html" title="Macros recipes">Macros recipes</a><br /><a href="How_to_install_macros.html" title="How to install macros">How to install macros</a><br /><a href="Customize_Toolbars.html" title="Customize Toolbars">How to customize toolbars</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 last 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>Občas někdo narazí na drát (lomenou čáru), který je obsažen v oblouku vytvořeném z malých přímých segmentů. Často se to stává při práci se soubory z jiných programů. Toto makro umožňuje relativně snadno konvertovat takový oblouk složený z přímek zpět do kružnicového oblouku. Snižuje to velikost souboru a soubor to dělá mnohem snadněji zpracovatelným,
</p><p>Pro použití tohoto makra musíte rozlámat drát do jednotlivých hran použitím funkce <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="Draft_Downgrade.html" title="Draft Downgrade">Draft Downgrade</a></span>. Potom jen vyberete segmenty, které chcete nahradit kružnicovým obloukem a spustíte makro. Potřebujete minimálně 2 segmenty.
</p><p>Makro zkontroluje jestli segmenty leží na obecné kružnici a pokud ne, samo se ukončí. Jinak vytvoří oblouk a odstraní segmenty.
</p><p>Kvůli malým nepřesnostem ve výpočtu, může funkce <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="Draft_Upgrade.html" title="Draft Upgrade">Draft Upgrade</a></span> někdy skončit chybně a vrátit oblouk zpět do drátu. V takovém případě poskytne lepší výsledek mnohem robustnější makro <a href="Macro_SuperWire.html" title="Macro SuperWire">Macro_SuperWire</a>.
</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) &lt; 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) &lt; 1e-8:
is_start = False
for point in start_vertices:
if edge.Vertexes[1].Point.distanceToPoint(point) &lt; 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 &gt; 0.5 and ratio &lt; 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) &gt; 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/cs&amp;oldid=240416">http://www.freecadweb.org/wiki/index.php?title=Macro_EdgesToArc/cs&amp;oldid=240416</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>