111 lines
4.9 KiB
HTML
111 lines
4.9 KiB
HTML
<html><head><title>Macro MeshToPart/it</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 MeshToPart/it</h1></div>
|
|
|
|
<div id="mw-content-text" lang="it" 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="Da_Mesh_a_Part"><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> Da Mesh a Part</span></h3>
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">Descrizione
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctEven left">Questa macro converte gli oggetti Mesh selezionati in Parti. Ha una tolleranza ampia, quindi è da utilizzare solo con oggetti che non hanno curve altrimenti si ottengono strani risultati
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">Autore
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctEven"><a href="https://www.freecadweb.org/wiki/index.php?title=User:Wmayer" title="User:Wmayer">Wmayer</a>
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">Link
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctEven"><a href="https://www.freecadweb.org/wiki/index.php?title=Macros_recipes/it" title="Macros recipes/it">Esempi di macro</a><br /><a href="https://www.freecadweb.org/wiki/index.php?title=How_to_install_macros/it" title="How to install macros/it">Come installare le Macro</a><br /><a href="https://www.freecadweb.org/wiki/index.php?title=Customize_Toolbars/it" title="Customize Toolbars/it">Personalizzare la barra degli strumenti</a>
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">Versione
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctEven macro-version">1.0
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">Data ultima modifica
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctEven macro-date">2011-08-01
|
|
</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="#Da_Mesh_a_Part"><span class="tocnumber">1</span> <span class="toctext">Da Mesh a Part</span></a></li>
|
|
<li class="toclevel-1 tocsection-1"><a href="#Descrizione"><span class="tocnumber">2</span> <span class="toctext">Descrizione</span></a></li>
|
|
<li class="toclevel-1 tocsection-2"><a href="#Link"><span class="tocnumber">3</span> <span class="toctext">Link</span></a></li>
|
|
</ul>
|
|
</div>
|
|
|
|
</td></tr>
|
|
</table>
|
|
<p><br />
|
|
</p>
|
|
<h2><span class="mw-headline" id="Descrizione">Descrizione</span></h2>
|
|
<p>Questa macro converte gli oggetti Mesh selezionati in Parti. Ha una tolleranza ampia, quindi è da utilizzare solo con oggetti che non hanno curve altrimenti si ottengono errori o strani risultati
|
|
</p><p><br />
|
|
</p>
|
|
<pre>import FreeCAD,FreeCADGui,Mesh,Part,MeshPart
|
|
|
|
for obj in FreeCADGui.Selection.getSelection():
|
|
if "Mesh" in obj.PropertiesList:
|
|
faces = []
|
|
mesh = obj.Mesh
|
|
segments = mesh.getPlanarSegments(0.01) # use rather strict tolerance here
|
|
|
|
for i in segments:
|
|
if len(i) > 0:
|
|
# a segment can have inner holes
|
|
wires = MeshPart.wireFromSegment(mesh, i)
|
|
# we assume that the exterior boundary is that one with the biggest bounding box
|
|
if len(wires) > 0:
|
|
ext = None
|
|
max_length = 0
|
|
for i in wires:
|
|
if i.BoundBox.DiagonalLength > max_length:
|
|
max_length = i.BoundBox.DiagonalLength
|
|
ext = i
|
|
wires.remove(ext)
|
|
# all interior wires mark a hole and must reverse their orientation, otherwise Part.Face fails
|
|
for i in wires:
|
|
i.reverse()
|
|
# make sure that the exterior wires comes as first in the lsit
|
|
wires.insert(0, ext)
|
|
faces.append(Part.Face(wires))
|
|
|
|
shell=Part.Compound(faces)
|
|
solid = Part.Solid(Part.Shell(faces))
|
|
name = obj.Name
|
|
FreeCAD.ActiveDocument.removeObject(name)
|
|
FreeCAD.ActiveDocument.addObject("Part::Feature",name).Shape = solid </pre>
|
|
<div style="clear:both"></div>
|
|
<p><br />
|
|
</p>
|
|
<h2><span class="mw-headline" id="Link">Link</span></h2>
|
|
<p>The discussion on the forum <a rel="nofollow" class="external text" href="http://forum.freecadweb.org/viewtopic.php?f=3&t=253&hilit=getPlanarSegments">Convert mesh to solid?</a>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div><div class="printfooter">
|
|
Online version: "<a dir="ltr" href="https://www.freecadweb.org/wiki/index.php?title=Macro_MeshToPart/it&oldid=240082">http://www.freecadweb.org/wiki/index.php?title=Macro_MeshToPart/it&oldid=240082</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> |