160 lines
8.5 KiB
HTML
160 lines
8.5 KiB
HTML
<html><head><title>Macro Cut Line/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 Cut Line/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="Taglia_linea"><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> Taglia linea</span></h3>
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">Descrizione
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctEven left">Taglia una linea in segmenti bicolore e crea i punti.
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">Autore
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctEven"><a href="https://www.freecadweb.org/wiki/index.php?title=User:Mario52" title="User:Mario52">mario52</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">0.1
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">Data ultima modifica
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctEven macro-date">2015-03-08
|
|
</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="#Taglia_linea"><span class="tocnumber">1</span> <span class="toctext">Taglia linea</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="#Uso"><span class="tocnumber">3</span> <span class="toctext">Uso</span></a></li>
|
|
<li class="toclevel-1 tocsection-3"><a href="#Script"><span class="tocnumber">4</span> <span class="toctext">Script</span></a></li>
|
|
<li class="toclevel-1 tocsection-4"><a href="#Link"><span class="tocnumber">5</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 piccola macro taglia una linea, crea dei punti e dei segmenti bicolore della linea.
|
|
</p>
|
|
<div class="floatleft"><a href="https://www.freecadweb.org/wiki/index.php?title=File:Macro_cutLine_00.png" class="image" title="cutLine"><img alt="cutLine" src="400px-Macro_cutLine_00.png" width="400" height="300" srcset="/wiki/images/thumb/d/dd/Macro_cutLine_00.png/600px-Macro_cutLine_00.png 1.5x, /wiki/images/d/dd/Macro_cutLine_00.png 2x" /></a></div>
|
|
<div style="clear:both"></div>
|
|
<h2><span class="mw-headline" id="Uso">Uso</span></h2>
|
|
<p>Può essere usata nell'editor delle macro di FreeCAD.
|
|
</p><p>Se la macro viene copiata nella console Python può essere utilizzata con:
|
|
</p>
|
|
<pre>cutLine(4, createLine = 1, biColor = 1, createPoint = 0) </pre>
|
|
<ul><li><b>4 :</b> numero di tagli</li>
|
|
<li><b>createPoint</b> : crea i punti (1) oppure no (0) (Defaut 1 crea pinti)</li>
|
|
<li><b>createLine</b> : crea le linee (>0) oppure no (0) (Defaut 0 non crea linee)</li>
|
|
<li><b>biColor</b> : crea linee bicolore (>0) oppure no (0) (Defaut 0)</li></ul>
|
|
<p><br />
|
|
è possibile modificare i valori di default nella macro.
|
|
</p><p>Con bisColor sulla linea originale vengono create delle linee rosse e bianche .... i colori sono modificabili nel codice alle righe 19 e 22.
|
|
</p>
|
|
<h2><span class="mw-headline" id="Script">Script</span></h2>
|
|
<p><b>Macro_cutLine.FCMacro</b>
|
|
</p>
|
|
<pre>#################################################################
|
|
# http://forum.freecadweb.org/viewtopic.php?f=3&t=4217&hilit=discretize
|
|
|
|
__title__ = "cutLine"
|
|
__author__ = "Mario52"
|
|
__version__ = "00.01"
|
|
__date__ = "08/03/2015"
|
|
|
|
import Draft, Part
|
|
def cutLine(numberOfPoints = 2, createPoint = 1, createLine = 0, biColor = 0): # create a points of forme
|
|
|
|
def createLines(numberOfPoints, points, biColor): # create line
|
|
biscolor = 0
|
|
for lin in range(numberOfPoints-1):
|
|
creaLine = [FreeCAD.Vector(points[lin]),FreeCAD.Vector(points[lin+1])]
|
|
wire = Draft.makeWire(creaLine,closed=False,face=False,support=None)
|
|
if biColor != 0: # biColor
|
|
if biscolor == 0:
|
|
FreeCADGui.ActiveDocument.getObject(wire.Name).LineColor = (1.0,0.0,0.0) # 255 = 1 (10 = (1/255 * 10 ))
|
|
biscolor = 1
|
|
else:
|
|
FreeCADGui.ActiveDocument.getObject(wire.Name).LineColor = (1.0,1.0,1.0) # 255 = 1 (10 = (1/255 * 10 ))
|
|
biscolor = 0
|
|
try:
|
|
points = []
|
|
points[:] = []
|
|
selectionObjects = FreeCADGui.Selection.getSelectionEx() # getSelectionEx
|
|
numberOfPoints += 1
|
|
for selection in selectionObjects:
|
|
compteur = pas = 0
|
|
for selectedEdge in selection.SubObjects:
|
|
# FreeCAD.Console.PrintMessage(selectionObjects[0].SubElementNames[compteur] + "\n")
|
|
print selectionObjects[0].SubElementNames[compteur] # getSelectionEx
|
|
compteur += 1
|
|
points = selectedEdge.discretize(numberOfPoints)
|
|
if createLine != 0:
|
|
createLines(numberOfPoints, points, biColor)
|
|
for p in points:
|
|
if createPoint != 0:
|
|
Draft.makePoint( p.x, p.y, p.z)
|
|
# FreeCAD.Console.PrintMessage(str(compteur)+" X"+ str(p.x)+" Y"+ str(p.y)+ " Z"+ str(p.z) + "\n")
|
|
print compteur," X", p.x, " Y", p.y, " Z", p.z
|
|
pas = 1 #
|
|
|
|
if pas == 0: # the not SubObjects
|
|
selectionObjects = FreeCADGui.Selection.getSelection() # select all elements
|
|
# FreeCAD.Console.PrintMessage(selectionObjects[0].Name + "\n")
|
|
print selectionObjects[0].Name # getSelection()
|
|
compteur = 0
|
|
for ii in enumerate(selectionObjects[0].Shape.Edges):
|
|
compteur += 1
|
|
points = ii[1].discretize(numberOfPoints) # discretize the element
|
|
for p in points:
|
|
if createPoint != 0:
|
|
Draft.makePoint( p.x, p.y, p.z) # create points
|
|
# FreeCAD.Console.PrintMessage(str(compteur)+" X"+ str(p.x)+" Y"+ str(p.y)+ " Z"+ str(p.z) + "\n")
|
|
print compteur, " X", p.x, " Y", p.y, " Z", p.z # list and display the coordinates
|
|
if createLine != 0:
|
|
createLines(numberOfPoints, points, biColor)
|
|
except:
|
|
# FreeCAD.Console.PrintError("Error" + "\n" + "Give : cutLine(numberOfPoints = 2, createPoint = 1, createLine = 0, biColor = 0)"+"\n")
|
|
print "Error : Give cutLine(numberOfPoints = 2, createPoint = 1, createLine = 0, biColor = 0)"
|
|
|
|
|
|
#cutLine(2, createLine = 1, biColor = 1, createPoint = 0) </pre>
|
|
<h2><span class="mw-headline" id="Link">Link</span></h2>
|
|
<p>questa funzione utilizzare la funzione discrete <a rel="nofollow" class="external text" href="http://forum.freecadweb.org/viewtopic.php?f=3&t=4217&hilit=discretize">the original code</a>
|
|
</p>
|
|
<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_Cut_Line/it&oldid=240657">http://www.freecadweb.org/wiki/index.php?title=Macro_Cut_Line/it&oldid=240657</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> |