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

454 lines
23 KiB
HTML

<html><head><title>Macro FCWire To Volume/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 FCWire To Volume/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="Macro_FCWire_To_Volume"><a href="https://www.freecadweb.org/wiki/index.php?title=File:Macro_FCWire_To_Volume.png" class="image"><img alt="Macro FCWire To Volume.png" src="32px-Macro_FCWire_To_Volume.png" width="32" height="32" srcset="/wiki/images/thumb/f/f2/Macro_FCWire_To_Volume.png/48px-Macro_FCWire_To_Volume.png 1.5x, /wiki/images/thumb/f/f2/Macro_FCWire_To_Volume.png/64px-Macro_FCWire_To_Volume.png 2x" /></a> Macro FCWire To Volume</span></h3>
</td></tr>
<tr>
<th class="ctOdd">Description
</th></tr>
<tr>
<td class="ctEven left">Crée un volume avec des objets Draft en une manipulation
</td></tr>
<tr>
<th class="ctOdd">Auteur
</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">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">2016-10-10
</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="#Macro_FCWire_To_Volume"><span class="tocnumber">1</span> <span class="toctext">Macro FCWire To Volume</span></a></li>
<li class="toclevel-1 tocsection-1"><a href="#Description"><span class="tocnumber">2</span> <span class="toctext">Description</span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#Utilisation"><span class="tocnumber">3</span> <span class="toctext">Utilisation</span></a></li>
<li class="toclevel-1 tocsection-3"><a href="#Lien"><span class="tocnumber">4</span> <span class="toctext">Lien</span></a></li>
</ul>
</div>
</td></tr>
</table><a href="https://www.freecadweb.org/wiki/index.php?title=File:Macro_FCWire_To_Volume_01.png" class="image" title="Formes"><img alt="Formes" src="400px-Macro_FCWire_To_Volume_01.png" width="400" height="300" srcset="/wiki/images/thumb/9/9b/Macro_FCWire_To_Volume_01.png/600px-Macro_FCWire_To_Volume_01.png 1.5x, /wiki/images/9/9b/Macro_FCWire_To_Volume_01.png 2x" /></a>
<div style="clear:both"></div>
<h2><span class="mw-headline" id="Description">Description</span></h2>
<p>Cette macro crée une extrusion avec des objets Draft en une seule opération.
</p>
<h2><span class="mw-headline" id="Utilisation">Utilisation</span></h2>
<p>Sélectionnez vos objet qui serviront à la création de l'extrusion, donnez la hauteur de l'extrusion choisissez le type d'extrusion et validez avec le bouton <span style="background: #DDDDDD; border: 1px solid #888888; padding: 0px 5px 1px 5px;">Create</span>
</p>
<div class="floatleft"><a href="https://www.freecadweb.org/wiki/index.php?title=File:Macro_FCWire_To_Volume_00.png" class="image"><img alt="Macro FCWire To Volume 00.png" src="Macro_FCWire_To_Volume_00.png" width="175" height="214" /></a></div>
<div style="clear:both"></div>
<ul><li><b>SpinBox</b>&#160;: Donnez la hauteur de l'extrusion</li>
<li><b>Single</b>&#160;: Si ce checkBox est coché l'objet créé sera un simple objet si non, l'objet créé conservera toute la hiérarchie de la création de l'objet (Défaut). Les objets originaux ne sont pas modifiés.</li>
<li><b>Common</b> , <b>Substract</b> , <b>Union</b> , <b>Difference</b>&#160;: Type d'opération Booléenne</li>
<li><b>X</b> , <b>Y</b> , <b>Z</b>&#160;: Axes d'extrusion (Z par défaut)</li>
<li><span style="background: #DDDDDD; border: 1px solid #888888; padding: 0px 5px 1px 5px;">Quit</span>&#160;: Quitte la macro</li>
<li><span style="background: #DDDDDD; border: 1px solid #888888; padding: 0px 5px 1px 5px;">Create</span>&#160;: Crée l'objet Booléen</li></ul>
<p>Copiez la macro dans votre répertoire de macros
</p><p>L'icône pour votre barre d'outils <a href="https://www.freecadweb.org/wiki/index.php?title=File:Macro_FCWire_To_Volume.png" class="image"><img alt="Macro FCWire To Volume.png" src="32px-Macro_FCWire_To_Volume.png" width="32" height="32" srcset="/wiki/images/thumb/f/f2/Macro_FCWire_To_Volume.png/48px-Macro_FCWire_To_Volume.png 1.5x, /wiki/images/thumb/f/f2/Macro_FCWire_To_Volume.png/64px-Macro_FCWire_To_Volume.png 2x" /></a>
</p><p>Macro_FCWire_To_Volume.FCMacro
</p>
<pre># -*- coding: utf-8 -*-
from __future__ import unicode_literals
#
"""
***************************************************************************
* Copyright (c) 2016 &lt;mario52&gt; *
* *
* This file is a supplement to the FreeCAD CAx development system. *
* *
* 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 software 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 macro; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
* USA *
***************************************************************************
* WARNING! All changes in this file will be lost and *
* may cause malfunction of the program *
***************************************************************************
"""
#Macro_FCWire_To_Volume 10/10/2016_01
#
#OS: Windows 10
#Word size of OS: 64-bit
#Word size of FreeCAD: 64-bit
#Version: 0.16.6706 (Git)
#Build type: Release
#Branch: releases/FreeCAD-0-16
#Hash: f86a4e411ff7848dea98d7242f43b7774bee8fa0
#Python version: 2.7.8
#Qt version: 4.8.7
#Coin version: 4.0.0a
#OCC version: 6.8.0.oce-0.17
#
__title__ = "Macro_FCWire_To_Volume"
__author__ = "Mario52"
__url__ = "http://www.freecadweb.org/index-fr.html"
__version__ = "00.01"
__date__ = "10/10/2016"
try:
import PyQt4
from PyQt4 import QtGui ,QtCore
from PyQt4.QtGui import *
from PyQt4.QtCore import *
except Exception:
import PySide
from PySide import QtGui ,QtCore
from PySide.QtGui import *
from PySide.QtCore import *
import Draft, Part, PartGui, FreeCADGui, FreeCAD
from FreeCAD import Base
import math
from math import sqrt, pi, sin, cos, asin
Gui = FreeCADGui
App = FreeCAD
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
def errorDialog(msg):
diag = QtGui.QMessageBox(QtGui.QMessageBox.Critical,u"Error Message",msg )
# diag.setWindowModality(QtCore.Qt.ApplicationModal) # la fonction a ete desactivee pour favoriser "WindowStaysOnTopHint"
try:
diag.setWindowFlags(PyQt4.QtCore.Qt.WindowStaysOnTopHint) # PyQt4 # cette fonction met la fenetre en avant
except Exception:
diag.setWindowFlags(PySide.QtCore.Qt.WindowStaysOnTopHint) # PySide # cette fonction met la fenetre en avant
diag.exec_()
class Ui_MainWindow(object):
def __init__(self ):
self.window = MainWindow
#self.path = FreeCAD.ConfigGet("AppHomePath")
self.path = FreeCAD.ConfigGet("UserAppData")
self.path = self.path.replace("\\","/")
self.thicknessValue = 0.0
self.thicknessX = 0.0 # extrusion
self.thicknessY = 0.0 # extrusion
self.thicknessZ = 0.0 # extrusion
def setupUi(self, MainWindow):
self.window = MainWindow
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(171, 180)
MainWindow.setMinimumSize(QtCore.QSize(171, 180))
MainWindow.setMaximumSize(QtCore.QSize(171, 180))
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.fontGlobal_08 = QtGui.QFont() # pour compatibilite Windows Linux pour tous les textes
self.fontGlobal_08.setFamily("Arial") # pour compatibilite Windows Linux pour tous les textes
self.fontGlobal_08.setPointSize(8.0) # pour compatibilite Windows Linux pour tous les textes
self.label_01 = QtGui.QLabel(self.centralwidget)
self.label_01.setGeometry(QtCore.QRect(10, 0, 151, 16))
self.label_01.setFont(self.fontGlobal_08) # pour compatibilite W L
self.label_01.setObjectName(_fromUtf8("label_01"))
self.doubleSpinBox = QtGui.QDoubleSpinBox(self.centralwidget)
self.doubleSpinBox.setGeometry(QtCore.QRect(10, 20, 81, 22))
self.doubleSpinBox.setFont(self.fontGlobal_08) # pour compatibilite W L
self.doubleSpinBox.setObjectName(_fromUtf8("doubleSpinBox"))
self.doubleSpinBox.setMinimum(0)
self.doubleSpinBox.setMaximum(999999.999999)
self.doubleSpinBox.setDecimals(3)
self.doubleSpinBox.setValue(0.0)
self.doubleSpinBox.valueChanged.connect(self.on_doubleSpinBox) ###
self.checkBox_01 = QtGui.QCheckBox(self.centralwidget)
self.checkBox_01.setGeometry(QtCore.QRect(100, 23, 70, 17))
self.checkBox_01.setFont(self.fontGlobal_08) # pour compatibilite W L
self.checkBox_01.setObjectName(_fromUtf8("checkBox_01"))
self.checkBox_01.setChecked(False) # True
self.checkBox_01.setToolTip(_fromUtf8("Check this checkBox"+"\n"+
"for create single object"))
self.FrameOp = QtGui.QFrame(self.centralwidget)
self.FrameOp.setGeometry(QtCore.QRect(10, 50, 81, 80))
self.FrameOp.setFrameShape(QtGui.QFrame.StyledPanel)
self.FrameOp.setFrameShadow(QtGui.QFrame.Raised)
self.FrameOp.setObjectName(_fromUtf8("FrameOp"))
self.RB_Common = QtGui.QRadioButton(self.FrameOp)
self.RB_Common.setGeometry(QtCore.QRect(10, 0, 82, 17))
self.RB_Common.setFont(self.fontGlobal_08) # pour compatibilite W L
self.RB_Common.setChecked(True)
self.RB_Common.setObjectName(_fromUtf8("RB_Common"))
self.RB_Substract = QtGui.QRadioButton(self.FrameOp)
self.RB_Substract.setGeometry(QtCore.QRect(10, 20, 82, 17))
self.RB_Substract.setFont(self.fontGlobal_08) # pour compatibilite W L
self.RB_Substract.setObjectName(_fromUtf8("RB_Substract"))
self.RB_Union = QtGui.QRadioButton(self.FrameOp)
self.RB_Union.setGeometry(QtCore.QRect(10, 40, 82, 17))
self.RB_Union.setFont(self.fontGlobal_08) # pour compatibilite W L
self.RB_Union.setObjectName(_fromUtf8("RB_Union"))
self.RB_Difference = QtGui.QRadioButton(self.FrameOp)
self.RB_Difference.setGeometry(QtCore.QRect(10, 60, 82, 17))
self.RB_Difference.setFont(self.fontGlobal_08) # pour compatibilite W L
self.RB_Difference.setObjectName(_fromUtf8("RB_Difference"))
self.FrameAxis = QtGui.QFrame(self.centralwidget)
self.FrameAxis.setGeometry(QtCore.QRect(90, 50, 71, 80))
self.FrameAxis.setFrameShape(QtGui.QFrame.StyledPanel)
self.FrameAxis.setFrameShadow(QtGui.QFrame.Raised)
self.FrameAxis.setObjectName(_fromUtf8("FrameAxis"))
self.RB_Axis_X = QtGui.QRadioButton(self.FrameAxis)
self.RB_Axis_X.setGeometry(QtCore.QRect(10, 0, 71, 17))
self.RB_Axis_X.setFont(self.fontGlobal_08) # pour compatibilite W L
self.RB_Axis_X.setObjectName(_fromUtf8("RB_Axis_X"))
self.RB_Axis_X.setToolTip(_fromUtf8("Plane YZ extrude direction X"))
self.RB_Axis_Y = QtGui.QRadioButton(self.FrameAxis)
self.RB_Axis_Y.setGeometry(QtCore.QRect(10, 30, 71, 17))
self.RB_Axis_Y.setFont(self.fontGlobal_08) # pour compatibilite W L
self.RB_Axis_Y.setObjectName(_fromUtf8("RB_Axis_Y"))
self.RB_Axis_Y.setToolTip(_fromUtf8("Plane XZ extrude direction Y"))
self.RB_Axis_Z = QtGui.QRadioButton(self.FrameAxis)
self.RB_Axis_Z.setGeometry(QtCore.QRect(10, 60, 71, 17))
self.RB_Axis_Z.setFont(self.fontGlobal_08) # pour compatibilite W L
self.RB_Axis_Z.setObjectName(_fromUtf8("RB_Axis_Z"))
self.RB_Axis_Z.setChecked(True)
self.RB_Axis_Z.setToolTip(_fromUtf8("Plane XY extrude direction Z"))
self.PB_Quit = QtGui.QPushButton(self.centralwidget)
self.PB_Quit.setGeometry(QtCore.QRect(10, 140, 73, 23))
self.PB_Quit.setFont(self.fontGlobal_08) # pour compatibilite W L
self.PB_Quit.setObjectName(_fromUtf8("PB_Quit"))
self.PB_Quit.clicked.connect(self.on_PB_Quit) ###
self.PB_Create = QtGui.QPushButton(self.centralwidget)
self.PB_Create.setGeometry(QtCore.QRect(90, 140, 73, 23))
self.PB_Create.setFont(self.fontGlobal_08) # pour compatibilite W L
self.PB_Create.setObjectName(_fromUtf8("PB_Create"))
self.PB_Create.clicked.connect(self.on_PB_Create) ###
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle("FCWire To Volume")
self.label_01.setText("FCWire To Volume")
self.checkBox_01.setText("Single")
self.RB_Common.setText("Common")
self.RB_Substract.setText("Substract")
self.RB_Union.setText("Union")
self.RB_Difference.setText("Difference")
self.RB_Axis_X.setText( "X Axis")
self.RB_Axis_Y.setText("Y Axis")
self.RB_Axis_Z.setText("Z Axis")
self.PB_Quit.setText("Quit")
self.PB_Create.setText("Create")
try:
MainWindow.setWindowFlags(PyQt4.QtCore.Qt.WindowStaysOnTopHint) # PyQt4 cette fonction met la fenetre en avant
except Exception:
MainWindow.setWindowFlags(PySide.QtCore.Qt.WindowStaysOnTopHint) # PySide cette fonction met la fenetre en avant
def on_doubleSpinBox(self,value):
self.thicknessValue = value
def on_PB_Quit(self): # Quit
App.Console.PrintMessage(str("Fin FCWire To Volume ")+"\n")
self.window.hide()
def on_PB_Create(self):
selectionObjects = FreeCADGui.Selection.getSelection()
noface = 0
try:
selectedEdge = FreeCADGui.Selection.getSelectionEx()[0].SubObjects[0] # select one element SubObjects
if str(selectedEdge)[1:5] == "Face":
noface = 1
except Exception:
None
selectionDuplicate = []
del selectionDuplicate[:]
p = []
del p[:]
try:
###########
self.thicknessX = 0.0
self.thicknessY = 0.0
self.thicknessZ = 0.0
if self.RB_Axis_X.isChecked():
self.thicknessX = self.thicknessValue
if self.RB_Axis_Y.isChecked():
self.thicknessY = self.thicknessValue
if self.RB_Axis_Z.isChecked():
self.thicknessZ = self.thicknessValue
###########
if (len(selectionObjects) &gt;= 2) and (noface == 0) and (self.thicknessX + self.thicknessY + self.thicknessZ&#160;!= 0.0):
for i in selectionObjects: # duplicate object
Part.show(i.Shape.copy())
sD = doc.ActiveObject
sD.Label = i.Name
selectionDuplicate.append(sD)
for i in (selectionDuplicate): # extrude object
a = Draft.extrude(i,Base.Vector(self.thicknessX,self.thicknessY,self.thicknessZ)) # axis extrude X Y Z
a.Solid = True
p.append(a)
if self.RB_Common.isChecked():
name = "Common_" + selectionDuplicate[0].Label ## create Common_
tx = doc.addObject("Part::MultiCommon",name)
tx.Shapes = p
doc.recompute()
if self.checkBox_01.isChecked():
Part.show(tx.Shape)
singleO = App.ActiveDocument.ActiveObject
singleO.Label = name
doc.removeObject(tx.Name)
for i in range(len(selectionDuplicate)):
doc.removeObject(selectionDuplicate[i].Name)
doc.removeObject(p[i].Name)
App.Console.PrintMessage("RB_Common ")
elif self.RB_Substract.isChecked():
name = str("Cut_" + selectionDuplicate[0].Label) ## create Cut_
tx = doc.addObject("Part::Cut",name)
tx.Base = p[0]
tx.Tool = p[1]
doc.recompute()
if self.checkBox_01.isChecked():
Part.show(tx.Shape)
singleO = App.ActiveDocument.ActiveObject
singleO.Label = name
doc.removeObject(tx.Name)
for i in range(len(selectionDuplicate)):
doc.removeObject(selectionDuplicate[i].Name)
doc.removeObject(p[i].Name)
App.Console.PrintMessage("RB_Substract ")
elif self.RB_Union.isChecked():
name = str("Fusion_" + selectionDuplicate[0].Label) ## create Fusion_
tx = doc.addObject("Part::MultiFuse",name)
tx.Shapes = p
doc.recompute()
if self.checkBox_01.isChecked():
Part.show(tx.Shape)
singleO = App.ActiveDocument.ActiveObject
singleO.Label = name
doc.removeObject(tx.Name)
for i in range(len(selectionDuplicate)):
doc.removeObject(selectionDuplicate[i].Name)
doc.removeObject(p[i].Name)
App.Console.PrintMessage("RB_Union")
elif self.RB_Difference.isChecked():
name = "CommonD_" + selectionDuplicate[0].Label ##
commun = doc.addObject("Part::MultiCommon",name)
commun.Shapes = p
name = str("FusionD_" + selectionDuplicate[0].Label) ##
fusion = doc.addObject("Part::MultiFuse",name)
fusion.Shapes = p
name = str("Difference_" + selectionDuplicate[0].Label)## create Difference_
difference = doc.addObject("Part::Cut",name)
difference.Base = fusion
difference.Tool = commun
doc.recompute()
if self.checkBox_01.isChecked():
Part.show(difference.Shape)
singleO = App.ActiveDocument.ActiveObject
singleO.Label = name
doc.removeObject(commun.Name)
doc.removeObject(fusion.Name)
doc.removeObject(difference.Name)
for i in range(len(selectionDuplicate)):
doc.removeObject(selectionDuplicate[i].Name)
doc.removeObject(p[i].Name)
App.Console.PrintMessage("RB_Difference ")
doc.recompute()
App.Console.PrintMessage(str(self.thicknessX)+" "+str(self.thicknessY)+" "+str(self.thicknessZ) + "\n")
else:
if (self.thicknessX + self.thicknessY + self.thicknessZ == 0.0):
App.Console.PrintError("Thickness = 0" + "\n")
else:
App.Console.PrintError("Not for Face" + "\n")
except Exception:
print "Wrong selection or operation"
#______________________________________________________________________________________
doc = FreeCAD.ActiveDocument
if doc == None:
doc = FreeCAD.newDocument()
MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show() </pre>
<h2><span class="mw-headline" id="Lien">Lien</span></h2>
<p>la discussion sur le forum <a rel="nofollow" class="external text" href="http://forum.freecadweb.org/viewtopic.php?f=3&amp;t=16570&amp;start=50">Bunch of issues/questions</a>
</p>
</div>
</div>
</div><div class="printfooter">
Online version: "<a dir="ltr" href="https://www.freecadweb.org/wiki/index.php?title=Macro_FCWire_To_Volume/fr&amp;oldid=240110">http://www.freecadweb.org/wiki/index.php?title=Macro_FCWire_To_Volume/fr&amp;oldid=240110</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>