Macro FCWire To Volume: Difference between revisions

From FreeCAD Documentation
m (date)
(Use {{MacroCode}})
 
(15 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<languages/>
<translate><!--T:1-->
{{Macro|Icon=Macro FCWire To Volume|Name=Macro FCWire To Volume|Description=Create the boolean operation with the selected wires|Author=Mario52|Version=1.0|Date=10/10/2016}}

<!--T:2-->
[[File:Macro FCWire To Volume 01.png|400px]]
</translate>
{{clear}}
<translate>
<translate>
<!--T:1-->
{{Macro
|Name=Macro FCWire To Volume
|Icon=Macro_FCWire_To_Volume.png
|Description=Create the boolean operation with the selected wires. Push the 2d button for create the boolean operation to 2D wire.
|Author=Mario52
|Version=0.02c
|Date=2020/04/11
|FCVersion=0.19
|Download=[https://www.freecadweb.org/wiki/images/f/f2/Macro_FCWire_To_Volume.png ToolBar Icon]
}}

==Description== <!--T:3-->
==Description== <!--T:3-->
This macro create on object boolean with the object Draft selected.
This macro create on object boolean with the object Draft selected.

</translate>
</translate>
[[File:Macro FCWire To Volume 01.png|400px]]
<translate>
<translate>

==Uses== <!--T:4-->
==Uses== <!--T:4-->
Select the wires objects, enter the thickness choice the operation desired and click the button {{KEY|Create}}
Select the wires objects, enter the thickness choice the operation desired and click the button {{KEY|Create}}. Push the 2d button for create the boolean operation to 2D wire.

[[File:Macro FCWire To Volume 00.png|left]]
</translate>
</translate>
[[File:Macro FCWire To Volume 00.png]]
{{clear}}
<translate>
<translate>

<!--T:5-->
===Thickness Solide=== <!--T:5-->
*'''SpinBox''' : Give the thickness

*'''Single''' : If the checkBox is checked the object is on single object, if not the object created conserve the hierarchy of the construction the object (Default). The originals objects hare not modified.
<!--T:9-->
*'''Common''' , '''Substract''' , '''Union''' , '''Difference''' : Boolean's operations
*{{SpinBox|SpinBox}} : Give the thickness
*'''X''' , '''Y''' , '''Z''' : Extrude Axis (Z by Default)

*{{KEY|Quit}} : Quit themacro
===Choice=== <!--T:10-->
*{{KEY|Create}} : Create the Boolean object

====Boolean==== <!--T:11-->

<!--T:12-->
{{RadioButton|TRUE|Intersection}} : Boolean operation

<!--T:13-->
{{RadioButton|Substraction}} : Boolean operation

<!--T:14-->
{{RadioButton|Union}} : Boolean operation

<!--T:15-->
{{RadioButton|Xor}} : Boolean operation

====Axis==== <!--T:16-->

<!--T:17-->
{{RadioButton|X Axis}} : Axis X

<!--T:18-->
{{RadioButton|Y Axis}} : Axis Y

<!--T:19-->
{{RadioButton|TRUE|Z Axis}} : Axis Z (default)

<!--T:20-->
{{RadioButton|Direction}} : (Not functional Later)

====Option==== <!--T:21-->

<!--T:22-->
{{CheckBox|TRUE|Single object}} : If the checkBox is checked the object is on single object, if not the object created conserve the hierarchy of the construction the object

<!--T:23-->
{{CheckBox|TRUE|Hidden}} : The original object are hidden

<!--T:24-->
{{CheckBox|Color}} : If it checked the object resultant is coloured in red

====Command==== <!--T:25-->

<!--T:26-->
*{{KEY|Create 2D}} : Create the Boolean object 2D (contour wire with {{Incode|Draft.makeShape2DView()}})

<!--T:27-->
*{{KEY|Create 3D}} : Create the Boolean object 3D (solid)

<!--T:28-->
*{{KEY|Help}} : Connect to the wiki page (in FreeCAD browser)

<!--T:29-->
*{{KEY|Quit}} : Quit the macro

</translate>
</translate>
<translate>
<translate>

==Script== <!--T:6-->
==Script== <!--T:6-->
Copy the macro in your macro folder.
Copy the macro in your macro folder.
Line 33: Line 97:
</translate>
</translate>


Macro_FCWire_To_Volume.FCMacro
'''Macro_FCWire_To_Volume.FCMacro'''

{{Code|code=
{{MacroCode|code=
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import unicode_literals
Line 40: Line 105:
"""
"""
***************************************************************************
***************************************************************************
* Copyright (c) 2016 <mario52> *
* Copyright (c) 2016 2017 2018 2019 2020 <mario52> *
* *
* *
* This file is a supplement to the FreeCAD CAx development system. *
* This file is a supplement to the FreeCAD CAx development system. *
Line 49: Line 114:
* the License, or (at your option) any later version. *
* the License, or (at your option) any later version. *
* for detail see the LICENCE text file. *
* for detail see the LICENCE text file. *
* *
** **
* Use at your own risk. The author assumes no liability for data loss. *
* It is advised to backup your data frequently. *
* If you do not trust the software do not use it. *
** **
* This software is distributed in the hope that it will be useful, *
* This software is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
Line 64: Line 133:
***************************************************************************
***************************************************************************
"""
"""
#Macro_FCWire_To_Volume 10/10/2016_01
#Macro_FCWire_To_Volume 10/10/2016_01, 2020/04/08_02, 2020/04/10_2b, 2020/04/11_2c
#
#
#OS: Windows 10
#OS: Windows 10 (10.0)
#Word size of OS: 64-bit
#Word size of OS: 64-bit
#Word size of FreeCAD: 64-bit
#Word size of FreeCAD: 64-bit
#Version: 0.16.6706 (Git)
#Version: 0.19.20311 (Git)
#Build type: Release
#Build type: Release
#Branch: releases/FreeCAD-0-16
#Branch: master
#Hash: 915e551bbb7e3614bc804f1ae1f65027b5432b9f
#Hash: f86a4e411ff7848dea98d7242f43b7774bee8fa0
#Python version: 2.7.8
#Python version: 3.6.8
#Qt version: 4.8.7
#Qt version: 5.12.1
#Coin version: 4.0.0a
#Coin version: 4.0.0a
#OCC version: 6.8.0.oce-0.17
#OCC version: 7.3.0
#
#
__title__ = "Macro_FCWire_To_Volume"
__title__ = "Macro_FCWire_To_Volume"
__author__ = "Mario52"
__author__ = "Mario52"
__url__ = "http://www.freecadweb.org/index-fr.html"
__url__ = "https://wiki.freecadweb.org/Macro_FCWire_To_Volume"
__version__ = "00.01"
__version__ = "00.02c"
__date__ = "10/10/2016"
__date__ = "2020/04/11" #YYYY/MM/DD

if int(FreeCAD.Version()[1]) < 18: # Version de FreeCAD
FreeCAD.Console.PrintMessage("This version " + __title__ + " rmu work with the FreeCAD 0.18 or higher. " + "\n\n")

import PySide2
from PySide2 import (QtWidgets, QtCore, QtGui)
from PySide2.QtWidgets import (QWidget, QApplication, QSlider, QGraphicsView, QGraphicsScene, QVBoxLayout, QStyle)
from PySide2.QtGui import (QPainter, QColor, QIcon)
#from PySide2.QtSvg import *
#import PySide2.QtXml
import WebGui


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
import Draft, Part, PartGui, FreeCADGui, FreeCAD
from FreeCAD import Base
from FreeCAD import Base
Line 102: Line 171:
Gui = FreeCADGui
Gui = FreeCADGui
App = FreeCAD
App = FreeCAD

global create2D ; create2D = 0
global ui ; ui = ""
global doc


try:
try:
Line 117: Line 190:
return QtGui.QApplication.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):
class Ui_MainWindow(object):


Line 138: Line 202:
self.thicknessY = 0.0 # extrusion
self.thicknessY = 0.0 # extrusion
self.thicknessZ = 0.0 # extrusion
self.thicknessZ = 0.0 # extrusion
self.thicknessD = 0.0 # extrusion


def setupUi(self, MainWindow):
def setupUi(self, MainWindow):
self.window = MainWindow
self.window = MainWindow
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.setObjectName(_fromUtf8("__title__"))
MainWindow.resize(171, 180)
MainWindow.resize(300, 300)
MainWindow.setMinimumSize(QtCore.QSize(171, 180))
# MainWindow.setMinimumSize(QtCore.QSize(300, 200))
MainWindow.setMaximumSize(QtCore.QSize(171, 180))
# MainWindow.setMaximumSize(QtCore.QSize(300, 200))
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget = QtWidgets.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.groupBox0 = QtWidgets.QGroupBox()
self.label_01.setGeometry(QtCore.QRect(10, 0, 151, 16))
self.groupBox_01 = QtWidgets.QGroupBox()
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 = QtWidgets.QDoubleSpinBox()
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.setMinimum(0)
self.doubleSpinBox.setMaximum(999999.999999)
self.doubleSpinBox.setMaximum(999999.999999)
self.doubleSpinBox.setDecimals(3)
self.doubleSpinBox.setDecimals(3)
self.doubleSpinBox.setValue(0.0)
self.doubleSpinBox.setValue(0.0)
self.doubleSpinBox.setAlignment(PySide2.QtCore.Qt.AlignCenter)
self.doubleSpinBox.setSuffix(" mm")
self.doubleSpinBox.valueChanged.connect(self.on_doubleSpinBox) ###
self.doubleSpinBox.valueChanged.connect(self.on_doubleSpinBox) ###
####
self.groupBox_02 = QtWidgets.QGroupBox()


self.checkBox_01 = QtGui.QCheckBox(self.centralwidget)
self.GroupBox_Bool = QtWidgets.QGroupBox()
self.RB_Intersection = QtWidgets.QRadioButton()
self.checkBox_01.setGeometry(QtCore.QRect(100, 23, 70, 17))
self.RB_Intersection.setIcon(QtGui.QIcon.fromTheme("bool",QtGui.QIcon(":/icons/Part_Common.svg")))
self.checkBox_01.setFont(self.fontGlobal_08) # pour compatibilite W L
self.checkBox_01.setObjectName(_fromUtf8("checkBox_01"))
self.RB_Intersection.setChecked(True)
self.checkBox_01.setChecked(False) # True
self.RB_Cut = QtWidgets.QRadioButton()
self.RB_Cut.setIcon(QtGui.QIcon.fromTheme("bool",QtGui.QIcon(":/icons/Part_Cut.svg")))
self.checkBox_01.setToolTip(_fromUtf8("Check this checkBox"+"\n"+
self.RB_Union = QtWidgets.QRadioButton()
"for create single object"))
self.RB_Union.setIcon(QtGui.QIcon.fromTheme("bool",QtGui.QIcon(":/icons/Part_Fuse.svg")))

self.FrameOp = QtGui.QFrame(self.centralwidget)
self.RB_Xor = QtWidgets.QRadioButton()
self.RB_Xor.setIcon(QtGui.QIcon.fromTheme("bool",QtGui.QIcon(":/icons/Part_XOR.svg")))
self.FrameOp.setGeometry(QtCore.QRect(10, 50, 81, 80))
####
self.FrameOp.setFrameShape(QtGui.QFrame.StyledPanel)
self.FrameOp.setFrameShadow(QtGui.QFrame.Raised)
self.groupBox_Axis = QtWidgets.QGroupBox()
self.FrameOp.setObjectName(_fromUtf8("FrameOp"))
self.RB_Axis_X = QtWidgets.QRadioButton()
self.RB_Axis_X.setIcon(QtGui.QIcon.fromTheme("axis",QtGui.QIcon(":/icons/Std_CoordinateSystem.svg")))

self.RB_Common = QtGui.QRadioButton(self.FrameOp)
self.RB_Axis_Y = QtWidgets.QRadioButton()
self.RB_Axis_Y.setIcon(QtGui.QIcon.fromTheme("axis",QtGui.QIcon(":/icons/Std_CoordinateSystem.svg")))
self.RB_Common.setGeometry(QtCore.QRect(10, 0, 82, 17))
self.RB_Axis_Z = QtWidgets.QRadioButton()
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.setChecked(True)
self.RB_Axis_Z.setToolTip(_fromUtf8("Plane XY extrude direction Z"))
self.RB_Axis_Z.setIcon(QtGui.QIcon.fromTheme("axis",QtGui.QIcon(":/icons/Std_CoordinateSystem.svg")))
self.RB_Axis_D = QtWidgets.QRadioButton()
self.RB_Axis_D.setEnabled(False)
self.RB_Axis_D.setIcon(QtGui.QIcon.fromTheme("axis",QtGui.QIcon(":/icons/Part_Line_Parametric.svg")))#Std_CoordinateSystem
####
self.groupBox_03 = QtWidgets.QGroupBox()
self.checkBox_01 = QtWidgets.QCheckBox()
self.checkBox_01.setChecked(True) # # False
self.checkBox_01.setIcon(QtGui.QIcon.fromTheme("part",QtGui.QIcon(":/icons/Tree_Part.svg")))
self.checkBox_01.clicked.connect(self.on_checkBox_01) ###


self.PB_Quit = QtGui.QPushButton(self.centralwidget)
self.CB_Create_2D_Visible = QtWidgets.QCheckBox()
self.PB_Quit.setGeometry(QtCore.QRect(10, 140, 73, 23))
self.CB_Create_2D_Visible.setChecked(True) # # False
self.CB_Create_2D_Visible.clicked.connect(self.on_CB_Create_2D_Visible) ###
self.PB_Quit.setFont(self.fontGlobal_08) # pour compatibilite W L
# self.CB_Create_2D_Visible.setIcon(QtGui.QIcon.fromTheme("draft",QtGui.QIcon(":/icons/dagViewVisible.svg")))#
self.PB_Quit.setObjectName(_fromUtf8("PB_Quit"))
self.PB_Quit.clicked.connect(self.on_PB_Quit) ###


self.PB_Create = QtGui.QPushButton(self.centralwidget)
self.CB_Colorer = QtWidgets.QCheckBox()
self.PB_Create.setGeometry(QtCore.QRect(90, 140, 73, 23))
self.CB_Colorer.setChecked(False) # True #
self.CB_Colorer.setIcon(QtGui.QIcon.fromTheme("part",QtGui.QIcon(":/icons/colors.svg")))
self.PB_Create.setFont(self.fontGlobal_08) # pour compatibilite W L
####
self.PB_Create.setObjectName(_fromUtf8("PB_Create"))
self.groupBox_04 = QtWidgets.QGroupBox()
self.PB_Create_2D = QtWidgets.QPushButton()
self.PB_Create_2D.clicked.connect(self.on_PB_Create_2D) ###
self.PB_Create_2D.setIcon(QIcon(QApplication.style().standardIcon(QStyle.SP_DialogOkButton))) #
self.PB_Create = QtWidgets.QPushButton()
self.PB_Create.clicked.connect(self.on_PB_Create) ###
self.PB_Create.clicked.connect(self.on_PB_Create) ###
self.PB_Create.setIcon(QIcon(QApplication.style().standardIcon(QStyle.SP_DialogOkButton))) #
self.PB_Help = QtWidgets.QPushButton()
self.PB_Help.clicked.connect(self.on_PB_Help) ###
self.PB_Help.setIcon(QIcon(QApplication.style().standardIcon(QStyle.SP_MessageBoxQuestion))) #
self.PB_Quit = QtWidgets.QPushButton()
self.PB_Quit.clicked.connect(self.on_PB_Quit) ###
self.PB_Quit.setIcon(QIcon(QApplication.style().standardIcon(QStyle.SP_DialogCloseButton))) #

####gridLayout####
self.gridLayout0 = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout0.setContentsMargins(10, 10, 10, 10)
self.gridLayout0.addWidget(self.groupBox0, 0, 0, 1, 1)
####
self.gridLayout = QtWidgets.QGridLayout(self.groupBox0)
self.gridLayout.setContentsMargins(10, 10, 10, 10)
####
self.gridLayout_02 = QtWidgets.QGridLayout(self.groupBox_01)
self.gridLayout_02.setContentsMargins(10, 10, 10, 10)
self.gridLayout_02.addWidget(self.doubleSpinBox, 0, 0, 1, 1)
self.gridLayout.addWidget(self.groupBox_01, 0, 0, 1, 2)
####
self.gridLayout_03 = QtWidgets.QGridLayout(self.groupBox_02)
self.gridLayout_03.setContentsMargins(10, 10, 10, 10)
self.gridLayout_03.addWidget(self.groupBox_02, 0, 0, 1, 1)
####
self.gridLayout_04 = QtWidgets.QGridLayout(self.GroupBox_Bool)
self.gridLayout_04.setContentsMargins(10, 10, 10, 10)
self.gridLayout_04.addWidget(self.RB_Intersection, 0, 0, 1, 1)
self.gridLayout_04.addWidget(self.RB_Cut, 1, 0, 1, 1)
self.gridLayout_04.addWidget(self.RB_Union, 2, 0, 1, 1)
self.gridLayout_04.addWidget(self.RB_Xor, 3, 0, 1, 1)
self.gridLayout_03.addWidget(self.GroupBox_Bool, 0, 0, 1, 1)
####
self.gridLayout_05 = QtWidgets.QGridLayout(self.groupBox_Axis)
self.gridLayout_05.setContentsMargins(10, 10, 10, 10)
self.gridLayout_05.addWidget(self.RB_Axis_X, 0, 0, 1, 1)
self.gridLayout_05.addWidget(self.RB_Axis_Y, 1, 0, 1, 1)
self.gridLayout_05.addWidget(self.RB_Axis_Z, 2, 0, 1, 1)
self.gridLayout_05.addWidget(self.RB_Axis_D, 3, 0, 1, 1)
self.gridLayout_03.addWidget(self.groupBox_Axis, 0, 1, 1, 1)
self.gridLayout.addWidget(self.groupBox_02, 1, 0, 1, 2)
####
self.gridLayout_06 = QtWidgets.QGridLayout(self.groupBox_03)
self.gridLayout_06.setContentsMargins(10, 10, 10, 10)
self.gridLayout_06.addWidget(self.checkBox_01, 0, 0, 1, 1)
self.gridLayout_06.addWidget(self.CB_Create_2D_Visible, 0, 1, 1, 1)
self.gridLayout_06.addWidget(self.CB_Colorer, 0, 2, 1, 1)
self.gridLayout.addWidget(self.groupBox_03, 2, 0, 1, 2)
####
self.gridLayout_07 = QtWidgets.QGridLayout(self.groupBox_04)
self.gridLayout_07.setContentsMargins(10, 10, 10, 10)
self.gridLayout_07.addWidget(self.PB_Create_2D, 0, 0, 1, 1)
self.gridLayout_07.addWidget(self.PB_Create, 0, 1, 1, 1)
self.gridLayout_07.addWidget(self.PB_Help, 1, 0, 1, 1)
self.gridLayout_07.addWidget(self.PB_Quit, 1, 1, 1, 1)
self.gridLayout.addWidget(self.groupBox_04, 3, 0, 1, 2)
####gridLayout####


MainWindow.setCentralWidget(self.centralwidget)
MainWindow.setCentralWidget(self.centralwidget)
Line 244: Line 333:


def retranslateUi(self, MainWindow):
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle("FCWire To Volume")
MainWindow.setWindowTitle("FCWire To Volume")
MainWindow.setWindowFlags(PySide2.QtCore.Qt.WindowStaysOnTopHint) # PySide2 cette fonction met la fenetre en avant
self.label_01.setText("FCWire To Volume")

self.checkBox_01.setText("Single")
self.groupBox0.setTitle(_translate("MainWindow", "Ver : " + __version__ + " : " + __date__) + " rmu") #__title__ + " " +
self.RB_Common.setText("Common")
self.RB_Substract.setText("Substract")
self.groupBox_01.setTitle(_translate("MainWindow", "Thickness Solide"))
self.RB_Union.setText("Union")
self.groupBox_02.setTitle(_translate("MainWindow", "Choice"))

self.RB_Difference.setText("Difference")
self.RB_Axis_X.setText( "X Axis")
self.GroupBox_Bool.setTitle(_translate("MainWindow", "Boolean"))
self.RB_Axis_Y.setText("Y Axis")
self.RB_Intersection.setText(_translate("MainWindow", "Intersection"))
self.RB_Axis_Z.setText("Z Axis")
self.RB_Cut.setText(_translate("MainWindow", "Substraction"))
self.PB_Quit.setText("Quit")
self.RB_Union.setText(_translate("MainWindow", "Union"))
self.PB_Create.setText("Create")
self.RB_Xor.setText(_translate("MainWindow", "Xor"))

self.groupBox_Axis.setTitle(_translate("MainWindow", "Axis"))
self.RB_Axis_X.setText(_translate("MainWindow", "X Axis"))
self.RB_Axis_X.setToolTip(_translate("MainWindow", "Plane YZ extrude direction X"))
self.RB_Axis_Y.setText(_translate("MainWindow", "Y Axis"))
self.RB_Axis_Y.setToolTip(_translate("MainWindow", "Plane XZ extrude direction Y"))
self.RB_Axis_Z.setText(_translate("MainWindow", "Z Axis"))
self.RB_Axis_Z.setToolTip(_translate("MainWindow", "Plane XY extrude direction Z"))
self.RB_Axis_D.setText(_translate("MainWindow", "Direction"))
self.RB_Axis_D.setToolTip(_translate("MainWindow", "Extrude direction (for later)"))

self.groupBox_03.setTitle(_translate("MainWindow", "Option"))
self.checkBox_01.setText(_translate("MainWindow", "Single object"))
self.checkBox_01.setToolTip(_translate("MainWindow", "Check this checkBox"+"\n"+
"for create single object"))
self.CB_Create_2D_Visible.setText(_translate("MainWindow", "Hidden"))
self.CB_Create_2D_Visible.setToolTip(_translate("MainWindow", "The object used are Hidden"))
self.CB_Colorer.setText(_translate("MainWindow", "Color"))
self.CB_Colorer.setToolTip(_translate("MainWindow", "If is checked the result is colored in red"))
self.groupBox_04.setTitle(_translate("MainWindow", "Command"))
self.PB_Create_2D.setText(_translate("MainWindow", "Create 2D"))
self.PB_Create_2D.setToolTip(_translate("MainWindow", "This button Create 2D object (Draft.makeShape2DView)" + "\n" +
"The projection is make in the Z axis" + "\n" +
"The selection order is decisive for the desired result (Substraction)"))
self.PB_Create.setText(_translate("MainWindow", "Create 3D"))
self.PB_Create.setToolTip(_translate("MainWindow", "Create the object 3D" + "\n" +
"The selection order is decisive for the desired result (Substraction)"))
self.PB_Help.setText(_translate("MainWindow", "Help"))
self.PB_Help.setToolTip(_translate("MainWindow", "Display the wiki page in the FreeCAD browser"))
self.PB_Quit.setText(_translate("MainWindow", "Quit"))
self.PB_Quit.setToolTip(_translate("MainWindow", "Quit Wire to volume, Salut"))


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):
def on_doubleSpinBox(self,value):
self.thicknessValue = value
self.thicknessValue = value
self.doubleSpinBox.setStyleSheet("Base")
self.PB_Create_2D.setStyleSheet("Base")
self.PB_Create.setStyleSheet("Base")


def on_PB_Quit(self): # Quit
def on_checkBox_01(self):
if self.checkBox_01.isChecked():
App.Console.PrintMessage(str("Fin FCWire To Volume ")+"\n")
self.checkBox_01.setIcon(QtGui.QIcon.fromTheme("part",QtGui.QIcon(":/icons/Tree_Part.svg")))
self.window.hide()
self.checkBox_01.setText(u"Single object")
else:
self.checkBox_01.setIcon(QtGui.QIcon.fromTheme("part",QtGui.QIcon(":/icons/sel-instance.svg")))
self.checkBox_01.setText(u"Objects")


def on_CB_Create_2D_Visible(self):
if self.CB_Create_2D_Visible.isChecked():
# self.CB_Create_2D_Visible.setIcon(QtGui.QIcon.fromTheme("draft",QtGui.QIcon(":/icons/dagViewVisible.svg")))#
self.CB_Create_2D_Visible.setIcon(QtGui.QIcon.fromTheme("part",QtGui.QIcon("")))
self.CB_Create_2D_Visible.setText(u"Hidden")
else:
self.CB_Create_2D_Visible.setIcon(QtGui.QIcon.fromTheme("part",QtGui.QIcon(":/icons/dagViewVisible.svg")))
self.CB_Create_2D_Visible.setText(u"Visible")

def on_PB_Create_2D(self):
global create2D
global ui

sel = FreeCADGui.Selection.getSelection()
self.PB_Create_2D.setStyleSheet("Base")
self.PB_Create.setStyleSheet("Base")
if len(sel) < 2:
create2D = 0
self.PB_Create_2D.setStyleSheet("background-color: white;\n"
"border:2px solid rgb(239, 41, 41);") # bord white and red
else:
create2D = 1
self.thicknessValue = 1.0
self.doubleSpinBox.setValue(self.thicknessValue)
self.RB_Axis_Z.setChecked(True)
ui.on_PB_Create()
def on_PB_Create(self):
def on_PB_Create(self):
global create2D
global doc

selectionObjects = FreeCADGui.Selection.getSelection()
selectionObjects = FreeCADGui.Selection.getSelection()
self.doubleSpinBox.setStyleSheet("Base")
self.PB_Create_2D.setStyleSheet("Base")
self.PB_Create.setStyleSheet("Base")
noface = 0
noface = 0
####
if create2D > 0:
lab00 = selectionObjects[0].Label
lab01 = selectionObjects[1].Label
boolChoice = ""
if self.RB_Intersection.isChecked():
boolChoice = "Comm"
elif self.RB_Cut.isChecked():
boolChoice = "Subs"
elif self.RB_Union.isChecked():
boolChoice = "Unio"
elif self.RB_Xor.isChecked():
boolChoice = "Diff"

if self.checkBox_01.isChecked():
None
else:
FCSpring = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup","Wire2D_" + lab00 + "_" + boolChoice + "_" +lab01)
####
try:
try:
selectedEdge = FreeCADGui.Selection.getSelectionEx()[0].SubObjects[0] # select one element SubObjects
selectedEdge = FreeCADGui.Selection.getSelectionEx()[0].SubObjects[0] # select one element SubObjects
Line 289: Line 465:
self.thicknessY = 0.0
self.thicknessY = 0.0
self.thicknessZ = 0.0
self.thicknessZ = 0.0
# self.thicknessD = 0.0
if self.RB_Axis_X.isChecked():
if self.RB_Axis_X.isChecked():
self.thicknessX = self.thicknessValue
self.thicknessX = self.thicknessValue
Line 296: Line 473:
if self.RB_Axis_Z.isChecked():
if self.RB_Axis_Z.isChecked():
self.thicknessZ = self.thicknessValue
self.thicknessZ = self.thicknessValue
# if self.RB_Axis_D.isChecked():
# self.thicknessD = self.thicknessValue
###########
###########
if (len(selectionObjects) >= 2) and (noface == 0) and (self.thicknessX + self.thicknessY + self.thicknessZ != 0.0):
if (len(selectionObjects) >= 2) and (noface == 0) and (self.thicknessX + self.thicknessY + self.thicknessZ != 0.0):
for i in selectionObjects: # duplicate object
for i in selectionObjects: # duplicate object
Line 310: Line 489:
p.append(a)
p.append(a)
if self.RB_Common.isChecked():
if self.RB_Intersection.isChecked():
name = "Common_" + selectionDuplicate[0].Label ## create Common_
name = "Common_" + selectionDuplicate[0].Label ## create Common_
tx = doc.addObject("Part::MultiCommon",name)
tx = doc.addObject("Part::MultiCommon",name)
Line 323: Line 502:
doc.removeObject(selectionDuplicate[i].Name)
doc.removeObject(selectionDuplicate[i].Name)
doc.removeObject(p[i].Name)
doc.removeObject(p[i].Name)
App.Console.PrintMessage("RB_Common ")
if self.CB_Colorer.isChecked():
FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (1.0,0.0,0.0)

elif self.RB_Substract.isChecked():
App.Console.PrintMessage("RB_Intersection ")
elif self.RB_Cut.isChecked():
name = str("Cut_" + selectionDuplicate[0].Label) ## create Cut_
name = str("Cut_" + selectionDuplicate[0].Label) ## create Cut_
tx = doc.addObject("Part::Cut",name)
tx = doc.addObject("Part::Cut",name)
Line 339: Line 520:
doc.removeObject(selectionDuplicate[i].Name)
doc.removeObject(selectionDuplicate[i].Name)
doc.removeObject(p[i].Name)
doc.removeObject(p[i].Name)
App.Console.PrintMessage("RB_Substract ")
if self.CB_Colorer.isChecked():
FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (1.0,0.0,0.0)
App.Console.PrintMessage("RB_Cut ")
elif self.RB_Union.isChecked():
elif self.RB_Union.isChecked():
Line 354: Line 537:
doc.removeObject(selectionDuplicate[i].Name)
doc.removeObject(selectionDuplicate[i].Name)
doc.removeObject(p[i].Name)
doc.removeObject(p[i].Name)
if self.CB_Colorer.isChecked():
FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (1.0,0.0,0.0)
App.Console.PrintMessage("RB_Union")
App.Console.PrintMessage("RB_Union")
elif self.RB_Difference.isChecked():
elif self.RB_Xor.isChecked():
name = "CommonD_" + selectionDuplicate[0].Label ##
name = "CommonD_" + selectionDuplicate[0].Label ##
commun = doc.addObject("Part::MultiCommon",name)
commun = doc.addObject("Part::MultiCommon",name)
Line 378: Line 563:
doc.removeObject(selectionDuplicate[i].Name)
doc.removeObject(selectionDuplicate[i].Name)
doc.removeObject(p[i].Name)
doc.removeObject(p[i].Name)
App.Console.PrintMessage("RB_Difference ")
if self.CB_Colorer.isChecked():
FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (1.0,0.0,0.0)
App.Console.PrintMessage("RB_Xor ")
doc.recompute()
doc.recompute()
Line 385: Line 572:
if (self.thicknessX + self.thicknessY + self.thicknessZ == 0.0):
if (self.thicknessX + self.thicknessY + self.thicknessZ == 0.0):
App.Console.PrintError("Thickness = 0" + "\n")
App.Console.PrintError("Thickness = 0" + "\n")
self.doubleSpinBox.setStyleSheet("background-color: white;\n"
"border:2px solid rgb(239, 41, 41);") # bord white and red
else:
else:
App.Console.PrintError("Not for Face" + "\n")
App.Console.PrintError("Not for Face" + "\n")
#### section 2D
if create2D > 0:
objSolid = App.ActiveDocument.getObject(FreeCAD.ActiveDocument.ActiveObject.Name)
objSolid.Label = "objSolid"
object2D = Draft.makeShape2DView(objSolid)
object2D.Label = "object2D"
FreeCAD.ActiveDocument.recompute()
Gui.Selection.clearSelection()
Gui.Selection.addSelection(object2D)
if self.CB_Create_2D_Visible.isChecked():
FreeCADGui.ActiveDocument.getObject(objSolid.Name).Visibility = False
else:
FreeCADGui.ActiveDocument.getObject(objSolid.Name).ShapeColor = (1.0,0.0,0.0)
FreeCADGui.ActiveDocument.getObject(objSolid.Name).Transparency = 80
if self.CB_Colorer.isChecked():
FreeCADGui.ActiveDocument.getObject(object2D.Name).LineColor = (1.0,0.0,0.0)
##### bon ordre pour effacer
if self.checkBox_01.isChecked():
Part.show(object2D.Shape.copy())
if self.CB_Colorer.isChecked():
FreeCADGui.ActiveDocument.ActiveObject.LineColor = (1.0,0.0,0.0)
App.ActiveDocument.ActiveObject.Label = ("Wire2D_" + lab00 + "_" + boolChoice + "_" +lab01)
doc.removeObject(object2D.Name)
doc.removeObject(objSolid.Name)
else:
FCSpring.addObject(objSolid)
FCSpring.addObject(object2D)
if self.CB_Create_2D_Visible.isChecked():
FreeCADGui.ActiveDocument.getObject(selectionObjects[0].Name).Visibility = False
FreeCADGui.ActiveDocument.getObject(selectionObjects[1].Name).Visibility = False
#### section 2D
create2D = 0
FreeCAD.ActiveDocument.recompute()
except Exception:
except Exception:
print "Wrong selection or operation"
print( "Wrong selection or operation")
self.PB_Create.setStyleSheet("background-color: white;\n"
"border:2px solid rgb(239, 41, 41);") # bord white and red


def on_PB_Help(self): #
#______________________________________________________________________________________
WebGui.openBrowser("https://wiki.freecadweb.org/Macro_FCWire_To_Volume")
App.Console.PrintMessage("https://wiki.freecadweb.org/Macro_FCWire_To_Volume" + "\n")

def on_PB_Quit(self): # Quit
App.Console.PrintMessage(str("Fin FCWire To Volume ")+"\n")
self.window.hide()

####


doc = FreeCAD.ActiveDocument
doc = FreeCAD.ActiveDocument
Line 396: Line 636:
doc = FreeCAD.newDocument()
doc = FreeCAD.newDocument()


MainWindow = QtGui.QMainWindow()
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
ui.setupUi(MainWindow)
Line 403: Line 643:
}}
}}
<translate>
<translate>

==Exemple== <!--T:30-->

</translate>
<center>
<gallery widths="300" heights="280">
File:Macro FCWire To Volume 01.png|Example 3D
</gallery>
</center>

<center>
<gallery widths="300" heights="280">
Image:Macro FCWire To Volume 02.png|Example 2D
Image:Macro FCWire To Volume 03.png|Common
</gallery>
</center>

<center>
<gallery widths="300" heights="280">
Image:Macro FCWire To Volume 04.png|Example 2D
Image:Macro FCWire To Volume 05.png|Union
</gallery>
</center>
<translate>

==Link== <!--T:8-->
==Link== <!--T:8-->

<!--T:31-->
The tread in the forum [http://forum.freecadweb.org/viewtopic.php?f=3&t=16570&start=50 Bunch of issues/questions]
The tread in the forum [http://forum.freecadweb.org/viewtopic.php?f=3&t=16570&start=50 Bunch of issues/questions]

==Version== <!--T:32-->

<!--T:36-->
ver 02c: 11/04/2020 : correct typo "Printmessage" to "PrintMessage"

<!--T:33-->
ver 02b: 10/04/2020 : adding icons and help button

<!--T:34-->
ver 02 : 07/04/2020 : convert for PySide2 Qt5 and layout, adding the 2D (contour) wire

<!--T:35-->
ver 01 : 10/10/2016 :

</translate>
</translate>
<languages/>

Latest revision as of 23:37, 7 May 2020

Other languages:

Macro FCWire To Volume

Description
Create the boolean operation with the selected wires. Push the 2d button for create the boolean operation to 2D wire.

Macro version: 0.02c
Last modified: 2020/04/11
FreeCAD version: 0.19
Download: ToolBar Icon
Author: Mario52
Author
Mario52
Download
ToolBar Icon
Links
Macro Version
0.02c
Date last modified
2020/04/11
FreeCAD Version(s)
0.19
Default shortcut
None
See also
None

Description

This macro create on object boolean with the object Draft selected.

Uses

Select the wires objects, enter the thickness choice the operation desired and click the button Create. Push the 2d button for create the boolean operation to 2D wire.

Thickness Solide

  • SpinBox  : Give the thickness

Choice

Boolean

Intersection : Boolean operation

Substraction : Boolean operation

Union : Boolean operation

Xor : Boolean operation

Axis

X Axis : Axis X

Y Axis : Axis Y

Z Axis : Axis Z (default)

Direction : (Not functional Later)

Option

Single object : If the checkBox is checked the object is on single object, if not the object created conserve the hierarchy of the construction the object

Hidden : The original object are hidden

Color : If it checked the object resultant is coloured in red

Command

  • Create 2D : Create the Boolean object 2D (contour wire with Draft.makeShape2DView())
  • Create 3D : Create the Boolean object 3D (solid)
  • Help : Connect to the wiki page (in FreeCAD browser)
  • Quit : Quit the macro


Script

Copy the macro in your macro folder.

The icon for the tool bar

Macro_FCWire_To_Volume.FCMacro

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
#
"""
***************************************************************************
*   Copyright (c) 2016 2017 2018 2019 2020 <mario52>                      *
*                                                                         *
*   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.                                 *
**                                                                       **
*   Use at your own risk. The author assumes no liability for data loss.  *
*              It is advised to backup your data frequently.              *
*             If you do not trust the software do not use it.             *
**                                                                       **
*   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, 2020/04/08_02, 2020/04/10_2b, 2020/04/11_2c
#
#OS: Windows 10 (10.0)
#Word size of OS: 64-bit
#Word size of FreeCAD: 64-bit
#Version: 0.19.20311 (Git)
#Build type: Release
#Branch: master
#Hash: 915e551bbb7e3614bc804f1ae1f65027b5432b9f
#Python version: 3.6.8
#Qt version: 5.12.1
#Coin version: 4.0.0a
#OCC version: 7.3.0
#
__title__   = "Macro_FCWire_To_Volume"
__author__  = "Mario52"
__url__     = "https://wiki.freecadweb.org/Macro_FCWire_To_Volume"
__version__ = "00.02c"
__date__    = "2020/04/11"    #YYYY/MM/DD

if int(FreeCAD.Version()[1]) < 18:      # Version de FreeCAD
    FreeCAD.Console.PrintMessage("This version " + __title__ + " rmu  work with the FreeCAD 0.18 or higher. " + "\n\n")

import PySide2
from PySide2 import (QtWidgets, QtCore, QtGui)
from PySide2.QtWidgets import (QWidget, QApplication, QSlider, QGraphicsView, QGraphicsScene, QVBoxLayout, QStyle)
from PySide2.QtGui import (QPainter, QColor, QIcon)
#from PySide2.QtSvg import *
#import PySide2.QtXml
import WebGui

import Draft, Part, PartGui, FreeCADGui, FreeCAD
from FreeCAD import Base
import math
from math import sqrt, pi, sin, cos, asin

Gui = FreeCADGui
App = FreeCAD

global create2D ; create2D = 0
global ui       ; ui       = ""
global doc

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)

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
        self.thicknessD      = 0.0     # extrusion

    def setupUi(self, MainWindow):
        self.window = MainWindow
        MainWindow.setObjectName(_fromUtf8("__title__"))
        MainWindow.resize(300, 300)
#        MainWindow.setMinimumSize(QtCore.QSize(300, 200))
#        MainWindow.setMaximumSize(QtCore.QSize(300, 200))
        self.centralwidget = QtWidgets.QWidget(MainWindow)

        self.groupBox0 = QtWidgets.QGroupBox()
        self.groupBox_01 = QtWidgets.QGroupBox()

        self.doubleSpinBox = QtWidgets.QDoubleSpinBox()
        self.doubleSpinBox.setMinimum(0)
        self.doubleSpinBox.setMaximum(999999.999999)
        self.doubleSpinBox.setDecimals(3)
        self.doubleSpinBox.setValue(0.0)
        self.doubleSpinBox.setAlignment(PySide2.QtCore.Qt.AlignCenter)
        self.doubleSpinBox.setSuffix(" mm")
        self.doubleSpinBox.valueChanged.connect(self.on_doubleSpinBox) ###
        ####
        self.groupBox_02 = QtWidgets.QGroupBox()

        self.GroupBox_Bool = QtWidgets.QGroupBox()
        self.RB_Intersection = QtWidgets.QRadioButton()
        self.RB_Intersection.setIcon(QtGui.QIcon.fromTheme("bool",QtGui.QIcon(":/icons/Part_Common.svg")))
        self.RB_Intersection.setChecked(True)
        self.RB_Cut = QtWidgets.QRadioButton()
        self.RB_Cut.setIcon(QtGui.QIcon.fromTheme("bool",QtGui.QIcon(":/icons/Part_Cut.svg")))
        self.RB_Union = QtWidgets.QRadioButton()
        self.RB_Union.setIcon(QtGui.QIcon.fromTheme("bool",QtGui.QIcon(":/icons/Part_Fuse.svg")))
        self.RB_Xor = QtWidgets.QRadioButton()
        self.RB_Xor.setIcon(QtGui.QIcon.fromTheme("bool",QtGui.QIcon(":/icons/Part_XOR.svg")))
        ####
        self.groupBox_Axis = QtWidgets.QGroupBox()
        self.RB_Axis_X = QtWidgets.QRadioButton()
        self.RB_Axis_X.setIcon(QtGui.QIcon.fromTheme("axis",QtGui.QIcon(":/icons/Std_CoordinateSystem.svg")))
        self.RB_Axis_Y = QtWidgets.QRadioButton()
        self.RB_Axis_Y.setIcon(QtGui.QIcon.fromTheme("axis",QtGui.QIcon(":/icons/Std_CoordinateSystem.svg")))
        self.RB_Axis_Z = QtWidgets.QRadioButton()
        self.RB_Axis_Z.setChecked(True)
        self.RB_Axis_Z.setIcon(QtGui.QIcon.fromTheme("axis",QtGui.QIcon(":/icons/Std_CoordinateSystem.svg")))
        self.RB_Axis_D = QtWidgets.QRadioButton()
        self.RB_Axis_D.setEnabled(False)
        self.RB_Axis_D.setIcon(QtGui.QIcon.fromTheme("axis",QtGui.QIcon(":/icons/Part_Line_Parametric.svg")))#Std_CoordinateSystem
        ####
        self.groupBox_03 = QtWidgets.QGroupBox()
        self.checkBox_01 = QtWidgets.QCheckBox()
        self.checkBox_01.setChecked(True)             #  # False
        self.checkBox_01.setIcon(QtGui.QIcon.fromTheme("part",QtGui.QIcon(":/icons/Tree_Part.svg")))
        self.checkBox_01.clicked.connect(self.on_checkBox_01) ###

        self.CB_Create_2D_Visible = QtWidgets.QCheckBox()
        self.CB_Create_2D_Visible.setChecked(True)    #    # False
        self.CB_Create_2D_Visible.clicked.connect(self.on_CB_Create_2D_Visible) ###
#        self.CB_Create_2D_Visible.setIcon(QtGui.QIcon.fromTheme("draft",QtGui.QIcon(":/icons/dagViewVisible.svg")))#

        self.CB_Colorer = QtWidgets.QCheckBox()
        self.CB_Colorer.setChecked(False)             # True   # 
        self.CB_Colorer.setIcon(QtGui.QIcon.fromTheme("part",QtGui.QIcon(":/icons/colors.svg")))
        ####
        self.groupBox_04 = QtWidgets.QGroupBox()
        self.PB_Create_2D = QtWidgets.QPushButton()
        self.PB_Create_2D.clicked.connect(self.on_PB_Create_2D) ###
        self.PB_Create_2D.setIcon(QIcon(QApplication.style().standardIcon(QStyle.SP_DialogOkButton))) #
        self.PB_Create = QtWidgets.QPushButton()
        self.PB_Create.clicked.connect(self.on_PB_Create) ###
        self.PB_Create.setIcon(QIcon(QApplication.style().standardIcon(QStyle.SP_DialogOkButton))) #
        self.PB_Help = QtWidgets.QPushButton()
        self.PB_Help.clicked.connect(self.on_PB_Help) ###
        self.PB_Help.setIcon(QIcon(QApplication.style().standardIcon(QStyle.SP_MessageBoxQuestion))) #
        self.PB_Quit = QtWidgets.QPushButton()
        self.PB_Quit.clicked.connect(self.on_PB_Quit) ###
        self.PB_Quit.setIcon(QIcon(QApplication.style().standardIcon(QStyle.SP_DialogCloseButton))) #

        ####gridLayout####
        self.gridLayout0 = QtWidgets.QGridLayout(self.centralwidget)
        self.gridLayout0.setContentsMargins(10, 10, 10, 10)
        self.gridLayout0.addWidget(self.groupBox0, 0, 0, 1, 1)
        ####
        self.gridLayout = QtWidgets.QGridLayout(self.groupBox0)
        self.gridLayout.setContentsMargins(10, 10, 10, 10)
        ####
        self.gridLayout_02 = QtWidgets.QGridLayout(self.groupBox_01)
        self.gridLayout_02.setContentsMargins(10, 10, 10, 10)
        self.gridLayout_02.addWidget(self.doubleSpinBox, 0, 0, 1, 1)
        self.gridLayout.addWidget(self.groupBox_01, 0, 0, 1, 2)
        ####
        self.gridLayout_03 = QtWidgets.QGridLayout(self.groupBox_02)
        self.gridLayout_03.setContentsMargins(10, 10, 10, 10)
        self.gridLayout_03.addWidget(self.groupBox_02, 0, 0, 1, 1)
        ####
        self.gridLayout_04 = QtWidgets.QGridLayout(self.GroupBox_Bool)
        self.gridLayout_04.setContentsMargins(10, 10, 10, 10)
        self.gridLayout_04.addWidget(self.RB_Intersection, 0, 0, 1, 1)
        self.gridLayout_04.addWidget(self.RB_Cut, 1, 0, 1, 1)
        self.gridLayout_04.addWidget(self.RB_Union, 2, 0, 1, 1)
        self.gridLayout_04.addWidget(self.RB_Xor, 3, 0, 1, 1)
        self.gridLayout_03.addWidget(self.GroupBox_Bool, 0, 0, 1, 1)
        ####
        self.gridLayout_05 = QtWidgets.QGridLayout(self.groupBox_Axis)
        self.gridLayout_05.setContentsMargins(10, 10, 10, 10)
        self.gridLayout_05.addWidget(self.RB_Axis_X, 0, 0, 1, 1)
        self.gridLayout_05.addWidget(self.RB_Axis_Y, 1, 0, 1, 1)
        self.gridLayout_05.addWidget(self.RB_Axis_Z, 2, 0, 1, 1)
        self.gridLayout_05.addWidget(self.RB_Axis_D, 3, 0, 1, 1)
        self.gridLayout_03.addWidget(self.groupBox_Axis, 0, 1, 1, 1)
        self.gridLayout.addWidget(self.groupBox_02, 1, 0, 1, 2)
        ####
        self.gridLayout_06 = QtWidgets.QGridLayout(self.groupBox_03)
        self.gridLayout_06.setContentsMargins(10, 10, 10, 10)
        self.gridLayout_06.addWidget(self.checkBox_01, 0, 0, 1, 1)
        self.gridLayout_06.addWidget(self.CB_Create_2D_Visible, 0, 1, 1, 1)
        self.gridLayout_06.addWidget(self.CB_Colorer, 0, 2, 1, 1)
        self.gridLayout.addWidget(self.groupBox_03, 2, 0, 1, 2)
        ####
        self.gridLayout_07 = QtWidgets.QGridLayout(self.groupBox_04)
        self.gridLayout_07.setContentsMargins(10, 10, 10, 10)
        self.gridLayout_07.addWidget(self.PB_Create_2D, 0, 0, 1, 1)
        self.gridLayout_07.addWidget(self.PB_Create, 0, 1, 1, 1)
        self.gridLayout_07.addWidget(self.PB_Help, 1, 0, 1, 1)
        self.gridLayout_07.addWidget(self.PB_Quit, 1, 1, 1, 1)
        self.gridLayout.addWidget(self.groupBox_04, 3, 0, 1, 2)
        ####gridLayout####

        MainWindow.setCentralWidget(self.centralwidget)
        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle("FCWire To Volume")
        MainWindow.setWindowFlags(PySide2.QtCore.Qt.WindowStaysOnTopHint)        # PySide2 cette fonction met la fenetre en avant

        self.groupBox0.setTitle(_translate("MainWindow", "Ver : " + __version__ + " : " + __date__) + " rmu") #__title__ + " " +
        self.groupBox_01.setTitle(_translate("MainWindow", "Thickness Solide"))
        self.groupBox_02.setTitle(_translate("MainWindow", "Choice"))

        self.GroupBox_Bool.setTitle(_translate("MainWindow", "Boolean"))
        self.RB_Intersection.setText(_translate("MainWindow", "Intersection"))
        self.RB_Cut.setText(_translate("MainWindow", "Substraction"))
        self.RB_Union.setText(_translate("MainWindow", "Union"))
        self.RB_Xor.setText(_translate("MainWindow", "Xor"))

        self.groupBox_Axis.setTitle(_translate("MainWindow", "Axis"))
        self.RB_Axis_X.setText(_translate("MainWindow", "X Axis"))
        self.RB_Axis_X.setToolTip(_translate("MainWindow", "Plane YZ extrude direction X"))
        self.RB_Axis_Y.setText(_translate("MainWindow", "Y Axis"))
        self.RB_Axis_Y.setToolTip(_translate("MainWindow", "Plane XZ extrude direction Y"))
        self.RB_Axis_Z.setText(_translate("MainWindow", "Z Axis"))
        self.RB_Axis_Z.setToolTip(_translate("MainWindow", "Plane XY extrude direction Z"))
        self.RB_Axis_D.setText(_translate("MainWindow", "Direction"))
        self.RB_Axis_D.setToolTip(_translate("MainWindow", "Extrude direction (for later)"))

        self.groupBox_03.setTitle(_translate("MainWindow", "Option"))
        self.checkBox_01.setText(_translate("MainWindow", "Single object"))
        self.checkBox_01.setToolTip(_translate("MainWindow", "Check this checkBox"+"\n"+
                                               "for create single object"))
        self.CB_Create_2D_Visible.setText(_translate("MainWindow", "Hidden"))
        self.CB_Create_2D_Visible.setToolTip(_translate("MainWindow", "The object used are Hidden"))
        self.CB_Colorer.setText(_translate("MainWindow", "Color"))
        self.CB_Colorer.setToolTip(_translate("MainWindow", "If is checked the result is colored in red"))
        self.groupBox_04.setTitle(_translate("MainWindow", "Command"))
        self.PB_Create_2D.setText(_translate("MainWindow", "Create 2D"))
        self.PB_Create_2D.setToolTip(_translate("MainWindow", "This button Create 2D object (Draft.makeShape2DView)" + "\n" +
                                                "The projection is make in the Z axis" + "\n" +
                                                "The selection order is decisive for the desired result (Substraction)"))
        self.PB_Create.setText(_translate("MainWindow", "Create 3D"))
        self.PB_Create.setToolTip(_translate("MainWindow", "Create the object 3D" + "\n" +
                                             "The selection order is decisive for the desired result (Substraction)"))
        self.PB_Help.setText(_translate("MainWindow", "Help"))
        self.PB_Help.setToolTip(_translate("MainWindow", "Display the wiki page in the FreeCAD browser"))
        self.PB_Quit.setText(_translate("MainWindow", "Quit"))
        self.PB_Quit.setToolTip(_translate("MainWindow", "Quit Wire to volume, Salut"))


    def on_doubleSpinBox(self,value):
        self.thicknessValue = value
        self.doubleSpinBox.setStyleSheet("Base")
        self.PB_Create_2D.setStyleSheet("Base")
        self.PB_Create.setStyleSheet("Base")

    def on_checkBox_01(self):
        if self.checkBox_01.isChecked():
            self.checkBox_01.setIcon(QtGui.QIcon.fromTheme("part",QtGui.QIcon(":/icons/Tree_Part.svg")))
            self.checkBox_01.setText(u"Single object")
        else:
            self.checkBox_01.setIcon(QtGui.QIcon.fromTheme("part",QtGui.QIcon(":/icons/sel-instance.svg")))
            self.checkBox_01.setText(u"Objects")

    def on_CB_Create_2D_Visible(self):
        if self.CB_Create_2D_Visible.isChecked():
#            self.CB_Create_2D_Visible.setIcon(QtGui.QIcon.fromTheme("draft",QtGui.QIcon(":/icons/dagViewVisible.svg")))#
            self.CB_Create_2D_Visible.setIcon(QtGui.QIcon.fromTheme("part",QtGui.QIcon("")))
            self.CB_Create_2D_Visible.setText(u"Hidden")
        else:
            self.CB_Create_2D_Visible.setIcon(QtGui.QIcon.fromTheme("part",QtGui.QIcon(":/icons/dagViewVisible.svg")))
            self.CB_Create_2D_Visible.setText(u"Visible")

    def on_PB_Create_2D(self):
        global create2D
        global ui

        sel = FreeCADGui.Selection.getSelection()
        self.PB_Create_2D.setStyleSheet("Base")
        self.PB_Create.setStyleSheet("Base")
        if len(sel) < 2:
            create2D = 0
            self.PB_Create_2D.setStyleSheet("background-color: white;\n"
                                            "border:2px solid rgb(239, 41, 41);")  # bord white and red
        else:
            create2D = 1
            self.thicknessValue = 1.0
            self.doubleSpinBox.setValue(self.thicknessValue)
            self.RB_Axis_Z.setChecked(True)
            ui.on_PB_Create()
        
    def on_PB_Create(self):
        global create2D
        global doc

        selectionObjects = FreeCADGui.Selection.getSelection()
        self.doubleSpinBox.setStyleSheet("Base")
        self.PB_Create_2D.setStyleSheet("Base")
        self.PB_Create.setStyleSheet("Base")
        noface = 0
        ####
        if create2D > 0:
            lab00 = selectionObjects[0].Label
            lab01 = selectionObjects[1].Label
            boolChoice = ""
            if self.RB_Intersection.isChecked():
                boolChoice = "Comm"
            elif self.RB_Cut.isChecked():
                boolChoice = "Subs"
            elif self.RB_Union.isChecked():
                boolChoice = "Unio"
            elif self.RB_Xor.isChecked():
                boolChoice = "Diff"

            if self.checkBox_01.isChecked():
                None
            else:
                FCSpring = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup","Wire2D_" + lab00 + "_" + boolChoice + "_" +lab01)
        ####
        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
        #        self.thicknessD = 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 self.RB_Axis_D.isChecked():
        #            self.thicknessD = self.thicknessValue
            ###########
        
            if (len(selectionObjects) >= 2) and (noface == 0) and (self.thicknessX + self.thicknessY + self.thicknessZ != 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_Intersection.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)
                    if self.CB_Colorer.isChecked():
                        FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (1.0,0.0,0.0)
                    App.Console.PrintMessage("RB_Intersection ")
        
                elif self.RB_Cut.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)
                    if self.CB_Colorer.isChecked():
                        FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (1.0,0.0,0.0)
                    App.Console.PrintMessage("RB_Cut ")
            
                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)
                    if self.CB_Colorer.isChecked():
                        FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (1.0,0.0,0.0)
                    App.Console.PrintMessage("RB_Union")
            
                elif self.RB_Xor.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)
                    if self.CB_Colorer.isChecked():
                        FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (1.0,0.0,0.0)
                    App.Console.PrintMessage("RB_Xor ")
            
                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")
                    self.doubleSpinBox.setStyleSheet("background-color: white;\n"
                                                     "border:2px solid rgb(239, 41, 41);")  # bord white and red
                else:
                    App.Console.PrintError("Not for Face" + "\n")
        
            #### section 2D
            if create2D > 0:
                objSolid = App.ActiveDocument.getObject(FreeCAD.ActiveDocument.ActiveObject.Name)
                objSolid.Label = "objSolid"
        
                object2D = Draft.makeShape2DView(objSolid)
                object2D.Label = "object2D"
                FreeCAD.ActiveDocument.recompute()
        
                Gui.Selection.clearSelection()
                Gui.Selection.addSelection(object2D)
        
                if self.CB_Create_2D_Visible.isChecked():
                    FreeCADGui.ActiveDocument.getObject(objSolid.Name).Visibility = False
                else:
                    FreeCADGui.ActiveDocument.getObject(objSolid.Name).ShapeColor = (1.0,0.0,0.0)
                    FreeCADGui.ActiveDocument.getObject(objSolid.Name).Transparency = 80
        
                if self.CB_Colorer.isChecked():
                    FreeCADGui.ActiveDocument.getObject(object2D.Name).LineColor = (1.0,0.0,0.0)
        
                ##### bon ordre pour effacer
                if self.checkBox_01.isChecked():
                    Part.show(object2D.Shape.copy())
                    if self.CB_Colorer.isChecked():
                        FreeCADGui.ActiveDocument.ActiveObject.LineColor = (1.0,0.0,0.0)
                    App.ActiveDocument.ActiveObject.Label = ("Wire2D_" + lab00 + "_" + boolChoice + "_" +lab01)
                    doc.removeObject(object2D.Name)
                    doc.removeObject(objSolid.Name)
                else:
                    FCSpring.addObject(objSolid)
                    FCSpring.addObject(object2D)
        
            if self.CB_Create_2D_Visible.isChecked():
                FreeCADGui.ActiveDocument.getObject(selectionObjects[0].Name).Visibility = False
                FreeCADGui.ActiveDocument.getObject(selectionObjects[1].Name).Visibility = False
            #### section 2D
        
            create2D = 0
            FreeCAD.ActiveDocument.recompute()
        except Exception:
            print( "Wrong selection or operation")
            self.PB_Create.setStyleSheet("background-color: white;\n"
                                         "border:2px solid rgb(239, 41, 41);")  # bord white and red

    def on_PB_Help(self): # 
        WebGui.openBrowser("https://wiki.freecadweb.org/Macro_FCWire_To_Volume")
        App.Console.PrintMessage("https://wiki.freecadweb.org/Macro_FCWire_To_Volume" + "\n")

    def on_PB_Quit(self):                        # Quit
        App.Console.PrintMessage(str("Fin FCWire To Volume ")+"\n")
        self.window.hide()

    ####

doc = FreeCAD.ActiveDocument
if doc == None:
    doc = FreeCAD.newDocument()

MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()

Exemple

Link

The tread in the forum Bunch of issues/questions

Version

ver 02c: 11/04/2020 : correct typo "Printmessage" to "PrintMessage"

ver 02b: 10/04/2020 : adding icons and help button

ver 02 : 07/04/2020 : convert for PySide2 Qt5 and layout, adding the 2D (contour) wire

ver 01 : 10/10/2016 :