246 lines
11 KiB
HTML
246 lines
11 KiB
HTML
<html><head><title>Macro Section/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 Section/fr</h1></div>
|
|
|
|
<div id="mw-content-text" lang="fr" dir="ltr" class="mw-content-ltr"><hr/><div class="mw-parser-output"><p>(parametrique!)
|
|
</p>
|
|
<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="Section"><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> Section</span></h3>
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">Description
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctEven left">Outil alternatif à l'outil <a href="https://www.freecadweb.org/wiki/index.php?title=Part_Section/fr" title="Part Section/fr">Part Section</a> (parametrique)
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">Auteur
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctEven"><a href="https://www.freecadweb.org/wiki/index.php?title=User:DeepSOIC" title="User:DeepSOIC">DeepSOIC</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.1
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">Date dernière modification
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctEven macro-date">2018-04-28
|
|
</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="#Section"><span class="tocnumber">1</span> <span class="toctext">Section</span></a></li>
|
|
<li class="toclevel-1 tocsection-1"><a href="#Installation:"><span class="tocnumber">2</span> <span class="toctext">Installation:</span></a></li>
|
|
<li class="toclevel-1 tocsection-2"><a href="#Utilisation"><span class="tocnumber">3</span> <span class="toctext">Utilisation</span></a></li>
|
|
</ul>
|
|
</div>
|
|
|
|
</td></tr>
|
|
</table><a href="https://www.freecadweb.org/wiki/index.php?title=File:Macro_Section_Screenshot.png" class="image"><img alt="Macro Section Screenshot.png" src="1000px-Macro_Section_Screenshot.png" width="1000" height="393" srcset="/wiki/images/b/b6/Macro_Section_Screenshot.png 1.5x" /></a>
|
|
<p><br />
|
|
L'outil <a href="https://www.freecadweb.org/wiki/index.php?title=Part_Section/fr" title="Part Section/fr">Part Section</a> produit des bords avec de continuité et un grand nombre de segments (nœuds), ce qui n'est pas très approprié pour l'outil <a href="https://www.freecadweb.org/wiki/index.php?title=Part_Sweep/fr" title="Part Sweep/fr">Sweep</a>.
|
|
</p><p>Cette macro fait le même travail et extrait les bords de la section du résultat général de la fusion (GFA). Le résultat est résultat continu et possède moins de nœuds. Il n'est pas encore parfait pour le balayage , mais le résultat est plus satisfaisant que la simple utilisation de Part Section.
|
|
</p><p>Requis FreeCAD v0.17+ built against OCC no less than 6.9.0 (tested on 7.0.0).
|
|
</p>
|
|
<h2><span class="mw-headline" id="Installation:">Installation:</span></h2>
|
|
<p>Téléchargez le fichier et sauvez les dans votre répertoire de macros:
|
|
</p><p><a rel="nofollow" class="external free" href="https://github.com/DeepSOIC/FreeCAD-Macros/raw/master/Section/MacroSection.py">https://github.com/DeepSOIC/FreeCAD-Macros/raw/master/Section/MacroSection.py</a>
|
|
</p>
|
|
<h2><span class="mw-headline" id="Utilisation">Utilisation</span></h2>
|
|
<ol><li> Sélectionnez deux objets shapes et lancez la macro pour créer la section</li>
|
|
<li> Dans le menu FreeCAD: Macro -> Macros... -> double-cliquez sur MacroSection.FCMacro . Un nouvel objet est créé.</li></ol>
|
|
<p>Après avoir exécuté la macro, vous pouvez ajouter un bouton sur votre barre d'outils. Allez dans Outils -> Personnaliser, Barres d'outils, sélectionnez MacroSection dans la liste déroulante de gauche et ajoutez la commande à l'une de vos barres d'outils personnalisées.
|
|
</p><p><br />
|
|
</p>
|
|
<div style="clear:both"></div>
|
|
<p><br />
|
|
MacroSection.py:
|
|
</p>
|
|
<pre>#***************************************************************************
|
|
#* *
|
|
#* Copyright (c) 2016 - Victor Titov (DeepSOIC) *
|
|
#* <vv.titov@gmail.com> *
|
|
#* *
|
|
#* This program is free software; you can redistribute it and/or modify *
|
|
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
|
#* as published by the Free Software Foundation; either version 2 of *
|
|
#* the License, or (at your option) any later version. *
|
|
#* for detail see the LICENCE text file. *
|
|
#* *
|
|
#* This program is distributed in the hope that it will be useful, *
|
|
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
#* GNU Library General Public License for more details. *
|
|
#* *
|
|
#* You should have received a copy of the GNU Library General Public *
|
|
#* License along with this program; if not, write to the Free Software *
|
|
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
|
#* USA *
|
|
#* *
|
|
#***************************************************************************
|
|
|
|
__title__="Macro Section"
|
|
__author__ = "DeepSOIC"
|
|
__doc__ = '''
|
|
Macro Section.
|
|
Alternative implementation of Part Section tool.
|
|
Requires FreeCAD v0.17+ and OCC 6.9.0+
|
|
|
|
Instructions:
|
|
First of all, save this macro as MacroSection.py, into a location from where it can be imported. FC's standard macro location is the best place to do that.
|
|
|
|
Select two shapes to compute section between.
|
|
Then, in Py console:
|
|
|
|
import MacroSection
|
|
MacroSection.run()
|
|
|
|
OR
|
|
|
|
just run this file as a macro.
|
|
|
|
Parametric Section object is created.
|
|
'''
|
|
if __name__ == "__main__": #being run as a macro
|
|
import MacroSection
|
|
MacroSection.run()
|
|
|
|
import FreeCAD as App
|
|
if App.GuiUp:
|
|
import FreeCADGui as Gui
|
|
import Part
|
|
|
|
def makeSectionFeature():
|
|
'''makeSectionFeature(): makes a Section parametric feature object. Returns the new object.'''
|
|
selfobj = App.ActiveDocument.addObject("Part::FeaturePython","Section")
|
|
Section(selfobj)
|
|
ViewProviderSection(selfobj.ViewObject)
|
|
return selfobj
|
|
|
|
class Section:
|
|
"The Section feature object"
|
|
def __init__(self,selfobj):
|
|
selfobj.addProperty("App::PropertyLink","Base","Section","Input shape")
|
|
selfobj.addProperty("App::PropertyLink","Tool","Section","Input shape")
|
|
selfobj.Proxy = self
|
|
|
|
def execute(self,selfobj):
|
|
import BOPTools
|
|
import BOPTools.ShapeMerge
|
|
from BOPTools.Utils import HashableShape
|
|
|
|
if len(selfobj.Base.Shape.Faces) == 0 or len(selfobj.Tool.Shape.Faces) == 0:
|
|
raise ValueError("Shapes must have at least one face each.")
|
|
sh1 = Part.Compound(selfobj.Base.Shape.Faces)
|
|
sh2 = Part.Compound(selfobj.Tool.Shape.Faces)
|
|
pieces, map = sh1.generalFuse([sh2])
|
|
pieces = pieces.childShapes()
|
|
assert(len(pieces) == 2)
|
|
|
|
edges1 = set([HashableShape(edge) for edge in pieces[0].Edges])
|
|
edges2 = set([HashableShape(edge) for edge in pieces[1].Edges])
|
|
edges_to_return = list(set.intersection(edges1, edges2))
|
|
edges_to_return = [edge.Shape for edge in edges_to_return] #convert hashable shapes back to plain shapes
|
|
print("returning {num} edges of total {tot}".format(num= len(edges_to_return), tot= len(edges1)+len(edges2)))
|
|
|
|
selfobj.Shape = BOPTools.ShapeMerge.mergeWires(edges_to_return)
|
|
|
|
class ViewProviderSection:
|
|
def __init__(self,vobj):
|
|
vobj.Proxy = self
|
|
|
|
def getIcon(self):
|
|
return ":/icons/Part_Section.svg"
|
|
|
|
def attach(self, vobj):
|
|
self.ViewObject = vobj
|
|
self.Object = vobj.Object
|
|
|
|
def __getstate__(self):
|
|
return None
|
|
|
|
def __setstate__(self,state):
|
|
return None
|
|
|
|
def claimChildren(self):
|
|
return [self.Object.Base, self.Object.Tool]
|
|
|
|
def onDelete(self, feature, subelements): # subelements is a tuple of strings
|
|
try:
|
|
self.Object.Base.ViewObject.show()
|
|
self.Object.Tool.ViewObject.show()
|
|
except Exception as err:
|
|
App.Console.PrintError("Error in onDelete: " + err.message)
|
|
return True
|
|
|
|
class CommandMacroSection:
|
|
"Command to create Section feature"
|
|
def GetResources(self):
|
|
return {'Pixmap'  : ":/icons/Part_Section.svg",
|
|
'MenuText': "Section",
|
|
'Accel': "",
|
|
'ToolTip': "Macro_Section: alternative implementation of Part Section tool"}
|
|
|
|
def Activated(self):
|
|
run()
|
|
def IsActive(self):
|
|
if App.ActiveDocument:
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
if App.GuiUp:
|
|
Gui.addCommand("Macro_Section", CommandMacroSection())
|
|
|
|
def run():
|
|
sel = Gui.Selection.getSelectionEx()
|
|
try:
|
|
if len(sel) != 2:
|
|
raise Exception("Select two shapes to compute section between, first! Then run this macro.")
|
|
try:
|
|
App.ActiveDocument.openTransaction("Macro Section")
|
|
selfobj = makeSectionFeature()
|
|
selfobj.Base = sel[0].Object
|
|
selfobj.Tool = sel[1].Object
|
|
selfobj.Base.ViewObject.hide()
|
|
selfobj.Tool.ViewObject.hide()
|
|
|
|
selfobj.Proxy.execute(selfobj)
|
|
finally:
|
|
App.ActiveDocument.commitTransaction()
|
|
except Exception as err:
|
|
from PySide import QtGui
|
|
mb = QtGui.QMessageBox()
|
|
mb.setIcon(mb.Icon.Warning)
|
|
mb.setText(err.message)
|
|
mb.setWindowTitle("Macro Section")
|
|
mb.exec_() </pre>
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div><div class="printfooter">
|
|
Online version: "<a dir="ltr" href="https://www.freecadweb.org/wiki/index.php?title=Macro_Section/fr&oldid=277955">http://www.freecadweb.org/wiki/index.php?title=Macro_Section/fr&oldid=277955</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> |