Macro FCWire To Volume: Difference between revisions
m (icon) |
(version 0.2) |
||
Line 5: | Line 5: | ||
|Name=Macro FCWire To Volume |
|Name=Macro FCWire To Volume |
||
|Icon=Macro_FCWire_To_Volume.png |
|Icon=Macro_FCWire_To_Volume.png |
||
|Description=Create the boolean operation with the selected wires |
|Description=Create the boolean operation with the selected wires. Push the 2d button for create the boolean operation to 2D wire. |
||
|Author=Mario52 |
|Author=Mario52 |
||
|Version= |
|Version=2.0 |
||
|Date= |
|Date=2020-04-08 |
||
|FCVersion= |
|FCVersion=0.19 |
||
|Download=[https://www.freecadweb.org/wiki/images/f/f2/Macro_FCWire_To_Volume.png ToolBar Icon] |
|Download=[https://www.freecadweb.org/wiki/images/f/f2/Macro_FCWire_To_Volume.png ToolBar Icon] |
||
}} |
}} |
||
Line 21: | Line 21: | ||
==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. |
||
</translate> |
</translate> |
||
Line 52: | Line 52: | ||
""" |
""" |
||
*************************************************************************** |
*************************************************************************** |
||
* Copyright (c) 2016 |
* 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 61: | Line 61: | ||
* 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 76: | Line 80: | ||
*************************************************************************** |
*************************************************************************** |
||
""" |
""" |
||
#Macro_FCWire_To_Volume 10/10/2016_01 |
#Macro_FCWire_To_Volume 10/10/2016_01, 2020/04/08_02, |
||
# |
# |
||
#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. |
#Version: 0.19.20311 (Git) |
||
#Build type: Release |
#Build type: Release |
||
#Branch: |
#Branch: master |
||
#Hash: 915e551bbb7e3614bc804f1ae1f65027b5432b9f |
|||
#Hash: f86a4e411ff7848dea98d7242f43b7774bee8fa0 |
|||
#Python version: |
#Python version: 3.6.8 |
||
#Qt version: |
#Qt version: 5.12.1 |
||
#Coin version: 4.0.0a |
#Coin version: 4.0.0a |
||
#OCC version: |
#OCC version: 7.3.0 |
||
# |
# |
||
__title__ = "Macro_FCWire_To_Volume" |
__title__ = "Macro_FCWire_To_Volume" |
||
__author__ = "Mario52" |
__author__ = "Mario52" |
||
__url__ = " |
__url__ = "https://wiki.freecadweb.org/Macro_FCWire_To_Volume" |
||
__version__ = "00. |
__version__ = "00.02" |
||
__date__ = " |
__date__ = "2020/04/08" #YYYY/MM/DD |
||
if int(FreeCAD.Version()[1]) < 18: # Version de FreeCAD |
|||
try: |
|||
FreeCAD.Console.Printmessage("This version " + __title__ + " rmu work with the FreeCAD 0.18 or higher. " + "\n\n") |
|||
import PyQt4 |
|||
from PyQt4 import QtGui ,QtCore |
|||
import PySide2 |
|||
from PyQt4.QtGui import * |
|||
from PySide2 import (QtWidgets, QtCore, QtGui) |
|||
from PyQt4.QtCore import * |
|||
from PySide2.QtWidgets import (QWidget, QApplication, QSlider, QGraphicsView, QGraphicsScene, QVBoxLayout, QStyle) |
|||
except Exception: |
|||
#from PySide2.QtGui import (QPainter, QColor, QIcon) |
|||
import PySide |
|||
#from PySide2.QtSvg import * |
|||
#import PySide2.QtXml |
|||
from PySide.QtGui import * |
|||
from PySide.QtCore import * |
|||
import Draft, Part, PartGui, FreeCADGui, FreeCAD |
import Draft, Part, PartGui, FreeCADGui, FreeCAD |
||
Line 114: | Line 117: | ||
Gui = FreeCADGui |
Gui = FreeCADGui |
||
App = FreeCAD |
App = FreeCAD |
||
global create2D ; create2D = 0 |
|||
global ui ; ui = "" |
|||
global doc |
|||
try: |
try: |
||
Line 129: | Line 136: | ||
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 150: | Line 148: | ||
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.setObjectName(_fromUtf8("__title__")) |
||
MainWindow.resize( |
MainWindow.resize(300, 300) |
||
MainWindow.setMinimumSize(QtCore.QSize( |
# MainWindow.setMinimumSize(QtCore.QSize(300, 200)) |
||
MainWindow.setMaximumSize(QtCore.QSize( |
# MainWindow.setMaximumSize(QtCore.QSize(300, 200)) |
||
self.centralwidget = |
self.centralwidget = QtWidgets.QWidget(MainWindow) |
||
self.centralwidget.setObjectName(_fromUtf8("centralwidget")) |
|||
self.groupBox0 = QtWidgets.QGroupBox() |
|||
self.fontGlobal_08 = QtGui.QFont() # pour compatibilite Windows Linux pour tous les textes |
|||
self.groupBox_01 = QtWidgets.QGroupBox() |
|||
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. |
self.doubleSpinBox = QtWidgets.QDoubleSpinBox() |
||
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.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.checkBox_01 = |
self.checkBox_01 = QtWidgets.QCheckBox() |
||
self.checkBox_01. |
self.checkBox_01.setChecked(True) # # False |
||
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. |
self.groupBox_02 = QtWidgets.QGroupBox() |
||
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. |
self.GroupBox_Bool = QtWidgets.QGroupBox() |
||
self.RB_Common. |
self.RB_Common = QtWidgets.QRadioButton() |
||
self.RB_Common.setFont(self.fontGlobal_08) # pour compatibilite W L |
|||
self.RB_Common.setChecked(True) |
self.RB_Common.setChecked(True) |
||
self. |
self.RB_Substract = QtWidgets.QRadioButton() |
||
self.RB_Union = QtWidgets.QRadioButton() |
|||
self.RB_Difference = QtWidgets.QRadioButton() |
|||
self. |
self.groupBox_Axis = QtWidgets.QGroupBox() |
||
self. |
self.RB_Axis_X = QtWidgets.QRadioButton() |
||
self.RB_Axis_Y = QtWidgets.QRadioButton() |
|||
self.RB_Substract.setFont(self.fontGlobal_08) # pour compatibilite W L |
|||
self. |
self.RB_Axis_Z = QtWidgets.QRadioButton() |
||
self.RB_Axis_Z.setChecked(True) |
|||
self.RB_Axis_D = QtWidgets.QRadioButton() |
|||
self.RB_Axis_D.setEnabled(False) |
|||
self. |
self.groupBox_03 = QtWidgets.QGroupBox() |
||
self.CB_Create_2D_Visible = QtWidgets.QCheckBox() |
|||
self.RB_Union.setGeometry(QtCore.QRect(10, 40, 82, 17)) |
|||
self. |
self.CB_Create_2D_Visible.setChecked(True) # # fALSE |
||
self. |
self.CB_Colorer = QtWidgets.QCheckBox() |
||
self.CB_Colorer.setChecked(False) # True # |
|||
self.PB_Create_2D = QtWidgets.QPushButton() |
|||
self.PB_Create_2D.clicked.connect(self.on_PB_Create_2D) ### |
|||
self. |
self.groupBox_04 = QtWidgets.QGroupBox() |
||
self. |
self.PB_Quit = QtWidgets.QPushButton() |
||
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_Quit.clicked.connect(self.on_PB_Quit) ### |
||
self.PB_Create = QtWidgets.QPushButton() |
|||
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) ### |
self.PB_Create.clicked.connect(self.on_PB_Create) ### |
||
####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_Common, 0, 0, 1, 1) |
|||
self.gridLayout_04.addWidget(self.RB_Substract, 1, 0, 1, 1) |
|||
self.gridLayout_04.addWidget(self.RB_Union, 2, 0, 1, 1) |
|||
self.gridLayout_04.addWidget(self.RB_Difference, 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_Quit, 1, 0, 1, 2) |
|||
self.gridLayout.addWidget(self.groupBox_04, 3, 0, 1, 2) |
|||
####gridLayout#### |
|||
MainWindow.setCentralWidget(self.centralwidget) |
MainWindow.setCentralWidget(self.centralwidget) |
||
Line 256: | Line 258: | ||
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. |
self.groupBox_01.setTitle(_translate("MainWindow", "Thickness Solide")) |
||
self. |
self.groupBox_02.setTitle(_translate("MainWindow", "Choice")) |
||
self. |
self.GroupBox_Bool.setTitle(_translate("MainWindow", "Boolean")) |
||
self. |
self.RB_Common.setText(_translate("MainWindow", "Common")) |
||
self. |
self.RB_Substract.setText(_translate("MainWindow", "Substract")) |
||
self. |
self.RB_Union.setText(_translate("MainWindow", "Union")) |
||
self. |
self.RB_Difference.setText(_translate("MainWindow", "Difference")) |
||
self. |
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_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_PB_Quit(self): # Quit |
||
Line 281: | Line 309: | ||
self.window.hide() |
self.window.hide() |
||
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_Common.isChecked(): |
|||
boolChoice = "Comm" |
|||
elif self.RB_Substract.isChecked(): |
|||
boolChoice = "Subs" |
|||
elif self.RB_Union.isChecked(): |
|||
boolChoice = "Unio" |
|||
elif self.RB_Difference.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 301: | Line 372: | ||
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 308: | Line 380: | ||
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 335: | Line 409: | ||
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_Common ") |
App.Console.PrintMessage("RB_Common ") |
||
elif self.RB_Substract.isChecked(): |
elif self.RB_Substract.isChecked(): |
||
name = str("Cut_" + selectionDuplicate[0].Label) ## create Cut_ |
name = str("Cut_" + selectionDuplicate[0].Label) ## create Cut_ |
||
Line 351: | Line 427: | ||
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_Substract ") |
App.Console.PrintMessage("RB_Substract ") |
||
Line 366: | Line 444: | ||
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") |
||
Line 390: | Line 470: | ||
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_Difference ") |
App.Console.PrintMessage("RB_Difference ") |
||
Line 397: | Line 479: | ||
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 |
|||
#______________________________________________________________________________________ |
|||
doc = FreeCAD.ActiveDocument |
doc = FreeCAD.ActiveDocument |
||
Line 408: | Line 534: | ||
doc = FreeCAD.newDocument() |
doc = FreeCAD.newDocument() |
||
MainWindow = |
MainWindow = QtWidgets.QMainWindow() |
||
ui = Ui_MainWindow() |
ui = Ui_MainWindow() |
||
ui.setupUi(MainWindow) |
ui.setupUi(MainWindow) |
||
MainWindow.show() |
MainWindow.show() |
||
}} |
}} |
||
<translate> |
<translate> |
||
==Exemple== |
|||
</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--> |
||
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== |
|||
ver 02 : 07/04/2020 : convert for PySide2 Qt5 and layout, adding the 2D (contour) wire |
|||
ver 01 : 10/10/2016 : |
|||
</translate> |
</translate> |
Revision as of 20:44, 7 April 2020
Description |
---|
Create the boolean operation with the selected wires. Push the 2d button for create the boolean operation to 2D wire. Macro version: 2.0 Last modified: 2020-04-08 FreeCAD version: 0.19 Download: ToolBar Icon Author: Mario52 |
Author |
Mario52 |
Download |
ToolBar Icon |
Links |
Macros recipes How to install macros How to customize toolbars |
Macro Version |
2.0 |
Date last modified |
2020-04-08 |
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.
- 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.
- Common , Substract , Union , Difference : Boolean's operations
- X , Y , Z : Extrude Axis (Z by Default)
- Quit : Quit themacro
- Create : Create the Boolean object
Script
Copy the macro in your macro folder.
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,
#
#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.02"
__date__ = "2020/04/08" #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 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.checkBox_01 = QtWidgets.QCheckBox()
self.checkBox_01.setChecked(True) # # False
self.groupBox_02 = QtWidgets.QGroupBox()
self.GroupBox_Bool = QtWidgets.QGroupBox()
self.RB_Common = QtWidgets.QRadioButton()
self.RB_Common.setChecked(True)
self.RB_Substract = QtWidgets.QRadioButton()
self.RB_Union = QtWidgets.QRadioButton()
self.RB_Difference = QtWidgets.QRadioButton()
self.groupBox_Axis = QtWidgets.QGroupBox()
self.RB_Axis_X = QtWidgets.QRadioButton()
self.RB_Axis_Y = QtWidgets.QRadioButton()
self.RB_Axis_Z = QtWidgets.QRadioButton()
self.RB_Axis_Z.setChecked(True)
self.RB_Axis_D = QtWidgets.QRadioButton()
self.RB_Axis_D.setEnabled(False)
self.groupBox_03 = QtWidgets.QGroupBox()
self.CB_Create_2D_Visible = QtWidgets.QCheckBox()
self.CB_Create_2D_Visible.setChecked(True) # # fALSE
self.CB_Colorer = QtWidgets.QCheckBox()
self.CB_Colorer.setChecked(False) # True #
self.PB_Create_2D = QtWidgets.QPushButton()
self.PB_Create_2D.clicked.connect(self.on_PB_Create_2D) ###
self.groupBox_04 = QtWidgets.QGroupBox()
self.PB_Quit = QtWidgets.QPushButton()
self.PB_Quit.clicked.connect(self.on_PB_Quit) ###
self.PB_Create = QtWidgets.QPushButton()
self.PB_Create.clicked.connect(self.on_PB_Create) ###
####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_Common, 0, 0, 1, 1)
self.gridLayout_04.addWidget(self.RB_Substract, 1, 0, 1, 1)
self.gridLayout_04.addWidget(self.RB_Union, 2, 0, 1, 1)
self.gridLayout_04.addWidget(self.RB_Difference, 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_Quit, 1, 0, 1, 2)
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_Common.setText(_translate("MainWindow", "Common"))
self.RB_Substract.setText(_translate("MainWindow", "Substract"))
self.RB_Union.setText(_translate("MainWindow", "Union"))
self.RB_Difference.setText(_translate("MainWindow", "Difference"))
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_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_PB_Quit(self): # Quit
App.Console.PrintMessage(str("Fin FCWire To Volume ")+"\n")
self.window.hide()
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_Common.isChecked():
boolChoice = "Comm"
elif self.RB_Substract.isChecked():
boolChoice = "Subs"
elif self.RB_Union.isChecked():
boolChoice = "Unio"
elif self.RB_Difference.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_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)
if self.CB_Colorer.isChecked():
FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (1.0,0.0,0.0)
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)
if self.CB_Colorer.isChecked():
FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (1.0,0.0,0.0)
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)
if self.CB_Colorer.isChecked():
FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (1.0,0.0,0.0)
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)
if self.CB_Colorer.isChecked():
FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (1.0,0.0,0.0)
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")
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
doc = FreeCAD.ActiveDocument
if doc == None:
doc = FreeCAD.newDocument()
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
Exemple
-
Example 3D
-
Example 2D
-
Common
-
Example 2D
-
Union
Link
The tread in the forum Bunch of issues/questions
Version
ver 02 : 07/04/2020 : convert for PySide2 Qt5 and layout, adding the 2D (contour) wire
ver 01 : 10/10/2016 :