Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Creates a clone or copy of the object and the converted in the chosen position and size (inch, mm, m, µm...) or free. The base object is recognized in mm (FreeCAd base)
# -*- coding: utf-8 -*-
# CloneConvert.FCMacro
# Cree un clone ou une copie de l'objet ou des objets selectionne(s) et le met e l'echelle de la grandeur choisie
# utilisation : lancer CloneConvert selectionnez un objet choisissez la grandeur et cliquez sur OK
#
# Creates a clone of one copy the selected object and updates the selected size range
# use: start CloneConvert select an object choose the size and click OK
#
#OS: Windows 10 (10.0)
#Word size of OS: 64-bit
#Word size of FreeCAD: 64-bit
#Version: 0.19.21280 (Git)
#Build type: Release
#Branch: master
#Hash: 6f3160db3e88733536c7eaf97ad7d6ebd21baccd
#Python version: 3.6.8
#Qt version: 5.12.1
#Coin version: 4.0.0a
#OCC version: 7.3.0
#Locale: French/Mars (fr_MA)
#
# ver 0.3 31/07/2014 PyQt4 + PySide
# ver 0.4 25/07/2015 ajout rotation
# ver 0.5 26/07/2015 correction rotation plusieurs objets Copy
# ver 0.6 26/01/2016 correction placement avec plusieurs objets Copy
# ver 0.7 30/01/2016 reecriture du code avec Placement et ajout Increment et de boutons
# ver 0.8 31/01/2016 clique 2 fois pour mettre les valeurs a zero (en cas de modifications reinitialisait )
# ver 0.9 14/06/2016 ajout du bouton nombre de copies et optimisation des labels
# ver 0.10 07/06/2017 modifie Draft... pour copie ne faisait plus de copie a l'echelle ?? remplace par Part...Shape!
# ver 0.11 30/03/2018 ajout d'un checkBox choix clone unique avec plusieurs objets ou clones separes
# ver 0.12 01/06/2019 adapte pour 0.19 et correction "Copy:legacy=True" et ShapeColor .....
# ver 0.13 15/09/2019 remplace le signe grec micro par "um", remplace tous "_translate("MainWindow", "mm", None)" par "mm" et commente ligne "text.encode('utf-8')"
# ver 0.14 2020/05/20 GridLayout PySide2 ajoute ".ActiveDocument.ActiveObject.recompute()" ligne 909 causait une erreur dans FC 0.19
# ver 0.15 2020/065/06 icon
#
__title__ = "CloneConvert"
__author__ = "mario52"
__url__ = "http://www.freecadweb.org/index-fr.html"
__version__ = "00.15"
__date__ = "2020/06/06" #YYYY/MM/DD
__Comment__ = "This macro creates Clone or Copy or Compound of object(s)"
__Web__ = "http://www.freecadweb.org/"
__Wiki__ = "http://www.freecadweb.org/wiki/index.php?title=Macro_CloneConvert"
__Icon__ = "https://wiki.freecadweb.org/images/0/0a/Macro_CloneConvert.png"
__Help__ = "start the macro and follow the instructions"
__Status__ = "stable"
__Requires__= "0.19"
__Communication__ = "http://www.freecadweb.org/wiki/index.php?title=User:Mario52"
#### Test FreeCAD.Version simple ############################################################################################################
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")
FreeCAD.Console.PrintMessage("For the precedent version see the page " + "\n\n")
FreeCAD.Console.PrintMessage("https://gist.githubusercontent.com/mario52a/9f2f2f6144e1307a048f1840ef99300c/raw/786ad9caab88a206ba26aad7fd6fb7c00eec2083/Macro_CloneConvert.FCMacro " + "\n\n")
#### Test FreeCAD.Version simple ############################################################################################################
# icon fromTheme by FreeCAD
helpIcon = [
"24 24 4 1",
" c None",
". c #016AC5",
"+ c #F8F8FF",
"@ c #FFFFFF",
"........................",
".++++++++++++++++++++++.",
".++++++++++++++++++++++.",
".++..................++.",
".++..................++.",
".++......@@@@@@......++.",
".++.....@@@@@@@@.....++.",
".++.....@@@..@@@.....++.",
".++.....@@....@@.....++.",
".++.....@@....@@.....++.",
".++...........@@.....++.",
".++..........@@@.....++.",
".++.........@@@......++.",
".++........@@@.......++.",
".++........@@........++.",
".++........@@........++.",
".++..................++.",
".++........@@........++.",
".++........@@........++.",
".++..................++.",
".++..................++.",
".++++++++++++++++++++++.",
".++++++++++++++++++++++.",
"........................"]
validIcon = [
"24 24 3 1",
" c None",
". c #4E9A06",
"+ c #FFFFFF",
" ",
" ",
" ",
" . ",
" .+. ",
" .+.+. ",
" .+...+. ",
" .+.....+. ",
" . .+.......+.",
" .+. .+.......+. ",
" .+.+. .+.......+. ",
" .+...+. .+.......+. ",
" .+.....+.+.......+. ",
".+.......+.......+. ",
" .+.............+. ",
" .+...........+. ",
" .+.........+. ",
" .+.......+. ",
" .+.....+. ",
" .+...+. ",
" .+.+. ",
" .+. ",
" . ",
" "]
quitIcon = [
"24 24 3 1",
" c None",
". c #FFFFFF",
"+ c #CC0000",
" .... ",
"++++++++++....++++++++++",
"+.......++....++.......+",
"+.......++....++.......+",
"+.......++....++.......+",
"+...++++++....++++++...+",
"+...++++++....++++++...+",
"+...+++++......+++++...+",
"+...+++++......+++++...+",
"+...+++++......+++++...+",
"+...+++++......+++++...+",
"+...+++++......+++++...+",
"+...+++++......+++++...+",
"+...++++++++++++++++...+",
"+...++++++++++++++++...+",
"+...++++++++++++++++...+",
"+...++++++++++++++++...+",
"+...++++++++++++++++...+",
"+...++++++++++++++++...+",
"+...++++++++++++++++...+",
"+......................+",
"+......................+",
"+......................+",
"++++++++++++++++++++++++"]
resetIcon = [
"24 24 3 1",
" c None",
". c #3465A4",
"+ c #888A85",
" ",
" ........ ",
" .++++++++. ",
" .++..+....+. ..... ",
" .+.. .+....+. .+++. ",
" .+. .+....+..+.+. ",
" ... .+....+.+.+. ",
" .+....+..+. ",
" .+......+. ",
" .+.....+. ",
" .+....+. ",
" ...... .+...+. ",
" .++++. .++++. ",
" .+...+. ...... ",
" .+....+. ",
" .+.....+. ",
" .+......+. ",
" .+..+....+. ",
" .+.+.+....+. ... ",
" .+.+..+....+. .+. ",
" .+++. .+....+. ..+. ",
" ..... .+....+..++. ",
" .++++++++. ",
" ........ "]
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
Gui = FreeCADGui
App = FreeCAD
global ui ; ui = ""
global sourisPass ; sourisPass = 0
import Draft, Part, FreeCAD, math, PartGui, FreeCADGui
from math import sqrt, pi, sin, cos, asin
from FreeCAD import Base
from decimal import *
from Draft import *
from FreeCAD import Vector, Rotation, Placement, Console
import FreeCADGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtWidgets.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtWidgets.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtWidgets.QApplication.translate(context, text, disambig)
global surface ; surface = 0.0
global volume_ ; volume_ = 0.0
global boundBox_ ; boundBox_ = 0.0
global boundBoxLX ; boundBoxLX = 0.0
global boundBoxLY ; boundBoxLY = 0.0
global boundBoxLZ ; boundBoxLZ = 0.0
global boundBox_S ; boundBox_S = ""
global uniteM_X ; uniteM_X = 1.0
global uniteM_Y ; uniteM_Y = 1.0
global uniteM_Z ; uniteM_Z = 1.0
global uniteM ; uniteM = 1.0
global uniteMs ; uniteMs = "mm" # default mm
global placement_X ; placement_X = 0.0
global placement_Y ; placement_Y = 0.0
global placement_Z ; placement_Z = 0.0
global Yaw_Z ; Yaw_Z = 0.0
global Pitch_Y ; Pitch_Y = 0.0
global Roll_X ; Roll_X = 0.0
global copyNumber ; copyNumber = 1
global copyUnique ; copyUnique = 0
global switchP ; switchP = 0
global switchA ; switchA = 0
global switchS ; switchS = 0
global sel ; sel = ""
global cloneCopy ; cloneCopy = 1
global a ; a = ""
global path
##path###########################################################################
#path = FreeCAD.ConfigGet("AppHomePath")
#path = FreeCAD.ConfigGet("UserAppData")
#path = "your path"
param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro")# macro path
path = param.GetString("MacroPath","") + "/" # macro path
path = path.replace("\\","/")
#App.Console.PrintMessage(str("Path for the icons : ") + path + "\n" + __title__ + " : " +__version__ + " " + __date__ + "\n")
#################################################################################
## icon freeCAD Theme
class Ui_MainWindow(object):
def __init__(self, MainWindow):
global path
global uniteMs
self.path = path
self.window = MainWindow
MainWindow.setObjectName(_fromUtf8("MainWindow"))
# MainWindow.resize(230, 549)
# MainWindow.setMinimumSize(QtCore.QSize(230, 549))
# MainWindow.setMaximumSize(QtCore.QSize(230, 549))
self.centralWidget = QtWidgets.QWidget(MainWindow)
self.centralWidget.setObjectName(_fromUtf8("centralWidget"))
self.label = QtWidgets.QLabel()
font = QtGui.QFont()
font.setPointSize(12)
self.label.setFont(font)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.groupBox_00 = QtWidgets.QGroupBox()
self.groupBox = QtWidgets.QGroupBox()
self.radioButton = QtWidgets.QRadioButton()
self.radioButton.setChecked(True)
self.radioButton.setIcon(QtGui.QIcon.fromTheme("close",QtGui.QIcon(":/icons/Draft_Clone.svg")))
self.radioButton.clicked.connect(self.on_radioButton_clicked) #connection radioButton mode clone
self.checkBox_00 = QtWidgets.QCheckBox()
self.checkBox_00.setChecked(False)
self.radioButton_2 = QtWidgets.QRadioButton()
self.radioButton_2.setIcon(QtGui.QIcon.fromTheme("close",QtGui.QIcon(":/icons/Part_Transformed_Copy.svg")))
self.radioButton_2.clicked.connect(self.on_radioButton_2_clicked) #connection radioButton_2 mode copy
self.radioButton_3 = QtWidgets.QRadioButton()
self.radioButton_3.setIcon(QtGui.QIcon.fromTheme("close",QtGui.QIcon(":/icons/Part_Compound.svg")))
self.radioButton_3.clicked.connect(self.on_radioButton_3_clicked) #connection radioButton_3 mode compount
self.checkBox = QtWidgets.QCheckBox()
self.checkBox.setChecked(True)
self.groupBox_Translate = QtWidgets.QGroupBox()
self.label_2 = QtWidgets.QLabel()
# self.label_2.setStyleSheet("color : #aa0000")
self.doubleSpinBox = QtWidgets.QDoubleSpinBox()
self.doubleSpinBox.setDecimals(7)
self.doubleSpinBox.setMinimum(-10000000.0)
self.doubleSpinBox.setMaximum(10000000.0)
self.doubleSpinBox.setSingleStep(1.0)
self.doubleSpinBox.setProperty("value", 0.0)
self.doubleSpinBox.valueChanged.connect(self.on_doubleSpinBox_valueChanged) #connection doubleSpinBox
self.label_3 = QtWidgets.QLabel()
# self.label_3.setStyleSheet("color : #00aa00")
self.doubleSpinBox_2 = QtWidgets.QDoubleSpinBox()
self.doubleSpinBox_2.setDecimals(7)
self.doubleSpinBox_2.setMinimum(-10000000.0)
self.doubleSpinBox_2.setMaximum(10000000.0)
self.doubleSpinBox_2.setSingleStep(1.0)
self.doubleSpinBox_2.setProperty("value", 0.0)
self.doubleSpinBox_2.valueChanged.connect(self.on_doubleSpinBox_2_valueChanged) #connection doubleSpinBox_2
self.label_4 = QtWidgets.QLabel()
# self.label_4.setStyleSheet("color : #0000aa")
self.doubleSpinBox_3 = QtWidgets.QDoubleSpinBox()
self.doubleSpinBox_3.setDecimals(7)
self.doubleSpinBox_3.setMinimum(-10000000.0)
self.doubleSpinBox_3.setMaximum(10000000.0)
self.doubleSpinBox_3.setSingleStep(1.0)
self.doubleSpinBox_3.setProperty("value", 0.0)
self.doubleSpinBox_3.valueChanged.connect(self.on_doubleSpinBox_3_valueChanged) #connection doubleSpinBox_3
self.pushButton_5 = QtWidgets.QPushButton()
self.pushButton_5.clicked.connect(self.on_pushButton_5_clicked) # connect on def "on_pushButton_5_clicked"
self.groupBox_2 = QtWidgets.QGroupBox()
self.comboBox = QtWidgets.QComboBox()
self.comboBox.setMinimumContentsLength(0)
self.comboBox.addItem(_fromUtf8(""))
self.comboBox.addItem(_fromUtf8(""))
self.comboBox.addItem(_fromUtf8(""))
self.comboBox.addItem(_fromUtf8(""))
self.comboBox.addItem(_fromUtf8(""))
self.comboBox.addItem(_fromUtf8(""))
self.comboBox.addItem(_fromUtf8(""))
self.comboBox.addItem(_fromUtf8(""))
self.comboBox.addItem(_fromUtf8(""))
self.comboBox.addItem(_fromUtf8(""))
self.comboBox.addItem(_fromUtf8(""))
self.comboBox.addItem(_fromUtf8(""))
self.comboBox.addItem(_fromUtf8(""))
self.comboBox.addItem(_fromUtf8(""))
self.comboBox.addItem(_fromUtf8(""))
self.comboBox.addItem(_fromUtf8(""))
self.comboBox.addItem(_fromUtf8(""))
self.comboBox.addItem(_fromUtf8(""))
self.comboBox.addItem(_fromUtf8(""))
QtCore.QObject.connect(self.comboBox, QtCore.SIGNAL("currentIndexChanged(QString)"), self.SIGNAL_comboBox_Changed)
self.groupBox_3 = QtWidgets.QGroupBox()
self.doubleSpinBox_4 = QtWidgets.QDoubleSpinBox()
self.doubleSpinBox_4.setDecimals(7)
self.doubleSpinBox_4.setMinimum(-1000000)
self.doubleSpinBox_4.setMaximum(1000000.0)
self.doubleSpinBox_4.setSingleStep(1.0)
self.doubleSpinBox_4.setProperty("value", 1.0)
self.doubleSpinBox_4.valueChanged.connect(self.on_doubleSpinBox_4_valueChanged) #connection doubleSpinBox_4
self.doubleSpinBox_5 = QtWidgets.QDoubleSpinBox()
self.doubleSpinBox_5.setDecimals(7)
self.doubleSpinBox_5.setMinimum(-1000000)
self.doubleSpinBox_5.setMaximum(1000000.0)
self.doubleSpinBox_5.setSingleStep(1.0)
self.doubleSpinBox_5.setProperty("value", 1.0)
self.doubleSpinBox_5.valueChanged.connect(self.on_doubleSpinBox_5_valueChanged) #connection doubleSpinBox_5
self.doubleSpinBox_6 = QtWidgets.QDoubleSpinBox()
self.doubleSpinBox_6.setDecimals(7)
self.doubleSpinBox_6.setMinimum(-1000000)
self.doubleSpinBox_6.setMaximum(1000000.0)
self.doubleSpinBox_6.setSingleStep(1.0)
self.doubleSpinBox_6.setProperty("value", 1.0)
self.doubleSpinBox_6.valueChanged.connect(self.on_doubleSpinBox_6_valueChanged) #connection doubleSpinBox_6
self.label_5 = QtWidgets.QLabel()
self.label_6 = QtWidgets.QLabel()
self.label_7 = QtWidgets.QLabel()
self.pushButton_6 = QtWidgets.QPushButton()
self.pushButton_6.clicked.connect(self.on_pushButton_6_clicked) # connect on def "on_pushButton_6_clicked"
self.pushButton_3 = QtWidgets.QPushButton(self.groupBox_3)
self.pushButton_3.clicked.connect(self.on_pushButton03_clicked) #connection pushButton03 "..." align YZ to X
self.groupBox_4 = QtWidgets.QGroupBox(self.centralWidget)
self.doubleSpinBox_7 = QtWidgets.QDoubleSpinBox()
self.doubleSpinBox_7.setDecimals(7)
self.doubleSpinBox_7.setMinimum(-360.0)
self.doubleSpinBox_7.setMaximum(360.0)
self.doubleSpinBox_7.valueChanged.connect(self.on_doubleSpinBox_7_valueChanged) #connection doubleSpinBox_7
self.doubleSpinBox_8 = QtWidgets.QDoubleSpinBox()
self.doubleSpinBox_8.setDecimals(7)
self.doubleSpinBox_8.setMinimum(-360.0)
self.doubleSpinBox_8.setMaximum(360.0)
self.doubleSpinBox_8.valueChanged.connect(self.on_doubleSpinBox_8_valueChanged) #connection doubleSpinBox_8
self.doubleSpinBox_9 = QtWidgets.QDoubleSpinBox()
self.doubleSpinBox_9.setDecimals(7)
self.doubleSpinBox_9.setMinimum(-360.0)
self.doubleSpinBox_9.setMaximum(360.0)
self.doubleSpinBox_9.valueChanged.connect(self.on_doubleSpinBox_9_valueChanged) #connection doubleSpinBox_9
self.groupBox_5 = QtWidgets.QGroupBox()
self.groupBox_6 = QtWidgets.QGroupBox()
self.SpinBox = QtWidgets.QSpinBox()
self.SpinBox.setMaximum(1000000)
self.SpinBox.setProperty("value", 1)
self.SpinBox.valueChanged.connect(self.on_SpinBox_valueChanged) #connection SpinBox
self.label_8 = QtWidgets.QLabel()
self.label_9 = QtWidgets.QLabel()
self.label_10 = QtWidgets.QLabel()
self.pushButton_4 = QtWidgets.QPushButton()
self.pushButton_4.clicked.connect(self.on_pushButton_4_clicked) # connect on def "on_pushButton_4_clicked"
self.lineEdit = QtWidgets.QLineEdit()
self.lineEdit.setText("Form")
self.pushButton_2 = QtWidgets.QPushButton()
self.pushButton_2.setIcon(QtGui.QIcon(QtGui.QPixmap(quitIcon))) # icone dans une variable
self.pushButton_2.clicked.connect(self.on_pushButton02_clicked) #connection pushButton02 "Quitter"
self.pushButton = QtWidgets.QPushButton()
self.pushButton.setIcon(QtGui.QIcon(QtGui.QPixmap(resetIcon))) # icone dans une variable
self.pushButton.clicked.connect(self.on_pushButton00_clicked) #connection pushButton00 "Reset"
self.pushButton_1 = QtWidgets.QPushButton()
self.pushButton_1.setStyleSheet("background-color: Base")
self.pushButton_1.setIcon(QtGui.QIcon(QtGui.QPixmap(validIcon)))# icone dans une variable
self.pushButton_1.clicked.connect(self.on_pushButton01_clicked) #connection pushButton01 "OK"
self.PB_Help = QtWidgets.QPushButton()
self.PB_Help.setIcon(QtGui.QIcon(QtGui.QPixmap(helpIcon))) # icone dans une variable
self.PB_Help.clicked.connect(self.on_PB_Help) #
#### gridLayout debut ####################
gridLayout_00 = QtWidgets.QGridLayout(self.centralWidget)
gridLayout_00.addWidget(self.groupBox_00)
gridLayout_01 = QtWidgets.QGridLayout(self.groupBox_00)
####
gridLayout_Tittle = QtWidgets.QGridLayout(self.label)
gridLayout_Tittle.setContentsMargins(2, 2, 2, 2)
gridLayout_Tittle.addWidget(self.label, 0, 0, 1, 2)
gridLayout_01.addWidget(self.label, 0, 0, 1, 2)
####
self.gridLayout_Mode = QtWidgets.QGridLayout(self.groupBox)
self.gridLayout_Mode.setContentsMargins(10, 10, 10, 10)
self.gridLayout_Mode.addWidget(self.radioButton, 0, 0, 1, 1)
self.gridLayout_Mode.addWidget(self.checkBox_00, 0, 1, 1, 1)
self.gridLayout_Mode.addWidget(self.radioButton_2, 1, 0, 1, 1)
self.gridLayout_Mode.addWidget(self.radioButton_3, 1, 1, 1, 1)
self.gridLayout_Mode.addWidget(self.checkBox, 1, 2, 1, 1)
gridLayout_01.addWidget(self.groupBox, 1, 0, 1, 2)
####
self.gridLayout_Translate = QtWidgets.QGridLayout(self.groupBox_Translate)
self.gridLayout_Translate.addWidget(self.label_2, 0, 0, 1, 1)
self.gridLayout_Translate.addWidget(self.pushButton_5, 0, 1, 1, 1)
self.gridLayout_Translate.addWidget(self.doubleSpinBox, 0, 2, 1, 1)
self.gridLayout_Translate.addWidget(self.label_3, 1, 0, 1, 1)
self.gridLayout_Translate.addWidget(self.doubleSpinBox_2, 1, 2, 1, 1)
self.gridLayout_Translate.addWidget(self.label_4, 2, 0, 1, 1)
self.gridLayout_Translate.addWidget(self.doubleSpinBox_3, 2, 2, 1, 1)
gridLayout_01.addWidget(self.groupBox_Translate, 2, 0, 1, 2)
####
self.gridLayout_Rotation = QtWidgets.QGridLayout(self.groupBox_4)
self.gridLayout_Rotation.setContentsMargins(10, 10, 10, 10)
self.gridLayout_Rotation.addWidget(self.label_8, 0, 0, 1, 1)
self.gridLayout_Rotation.addWidget(self.pushButton_4, 0, 1, 1, 1)
self.gridLayout_Rotation.addWidget(self.doubleSpinBox_7, 0, 2, 1, 1)
self.gridLayout_Rotation.addWidget(self.label_9, 1, 0, 1, 1)
self.gridLayout_Rotation.addWidget(self.doubleSpinBox_8, 1, 2, 1, 1)
self.gridLayout_Rotation.addWidget(self.label_10, 2, 0, 1, 1)
self.gridLayout_Rotation.addWidget(self.doubleSpinBox_9, 2, 2, 1, 1)
gridLayout_01.addWidget(self.groupBox_4, 3, 0, 1, 2)
####
self.gridLayout_Scale = QtWidgets.QGridLayout(self.groupBox_2)
self.gridLayout_Scale.setContentsMargins(10, 10, 10, 10)
self.gridLayout_Scale.addWidget(self.comboBox, 0, 0, 1, 1)
gridLayout_01.addWidget(self.groupBox_2, 4, 0, 1, 1)
####
self.gridLayout_NumberCopy = QtWidgets.QGridLayout(self.groupBox_5)
self.gridLayout_NumberCopy.setContentsMargins(10, 10, 10, 10)
self.gridLayout_NumberCopy.addWidget(self.SpinBox, 0, 0, 1, 1)
gridLayout_01.addWidget(self.groupBox_5, 4, 1, 1, 1)
####
self.gridLayout_ScaleFree = QtWidgets.QGridLayout(self.groupBox_3)
self.gridLayout_ScaleFree.setContentsMargins(10, 10, 10, 10)
self.gridLayout_ScaleFree.addWidget(self.label_5, 0, 0, 1, 1)
self.gridLayout_ScaleFree.addWidget(self.pushButton_3, 0, 1, 1, 1)
self.gridLayout_ScaleFree.addWidget(self.doubleSpinBox_4, 0, 2, 1, 1)
self.gridLayout_ScaleFree.addWidget(self.label_6, 1, 0, 1, 1)
self.gridLayout_ScaleFree.addWidget(self.doubleSpinBox_5, 1, 2, 1, 1)
self.gridLayout_ScaleFree.addWidget(self.label_7, 2, 0, 1, 1)
self.gridLayout_ScaleFree.addWidget(self.doubleSpinBox_6, 2, 2, 1, 1)
gridLayout_01.addWidget(self.groupBox_3, 5, 0, 1, 2)
####
self.gridLayout_Command = QtWidgets.QGridLayout(self.groupBox_6)
self.gridLayout_Command.setContentsMargins(10, 10, 10, 10)
self.gridLayout_Command.addWidget(self.pushButton_6, 0, 0, 1, 1)
self.gridLayout_Command.addWidget(self.lineEdit, 0, 1, 1, 3)
self.gridLayout_Command.addWidget(self.pushButton_2, 1, 0, 1, 1)
self.gridLayout_Command.addWidget(self.pushButton, 1, 1, 1, 1)
self.gridLayout_Command.addWidget(self.pushButton_1, 1, 2, 1, 1)
self.gridLayout_Command.addWidget(self.PB_Help, 1, 3, 1, 1)
gridLayout_01.addWidget(self.groupBox_6, 6, 0, 1, 2)
#### gridLayout fin ####################
MainWindow.setCentralWidget(self.centralWidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", __title__, None))
MainWindow.setWindowIcon(QtGui.QIcon(_fromUtf8(self.path + "Macro_CloneConvert.png"))) # change l'icone de la fenetre principale
MainWindow.setWindowFlags(PySide2.QtCore.Qt.WindowStaysOnTopHint) # cette fonction met la fenetre en avant
self.groupBox_00.setTitle(_translate("MainWindow", "ver : " + __version__ + " : " + __date__, None))
self.label.setText(_translate("MainWindow", "Clone Convert", None))
self.groupBox.setTitle(_translate("MainWindow", "Mode", None))
####
self.radioButton.setText(_translate("MainWindow", "Clone", None))
self.radioButton.setToolTip(_translate("MainWindow", "Create a clone of the object(s)", None))
self.checkBox_00.setText(_translate("MainWindow", "Unique", None))
self.checkBox_00.setToolTip(_translate("MainWindow", "If checked and multiple object selected" + "\n"
"the clone created is one unique object", None))
self.radioButton_2.setText(_translate("MainWindow", "Copy", None))
self.radioButton_2.setToolTip(_translate("MainWindow", "Create a copy of the object(s)", None))
self.radioButton_3.setText(_translate("MainWindow", "Comp.", None))
self.radioButton_3.setToolTip(_translate("MainWindow", "Create a compount of the object(s)", None))
self.checkBox.setText(_translate("MainWindow", "Increm.", None))
self.checkBox.setToolTip(_translate("MainWindow", "Apply incremental changes to object Placement (Defaut)\n"+
"If this is not checked the Placement begin in coordinates 0,0,0 of FreeCAD\n"+
"In case a compound Placement information is [0,0,0] the Placement begin in the position of object\n"+
"If the real location is away from the base coordinates 0,0,0 use the ValueAt() button\n"
"for the real Placement of the subObject selected Face, Wire, Line ....", None))
####
self.groupBox_Translate.setTitle(_translate("MainWindow", "Translate", None))
self.label_2.setText("<html> <body> <text=""#000000""> Coordinate <FONT COLOR=""#aa0000""> X </font> </body> </html>" )
self.pushButton_5.setToolTip(_translate("MainWindow", "Align the YZ coordinates values to X value \n Two click reset the coordinates values to 0.0", None))
self.pushButton_5.setText(_translate("MainWindow", "Align YZ ...", None))
self.doubleSpinBox.setToolTip(_translate("MainWindow", "Place the new object to the X coordinate ", None))
self.doubleSpinBox.setSuffix(_translate("MainWindow", " mm", None))
self.label_3.setText("<html> <body> <text=""#000000""> Coordinate <FONT COLOR=""#00aa00""> Y </font> </body> </html>" )
self.doubleSpinBox_2.setToolTip(_translate("MainWindow", "Place the new object to the Y coordinate", None))
self.doubleSpinBox_2.setSuffix(_translate("MainWindow", " mm", None))
self.label_4.setText("<html> <body> <text=""#000000""> Coordinate <FONT COLOR=""#0000aa""> Z </font> </body> </html>" )
self.doubleSpinBox_3.setToolTip(_translate("MainWindow", "Place the new object to the Z coordinate", None))
self.doubleSpinBox_3.setSuffix(_translate("MainWindow", " mm", None))
####
self.groupBox_4.setTitle(_translate("MainWindow", "Rotation", None))
# self.label_8.setText(_translate("MainWindow", "Yaw ( Z )", None))
self.label_8.setText("<html> <body> <text=""#000000""> Yaw ( <FONT COLOR=""#0000aa""> Z </font> <text=""#000000""> ) </body> </html>" )
self.pushButton_4.setToolTip(_translate("MainWindow", "Align the YX degrees values to Z value \n Two click reset the rotations values to 0.0", None))
self.pushButton_4.setText(_translate("MainWindow", "Align YX ...", None))
self.doubleSpinBox_7.setSuffix(_translate("MainWindow", " Deg", None))
self.doubleSpinBox_7.setToolTip(_translate("MainWindow", "Rotation of Yaw ( Axis Z )", None))
# self.label_9.setText(_translate("MainWindow", "Pitch ( Y )", None))
self.label_9.setText("<html> <body> <text=""#000000""> Pitch ( <FONT COLOR=""#00aa00""> Y </font> <text=""#000000""> ) </body> </html>" )
self.doubleSpinBox_8.setSuffix(_translate("MainWindow", " Deg", None))
self.doubleSpinBox_8.setToolTip(_translate("MainWindow", "Rotation of Pitch ( Axis Y )", None))
# self.label_10.setText(_translate("MainWindow", "Roll ( X )", None))
self.label_10.setText("<html> <body> <text=""#000000""> Roll ( <FONT COLOR=""#aa0000""> X </font> <text=""#000000""> ) </body> </html>" )
self.doubleSpinBox_9.setSuffix(_translate("MainWindow", " Deg", None))
self.doubleSpinBox_9.setToolTip(_translate("MainWindow", "Rotation of Roll ( Axis X )", None))
####
self.groupBox_2.setTitle(_translate("MainWindow", "Scale predefined", None))
self.comboBox.setToolTip(_translate("MainWindow", "Convert your object to . . .", None))
self.comboBox.setCurrentIndex(6)
self.comboBox.setItemText(0, "km") #km # = 1000000
self.comboBox.setItemText(1, "hm") #hm # = 100000
self.comboBox.setItemText(2, "dam") #dam# = 10000
self.comboBox.setItemText(3, "m") #m # = 1000
self.comboBox.setItemText(4, "dm") #dm # = 100
self.comboBox.setItemText(5, "cm") #cm # = 10
self.comboBox.setItemText(6, "mm") #mm # = 1 #####
self.comboBox.setItemText(7, "um") #um # micro = 0.001
self.comboBox.setItemText(8, "nm") #nm # nano = 0.000001
self.comboBox.setItemText(9, "inch") #in # inch pouce = 25.400
self.comboBox.setItemText(10, "link") #lk # link chainon = 201.168
self.comboBox.setItemText(11, "foot") #ft # foot pied = 304.800
self.comboBox.setItemText(12, "yard") #yd # yard verge = 914.400
self.comboBox.setItemText(13, "perch") #rd # rod ou perch perche = 5029.200
self.comboBox.setItemText(14, "chain") #ch # chain chaine = 20116.800
self.comboBox.setItemText(15, "furlong") #fur# furlong = 201168
self.comboBox.setItemText(16, "mile") #mi # mile = 1609344
self.comboBox.setItemText(17, "league") #lea# league lieue = 4828032
self.comboBox.setItemText(18, "nautique") #nmi# mile nautique = 1852000
self.comboBox.setToolTip(_translate("MainWindow",u"Select unit. . .", None))
####
self.groupBox_5.setTitle(_translate("MainWindow", "Number copy", None))
self.SpinBox.setToolTip(_translate("MainWindow", "Number copy of original", None))
####
self.groupBox_3.setTitle(_translate("MainWindow", "Scale free", None))
self.label_5.setText(_translate("MainWindow", "Scale X", None))
self.pushButton_3.setToolTip(_translate("MainWindow", "Align the YZ scale values to X scale value \n Two click reset the scales values to 1.0", None))
self.pushButton_3.setText(_translate("MainWindow", "Align YZ ...", None))
self.doubleSpinBox_4.setToolTip(_translate("MainWindow", "Scale free X multiplied by ...\nIf the value is negative the object result is reverted in X axis", None))
self.label_6.setText(_translate("MainWindow", "Scale Y", None))
self.doubleSpinBox_5.setToolTip(_translate("MainWindow", "Scale free Y multiplied by ...\n"+
"If the value is negative the object result is reverted in Y axis", None))
self.label_7.setText(_translate("MainWindow", "Scale Z", None))
self.doubleSpinBox_6.setToolTip(_translate("MainWindow", "Scale free Z multiplied by ...\n"+
"If the value is negative the object result is reverted in Z axis", None))
####
self.groupBox_6.setTitle(_translate("MainWindow", "Command", None))
self.pushButton_6.setToolTip(_translate("MainWindow", "Give the valueAt() the subObject selected Face, Wire, Line ...\n"+
"This option is useful in case a compound Placement information [0,0,0]\n"+
"and its real location is away from the base coordinates 0,0,0\n"+
"(gives no provide information about the tilt of the object)", None))
self.pushButton_6.setText(_translate("MainWindow", "ValueAt()", None))
##
self.pushButton_2.setToolTip(_translate("MainWindow", "Quit the macro", None))
self.pushButton_2.setText(_translate("MainWindow", "Quit", None))
self.pushButton.setToolTip(_translate("MainWindow", "Reset the values", None))
self.pushButton.setText(_translate("MainWindow", "Reset", None))
self.pushButton_1.setToolTip(_translate("MainWindow", "Ok for Convert Copy or Compount", None))
self.pushButton_1.setText(_translate("MainWindow", "Ok", None))
self.PB_Help.setText(_translate("MainWindow", "Help"))
def SIGNAL_comboBox_Changed(self,text):
global uniteM_X
global uniteM_Y
global uniteM_Z
global uniteM
global uniteMs
if text == "km": # = 1000000
uniteM = uniteM_X = uniteM_Y = uniteM_Z = 1000000.0
uniteMs= "km"
elif text == "hm": # = 100000
uniteM = uniteM_X = uniteM_Y = uniteM_Z = 100000.0
uniteMs= "hm"
elif text == "dam": # = 10000
uniteM = uniteM_X = uniteM_Y = uniteM_Z = 10000.0
uniteMs= "dam"
elif text == "m": # = 1000
uniteM = uniteM_X = uniteM_Y = uniteM_Z = 1000.0
uniteMs= "m"
elif text == "dm": # = 100
uniteM = uniteM_X = uniteM_Y = uniteM_Z = 100.0
uniteMs= "dm"
elif text == "cm": # = 10
uniteM = uniteM_X = uniteM_Y = uniteM_Z = 10.0
uniteMs= "cm"
elif text == "mm": # = 1 ###############################
uniteM = uniteM_X = uniteM_Y = uniteM_Z = 1.0
uniteMs= "mm"
elif text == "um": # = 1000
uniteM = uniteM_X = uniteM_Y = uniteM_Z = 1.0/1000.0
uniteMs= "um"
elif text == "nm": # = 1000000
uniteM = uniteM_X = uniteM_Y = uniteM_Z = 1.0/1000000.0
uniteMs= u"nm"
elif text == "inch": # inch = 25.400
uniteM = uniteM_X = uniteM_Y = uniteM_Z = 25.400
uniteMs= "in"
elif text == "link": # link = 201.168
uniteM = uniteM_X = uniteM_Y = uniteM_Z = 201.168
uniteMs= "lk"
elif text == "foot": # foot = 304.800
uniteM = uniteM_X = uniteM_Y = uniteM_Z = 304.800
uniteMs= "ft"
elif text == "yard": # yard = 914.400
uniteM = uniteM_X = uniteM_Y = uniteM_Z = 914.400
uniteMs= "yd"
elif text == "perch": #rd # rod perche = 5029.200
uniteM = uniteM_X = uniteM_Y = uniteM_Z = 5029.200
uniteMs= "rd"
elif text == "chain": # chain = 20116.800
uniteM = uniteM_X = uniteM_Y = uniteM_Z = 20116.800
uniteMs= "ch"
elif text == "furlong": # furlong= 201168
uniteM = uniteM_X = uniteM_Y = uniteM_Z = 201168
uniteMs= "fur"
elif text == "mile": # mile = 1609344
uniteM = uniteM_X = uniteM_Y = uniteM_Z = 1609344
uniteMs= "mi"
elif text == "league": # league = 4828032
uniteM = uniteM_X = uniteM_Y = uniteM_Z = 4828032
uniteMs= "lea"
elif text == "nautique": # nautique = 1852000
uniteM = uniteM_X = uniteM_Y = uniteM_Z = 1852000
uniteMs= "nmi"
else: # mm = 1
uniteM = uniteM_X = uniteM_Y = uniteM_Z = 1.0
uniteMs= "mm"
self.doubleSpinBox_4.setProperty("value", uniteM_X)
self.doubleSpinBox_5.setProperty("value", uniteM_Y)
self.doubleSpinBox_6.setProperty("value", uniteM_Z)
def on_radioButton_clicked(self): # if checked then mode clone
global cloneCopy
cloneCopy = 1
def on_radioButton_2_clicked(self): # if checked then mode copy
global cloneCopy
cloneCopy = 0
def on_radioButton_3_clicked(self): # if checked then mode compount
global cloneCopy
cloneCopy = 2
def on_doubleSpinBox_valueChanged(self,value): # doubleSpinbox X
global placement_X
global switchP
switchP = 0
placement_X = value
def on_doubleSpinBox_2_valueChanged(self,value): # doubleSpinbox Y
global placement_Y
global switchP
switchP = 0
placement_Y = value
def on_doubleSpinBox_3_valueChanged(self,value): # doubleSpinbox Z
global placement_Z
global switchP
switchP = 0
placement_Z = value
def on_doubleSpinBox_4_valueChanged(self,value): # doubleSpinbox free X
global uniteM_X
global switchS
switchS = 0
uniteM_X = value
if uniteM_X == 0:
uniteM_X = 1
def on_doubleSpinBox_5_valueChanged(self,value): # doubleSpinbox free Y
global uniteM_Y
global switchS
switchS = 0
uniteM_Y = value
if uniteM_Y == 0:
uniteM_Y = 1
def on_doubleSpinBox_6_valueChanged(self,value): # doubleSpinbox free Z
global uniteM_Z
global switchS
switchS = 0
uniteM_Z = value
if uniteM_Z == 0:
uniteM_Z = 1
def on_doubleSpinBox_7_valueChanged(self,value): # doubleSpinBox_7 Yaw ( Z )
global Yaw_Z
global switchA
switchA = 0
Yaw_Z = value
def on_doubleSpinBox_8_valueChanged(self,value): # doubleSpinBox_8 Pitch ( Y )
global Pitch_Y
global switchA
switchA = 0
Pitch_Y = value
def on_doubleSpinBox_9_valueChanged(self,value): # doubleSpinBox_9 Roll ( X )
global Roll_X
global switchA
switchA = 0
Roll_X = value
def on_SpinBox_valueChanged(self,value): # SpinBox Number copy
global copyNumber
copyNumber = value
def on_pushButton_5_clicked(self): # Bouton ... (align) placement
global placement_X
global placement_Y
global placement_Z
global switchP
if switchP == 0:
placement_Y = placement_Z = placement_X
switchP = 1
else:
placement_Y = placement_Z = placement_X = 0.0
switchP = 0
self.doubleSpinBox.setProperty("value", placement_X)
self.doubleSpinBox_2.setProperty("value", placement_Y)
self.doubleSpinBox_3.setProperty("value", placement_Z)
def on_pushButton_6_clicked(self): # valueAt() placement detected
try:
sel = FreeCADGui.Selection.getSelection()
App.Console.PrintMessage(str(sel[0].Placement) +"\r\n")
selectionObjects = FreeCADGui.Selection.getSelectionEx() # Select an object or sub object getSelectionEx
edge = selectionObjects[0].SubObjects[0]
try:
self.lineEdit.setText(str(edge.valueAt(0,0))) # face
self.pushButton_6.setText(_translate("MainWindow", "ValueAt(0,0)", None))
App.Console.PrintMessage(str(edge.valueAt(0,0)) +"\r\n")
except Exception:
self.lineEdit.setText(str(edge.valueAt(0))) # fil
self.pushButton_6.setText(_translate("MainWindow", "ValueAt(0)", None))
App.Console.PrintMessage(str(edge.valueAt(0)) +"\r\n")
except Exception:
self.pushButton_6.setText(_translate("MainWindow", "ValueAt()", None))
App.Console.PrintError("Select one subObject, Face, Wire, Line ..."+"\r\n")
App.Console.PrintMessage("____________________________________"+"\r\n")
def on_pushButton_4_clicked(self): # Bouton ... (align) rotation
global Yaw_Z
global Pitch_Y
global Roll_X
global switchA
if switchA == 0:
Pitch_Y = Roll_X = Yaw_Z
switchA = 1
else:
Pitch_Y = Roll_X = Yaw_Z = 0.0
switchA = 0
self.doubleSpinBox_7.setProperty("value", Yaw_Z)
self.doubleSpinBox_8.setProperty("value", Pitch_Y)
self.doubleSpinBox_9.setProperty("value", Roll_X)
def on_pushButton03_clicked(self): # Bouton ... (align) uniteM
global uniteM_X
global uniteM_Y
global uniteM_Z
global switchS
global uniteM
global uniteMs
if switchS == 0:
uniteM_Y = uniteM_Z = uniteM_X
switchS = 1
else:
uniteM_Y = uniteM_Z = uniteM_X = 1.0
switchS = 0
self.doubleSpinBox_4.setProperty("value", uniteM_X)
self.doubleSpinBox_5.setProperty("value", uniteM_Y)
self.doubleSpinBox_6.setProperty("value", uniteM_Z)
def on_pushButton00_clicked(self): # Bouton Reset
global sel
global uniteM_X
global uniteM_Y
global uniteM_Z
global uniteM
global uniteMs
global placement_X
global placement_Y
global placement_Z
global cloneCopy
global Yaw_Z
global Pitch_Y
global Roll_X
global copyNumber
sel = ""
self.pushButton_1.setToolTip("Ok for Convert or copy")
self.pushButton_1.setStyleSheet("background-color: Base")
self.radioButton.setChecked(True)
cloneCopy = 1
self.comboBox.setCurrentIndex(6)
self.doubleSpinBox.setProperty("value", 0.0) # coordinates
self.doubleSpinBox_2.setProperty("value", 0.0)
self.doubleSpinBox_3.setProperty("value", 0.0)
self.checkBox.setChecked(True)
placement_X = placement_Y = placement_Z = 0.0
self.doubleSpinBox_4.setProperty("value", 1.0) # scale
self.doubleSpinBox_5.setProperty("value", 1.0)
self.doubleSpinBox_6.setProperty("value", 1.0)
self.doubleSpinBox_7.setProperty("value", 0.0) # angles
self.doubleSpinBox_8.setProperty("value", 0.0)
self.doubleSpinBox_9.setProperty("value", 0.0)
self.SpinBox.setProperty("value", 1) # number copy
copyNumber = 1
uniteM = uniteM_X = uniteM_Y = uniteM_Z = 1.0
uniteMs= "mm"
uniteM = 1
self.lineEdit.setText("")
def on_pushButton01_clicked(self): # Bouton OK
global sel
global surface
global volume_
global boundBox
global boundBoxLX
global boundBoxLY
global boundBoxLZ
global boundBox_S
global uniteM_X
global uniteM_Y
global uniteM_Z
global uniteM
global uniteMs
global placement_X
global placement_Y
global placement_Z
global sel
global Yaw_Z
global Pitch_Y
global Roll_X
global copyNumber
global copyUnique
sel = FreeCADGui.Selection.getSelection()
if len(sel) != 0:
self.pushButton_1.setToolTip(_translate("MainWindow", "Ok for Convert or copy", None))
self.pushButton_1.setStyleSheet("background-color: Base")
FreeCADGui.updateGui() # rafraichi l'ecran
# boundinbox (dimensions hors tout)
try:
boundBox_ = sel[0].Shape.BoundBox # pour 1 seul objet, (le premier)
boundBoxLX = boundBox_.XLength
boundBoxLY = boundBox_.YLength
boundBoxLZ = boundBox_.ZLength
except:
boundBox_ = 0.0
boundBoxLX = 0.0
boundBoxLY = 0.0
boundBoxLZ = 0.0
boundBox_S = ""
# volume de tous les objets
volume_ = 0.0
try:
for i in range(len(sel)):
volume_ += sel[i].Shape.Volume
except:
volume_ = 0.0
# surface de tous les objets
surface = 0.0
try:
for i in range(len(sel)):
surface += sel[i].Shape.Area
except:
surface = 0.0
boundBox_S = "[X: "+str(boundBoxLX)+" mm] x [Y: "+str(boundBoxLY)+" mm] x [Z:"+str(boundBoxLZ)+" mm]"
App.Console.PrintMessage("Original boundBox : "+boundBox_S+"\r\n")
App.Console.PrintMessage("Original volume_ : "+str(volume_)+" mm3 ("+str(len(sel))+" element(s))"+"\r\n")
App.Console.PrintMessage("Original surface : "+str(surface)+" mm2 ("+str(len(sel))+" element(s))"+"\r\n")
App.Console.PrintMessage("- - - - - - - - - -"+"\r\n")
try:
obj = comptName = ""
import Draft
for copies in range(1,copyNumber+1): ##### Boucle copies Debut ###########################
if copyNumber > 1:
comptName = str(copies)
if cloneCopy == 1: # clone ok
if self.checkBox_00.isChecked(): # create clone unique with all object
#import Draft
mess = "Clone"
obj=Draft.clone(sel)
try:
obj.Scale = (uniteM_X, uniteM_Y, uniteM_Z)
except Exception:
try:
FreeCAD.ActiveDocument.getObject(obj.Name).Length.Value = (sel[0].Length.Value * uniteM_X)
FreeCAD.ActiveDocument.getObject(obj.Name).Thickness.Value = (sel[0].Thickness.Value * uniteM_Y)
FreeCAD.ActiveDocument.getObject(obj.Name).Width.Value = (sel[0].Width.Value * uniteM_Z)
except Exception:
None
if self.checkBox.isChecked(): # if checkbox is checked then .... increment
obj.Placement=App.Placement(App.Vector(placement_X,placement_Y,placement_Z), App.Rotation(Yaw_Z,Pitch_Y,Roll_X), App.Vector(0,0,0)).multiply(App.activeDocument().getObject(obj.Name).Placement) # increment
else:
obj.Placement=App.Placement(App.Vector(placement_X,placement_Y,placement_Z), App.Rotation(Yaw_Z,Pitch_Y,Roll_X), App.Vector(0,0,0))
oL = obj.Label[:5] + " " + comptName + " " + obj.Label[6:]
obj.Label = oL
else: # create object separated
#import Draft
mess = "Clone"
for i in range(len(sel)):
obj=Draft.clone(sel[i])
try:
obj.Scale = (uniteM_X, uniteM_Y, uniteM_Z)
except Exception:
try:
FreeCAD.ActiveDocument.getObject(obj.Name).Length.Value = (sel[i].Length.Value * uniteM_X)
FreeCAD.ActiveDocument.getObject(obj.Name).Thickness.Value = (sel[i].Thickness.Value * uniteM_Y)
FreeCAD.ActiveDocument.getObject(obj.Name).Width.Value = (sel[i].Width.Value * uniteM_Z)
except Exception:
None
if self.checkBox.isChecked(): # if checkbox is checked then .... increment
obj.Placement=App.Placement(App.Vector(placement_X,placement_Y,placement_Z), App.Rotation(Yaw_Z,Pitch_Y,Roll_X), App.Vector(0,0,0)).multiply(App.activeDocument().getObject(sel[i].Name).Placement) # increment
else:
obj.Placement=App.Placement(App.Vector(placement_X,placement_Y,placement_Z), App.Rotation(Yaw_Z,Pitch_Y,Roll_X), App.Vector(0,0,0))
oL = obj.Label[:5] + " " + comptName + " " + obj.Label[6:]
obj.Label = oL
obj.touch() # recompute l'objet
if len(sel) > 1:
obj = ""
if cloneCopy == 0: # copy ok
#import Draft
#import Part
mess = "Copy "
for i in range(len(sel)):
obj = Draft.scale(sel[i],App.Vector(uniteM_X, uniteM_Y, uniteM_Z),center=App.Vector(0,0,0),copy=True)
if self.checkBox.isChecked(): # if checkbox is checked then .... increment
obj.Placement=App.Placement(App.Vector(placement_X,placement_Y,placement_Z), App.Rotation(Yaw_Z,Pitch_Y,Roll_X), App.Vector(0,0,0)).multiply(App.activeDocument().getObject(obj.Name).Placement) # increment
else:
obj.Placement=App.Placement(App.Vector(placement_X,placement_Y,placement_Z), App.Rotation(Yaw_Z,Pitch_Y,Roll_X), App.Vector(0,0,0))
obj2 = Part.show(obj.Shape)
FreeCADGui.activeDocument().activeObject().LineColor = sel[i].ViewObject.LineColor
FreeCADGui.activeDocument().activeObject().PointColor = sel[i].ViewObject.PointColor
FreeCADGui.activeDocument().activeObject().ShapeColor = sel[i].ViewObject.ShapeColor
App.ActiveDocument.ActiveObject.Label = "Copy " + comptName + " of " + sel[i].Label
App.ActiveDocument.removeObject(obj.Name)
obj = App.ActiveDocument.ActiveObject
if cloneCopy == 2: # compound ok
#import Draft
mess = "Compount "
liste = []
########################################################################################################################
# objori = Draft.makeBlock(Gui.Selection.getSelection()) # create Block other method compound
# obj = Draft.scale([objori],delta=App.Vector(uniteM_X, uniteM_Y, uniteM_Z),center=App.Vector(0,0,0))
# App.activeDocument().removeObject(objori.Name)
########################################################################################################################
#######################################################################################################################
objori = App.activeDocument().addObject("Part::Compound","Compound") # create method compound
for i in range(len(sel)):
objori.Links += App.activeDocument().getObject(sel[i].Name),
liste.append(sel[i].Name)
App.ActiveDocument.ActiveObject.recompute()
obj = Draft.scale(App.ActiveDocument.ActiveObject,App.Vector(uniteM_X, uniteM_Y, uniteM_Z),center=App.Vector(0,0,0),copy=True)#,copy=False
#######################################################################################################################
if self.checkBox.isChecked(): # if checkbox is checked then .... increment
obj.Placement=App.Placement(App.Vector(placement_X,placement_Y,placement_Z), App.Rotation(Yaw_Z,Pitch_Y,Roll_X), App.Vector(0,0,0)).multiply(App.activeDocument().getObject(obj.Name).Placement) # increment
else:
obj.Placement=App.Placement(App.Vector(placement_X,placement_Y,placement_Z), App.Rotation(Yaw_Z,Pitch_Y,Roll_X), App.Vector(0,0,0))
obj.Label = "Compount " + comptName + " of " + obj.Label
try:
objori.Label = "Ori " + obj.Label # renamme the original object
except Exception:
None
# try: # optional delette the original objects
# App.activeDocument().removeObject(objori.Name)
# for i in liste:
# App.activeDocument().removeObject(i)
# except:
# None
##### Boucle copies Fin ###########################
FreeCAD.ActiveDocument.recompute()
# boundinbox (dimensions hors tout)
try:
boundBox_ = obj.Shape.BoundBox
boundBoxLX = boundBox_.XLength
boundBoxLY = boundBox_.YLength
boundBoxLZ = boundBox_.ZLength
except:
boundBox_ = 0.0
boundBoxLX = 0.0
boundBoxLY = 0.0
boundBoxLZ = 0.0
# volume
volume_ = 0.0
try:
volume_ = obj.Shape.Volume
except Exception:
try:
for i in range(len(obj)):
volume_ += obj[i].Shape.Volume
except Exception:
volume_ = 0.0
# surface
surface = 0.0
try:
surface = obj.Shape.Area
except:
try:
for i in range(len(obj)):
surface += obj[i].Shape.Area
except Exception:
surface = 0.0
try:
App.Console.PrintMessage(obj.Label+"\r\n")
except Exception:
App.Console.PrintMessage("\r\n")
App.Console.PrintMessage("Convert mm in ' "+uniteMs+" ' (1 "+uniteMs+" = "+str(uniteM)+" mm)"+"\r\n")
App.Console.PrintMessage(mess + " boundBox_X : "+str(boundBoxLX)+" mm"+"\r\n")
App.Console.PrintMessage(mess + " boundBox_Y : "+str(boundBoxLY)+" mm"+"\r\n")
App.Console.PrintMessage(mess + " boundBox_Z : "+str(boundBoxLZ)+" mm"+"\r\n")
App.Console.PrintMessage(mess + " volume : "+str(volume_)+" mm3 ("+str(len(sel))+" element(s))"+"\r\n")#
App.Console.PrintMessage(mess + " surface : "+str(surface)+" mm2 ("+str(len(sel))+" element(s))"+"\r\n")#
App.Console.PrintMessage("___________________"+"\r\n")
self.pushButton_1.setStyleSheet("background-color: green")
except Exception:
FreeCAD.Console.PrintError("Error interne"+"\r\n")
else:
self.pushButton_1.setStyleSheet("background-color: red")#red
self.pushButton_1.setToolTip("Not object selected for Convert or copy")
FreeCAD.Console.PrintError("Select an object"+"\r\n") #App.Console.PrintMessage
sel = ""
def on_pushButton02_clicked(self): # Bouton Quitter
App.Console.PrintMessage("End CloneConvert\r\n")
self.window.hide()
def on_PB_Help(self): #
import WebGui
WebGui.openBrowser("http://www.freecadweb.org/wiki/index.php?title=Macro_CloneConvert")
App.Console.PrintMessage("http://www.freecadweb.org/wiki/index.php?title=Macro_CloneConvert" + "\n")
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetString("Version",__version__ + " (" + __date__ + ")")#
sel = FreeCADGui.Selection.getSelection()
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow(MainWindow)
#ui.setupUi(MainWindow)
MainWindow.show()
@mario52a

This comment has been minimized.

Copy link
Owner Author

mario52a commented Sep 20, 2016

This macro utility is intended for the use of the program FreeCAD http://www.freecadweb.org/
The icon for your toolbar, it is to place in your macros directory (in the same location of the macro)

macro_cloneconvert rename the image in Macro_CloneConvert.png

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.