Skip to content

Instantly share code, notes, and snippets.

@mario52a
Last active August 12, 2021 23:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mario52a/7be361a8c489deec918f664fdcfc4394 to your computer and use it in GitHub Desktop.
Save mario52a/7be361a8c489deec918f664fdcfc4394 to your computer and use it in GitHub Desktop.
Draf command set in a small macro for the 2D sketch example : files DXF
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
"""
***************************************************************************
* Copyright (c) 2016 2017 2018 <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. *
* *
* 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_Compound_Plus 05/08/2016 /_00 24/01/2018
#
#OS: Windows 10
#Word size of OS: 64-bit
#Word size of FreeCAD: 64-bit
#Version: 0.16.6706 (Git)
#Build type: Release
#Branch: releases/FreeCAD-0-16
#Hash: f86a4e411ff7848dea98d7242f43b7774bee8fa0
#Python version: 2.7.8
#Qt version: 4.8.7
#Coin version: 4.0.0a
#OCC version: 6.8.0.oce-0.17
#
__title__ = "Macro_Compound_Plus"
__author__ = "Mario52"
__url__ = "http://www.freecadweb.org/index-fr.html"
__version__ = "00.02"
__date__ = "24/01/2018"
import PySide
from PySide import QtGui ,QtCore
from PySide.QtGui import *
from PySide.QtCore import *
import Draft, Part, FreeCAD, math, PartGui, FreeCADGui, FreeCAD
from math import sqrt, pi, sin, cos, asin
from FreeCAD import Base
App = FreeCAD
doc = App.activeDocument()
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
def errorDialog(msg):
diag = QtGui.QMessageBox(QtGui.QMessageBox.Critical,u"Error Message",msg )
diag.setWindowFlags(PySide.QtCore.Qt.WindowStaysOnTopHint) # PySide #cette fonction met la fenetre en avant
# diag.setWindowModality(QtCore.Qt.ApplicationModal) # la fonction a ete desactivee pour favoriser "WindowStaysOnTopHint"
diag.exec_()
import os, sys, platform
global PolicePath
global nomPolice
####### detect platform meme dans reset ###################
if platform.system() == "Windows" :
PolicePath = "C:/Windows/Fonts/ARIAL.TTF"
elif platform.system() == "Linux" :
PolicePath = "/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-M.ttf"
elif platform.system() == "Darwin":
PolicePath = "/Library/Fonts/Arial.ttf"
else:
PolicePath = "C:/Windows/Fonts/ARIAL.TTF"
nomPolice = os.path.basename(PolicePath).split('.')[0]
class Ui_Compound(object):
def __init__(self):
#self.path = "Your Path"
#self.path = FreeCAD.ConfigGet("AppHomePath")
self.path = FreeCAD.ConfigGet("UserAppData")
self.nameL = []
self.comP = []
del self.nameL[:]
del self.comP[:]
self.red = 255.0
self.green = 0.0
self.blue = 0.0
self.lineWidth = 2.0
self.font = ""
self.TextLabel = ""
self.TextLabelText = ""
self.TextPosition = ""
self.TextFontSize = 8.0
self.TextTextColor = ""
self.FontSize = 8.0
self.fonte = ""
self.fontGlobal_08 = "" # pour compatibilite Windows Linux pour tous les textes
self.manuel = False
global PolicePath
global nomPolice
# self.pathFont = QtGui.QDesktopServices.storageLocation(QtGui.QDesktopServices.FontsLocation) # path font search
# self.fonteComp = self.pathFont + "/" + self.nomPolice + ".TTF"
# self.fonteComp = self.fonteComp.replace("\\","/")
def setupUi(self, MainWindow):
global PolicePath
global nomPolice
self.window = MainWindow
Compound.setObjectName(_fromUtf8("Compound"))
Compound.resize(250, 440)
MainWindow.setMinimumSize(QtCore.QSize(250, 440))
MainWindow.setMaximumSize(QtCore.QSize(250, 440))
self.centralwidget = QtGui.QWidget(Compound)
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.PB_01_Compound_01 = QtGui.QPushButton(self.centralwidget)
self.PB_01_Compound_01.setGeometry(QtCore.QRect(10, 40, 75, 23))
self.PB_01_Compound_01.setFont(self.fontGlobal_08)
self.PB_01_Compound_01.setToolTip("Make a compound Block unique")
self.PB_01_Compound_01.setObjectName(_fromUtf8("PB_01_Compound_01"))
self.PB_01_Compound_01.clicked.connect(self.on_PB_01_Compound_01) #
self.PB_02_Compound_02 = QtGui.QPushButton(self.centralwidget)
self.PB_02_Compound_02.setGeometry(QtCore.QRect(10, 70, 75, 23))
self.PB_02_Compound_02.setFont(self.fontGlobal_08)
self.PB_02_Compound_02.setToolTip("Make a compound same Part, Menu > Part > Make compound")
self.PB_02_Compound_02.setObjectName(_fromUtf8("PB_02_Compound_02"))
self.PB_02_Compound_02.clicked.connect(self.on_PB_02_Compound_02) #
self.groupBox_00 = QtGui.QGroupBox(self.centralwidget)
self.groupBox_00.setGeometry(QtCore.QRect(10, 100, 231, 91))
self.groupBox_00.setAlignment(Qt.AlignLeft) # AlignLeft AlignCenter AlignRight
self.groupBox_00.setFont(self.fontGlobal_08)
self.groupBox_00.setToolTip("If this box is unchecked the colors attributes and width line\n"
"of the original line(s) are not modified\n"
"This chekBox work only with Compound II\n"
"Same attributes Part, Menu > Part > Make compound")
self.groupBox_00.setCheckable(True)
self.groupBox_00.setObjectName(_fromUtf8("groupBox_00"))
self.PB_03_Color = QtGui.QPushButton(self.groupBox_00)
self.PB_03_Color.setGeometry(QtCore.QRect(10, 30, 75, 23))
self.PB_03_Color.setFont(self.fontGlobal_08)
self.PB_03_Color.setToolTip("Change the color of object(s) selected(s) value by defaut rvb 255,0,0")
self.PB_03_Color.setObjectName(_fromUtf8("PB_03_Color"))
self.PB_03_Color.clicked.connect(self.on_PB_03_Color) #
self.PB_03_Color.setStyleSheet("background-color: rgb("+str(self.red)+","+str(self.green)+","+str(self.blue)+"); color: cmj("+str(255)+","+str(255)+","+str(255)+")")
self.DS_01_Width = QtGui.QDoubleSpinBox(self.groupBox_00)
self.DS_01_Width.setGeometry(QtCore.QRect(10, 60, 73, 22))
self.DS_01_Width.setFont(self.fontGlobal_08)
self.DS_01_Width.setToolTip("Give a new width for the line(s) selected(s)")
self.DS_01_Width.setObjectName(_fromUtf8("DS_01_Width"))
self.DS_01_Width.setValue(self.lineWidth)
self.DS_01_Width.valueChanged.connect(self.on_DS_01_Width_valueChanged) #
self.PB_04_Convert = QtGui.QPushButton(self.centralwidget)
self.PB_04_Convert.setGeometry(QtCore.QRect(10, 200, 75, 23))
self.PB_04_Convert.setFont(self.fontGlobal_08)
self.PB_04_Convert.setToolTip("Convert the selected text in ShapeString\n"
"By default Convert (A)utomatic use the font preselected and the size of original text\n"
"If the values or font is modified the button change of Convert (M)anual\n"
"The label of the texte are modified to SString_original text (max 30 characters)")
self.PB_04_Convert.setObjectName(_fromUtf8("PB_04_Convert"))
self.PB_04_Convert.clicked.connect(self.on_PB_04_Convert) # ""
if platform.system() == "Windows" :
self.fontComboBox = QtGui.QFontComboBox(self.centralwidget)
self.fontComboBox.setGeometry(QtCore.QRect(100, 225, 141, 35))
font = QtGui.QFont()
font.setFamily(nomPolice)
font.setPointSize(self.FontSize)
# self.fontComboBox.setFont(self.fontGlobal_08)
self.fontComboBox.setCurrentFont(font)
self.fontComboBox.setToolTip("New font.\nActual : "+nomPolice)
self.fontComboBox.setObjectName(_fromUtf8("fontComboBox"))
self.fontComboBox.currentFontChanged.connect(self.on_PB_Fonte_Win01) #
self.DS_02_Width_Font = QtGui.QDoubleSpinBox(self.centralwidget)
self.DS_02_Width_Font.setGeometry(QtCore.QRect(10, 230, 73, 22))
self.DS_02_Width_Font.setFont(self.fontGlobal_08)
self.DS_02_Width_Font.setToolTip("Give a new width for the font")
self.DS_02_Width_Font.setObjectName(_fromUtf8("DS_02_Width_Font"))
self.DS_02_Width_Font.setValue(self.FontSize)
self.DS_02_Width_Font.valueChanged.connect(self.on_DS_02_Width_Font_valueChanged) #
else: # Linux +
import os.path
nomPolice = os.path.basename(PolicePath).split('.')[0]
self.PB_Fonte_Linux = QtGui.QPushButton(self.centralwidget)
self.PB_Fonte_Linux.setGeometry(QtCore.QRect(100, 225, 141, 35))
font = QtGui.QFont()
font.setFamily(nomPolice)
font.setPointSize(self.FontSize)
self.PB_Fonte_Linux.setFont(font)
self.PB_Fonte_Linux.setToolTip(_fromUtf8("New font.\nActual : "+nomPolice))
self.PB_Fonte_Linux.setAccessibleDescription(_fromUtf8(""))
self.PB_Fonte_Linux.setText(_fromUtf8(nomPolice))
self.PB_Fonte_Linux.setObjectName(_fromUtf8("PB_Fonte_Linux"))
self.PB_Fonte_Linux.clicked.connect(self.on_PB_Fonte_Linux)
self.DS_02_Width_Font = QtGui.QDoubleSpinBox(self.centralwidget)
self.DS_02_Width_Font.setGeometry(QtCore.QRect(10, 230, 75, 23))
self.DS_02_Width_Font.setFont(self.fontGlobal_08)
self.DS_02_Width_Font.setToolTip("Give a new width for the font")
self.DS_02_Width_Font.setObjectName(_fromUtf8("DS_02_Width_Font"))
self.DS_02_Width_Font.setValue(self.FontSize)
self.DS_02_Width_Font.valueChanged.connect(self.on_DS_02_Width_Font_valueChanged) #
self.PB_04c_Convert_Edge = QtGui.QPushButton(self.centralwidget)
self.PB_04c_Convert_Edge.setGeometry(QtCore.QRect(10, 260, 75, 23))
self.PB_04c_Convert_Edge.setFont(self.fontGlobal_08)
self.PB_04c_Convert_Edge.setToolTip("Convert the edge to line with coordinates\n"
"Select the edge(s) in the 3D view")
self.PB_04c_Convert_Edge.setObjectName(_fromUtf8("PB_04c_Convert_Edge"))
self.PB_04c_Convert_Edge.clicked.connect(self.on_PB_04c_Convert_Edge) # ""
self.PB_05_Reset = QtGui.QPushButton(self.centralwidget)
self.PB_05_Reset.setGeometry(QtCore.QRect(10, 410, 75, 23))
self.PB_05_Reset.setFont(self.fontGlobal_08)
self.PB_05_Reset.setToolTip("Reset the values")
self.PB_05_Reset.setObjectName(_fromUtf8("PB_05_Reset"))
self.PB_05_Reset.clicked.connect(self.on_PB_05_Reset) #
self.PB_06_Downgrade = QtGui.QPushButton(self.centralwidget)
self.PB_06_Downgrade.setGeometry(QtCore.QRect(90, 410, 75, 23))
self.PB_06_Downgrade.setFont(self.fontGlobal_08)
self.PB_06_Downgrade.setToolTip("Downgrade the selected object Same Draft > Downgrade")
self.PB_06_Downgrade.setObjectName(_fromUtf8("PB_06_Downgrade"))
self.PB_06_Downgrade.clicked.connect(self.on_PB_06_Downgrade) #
self.PB_07_Quit = QtGui.QPushButton(self.centralwidget)
self.PB_07_Quit.setGeometry(QtCore.QRect(170, 410, 75, 23))
self.PB_07_Quit.setFont(self.fontGlobal_08)
self.PB_07_Quit.setToolTip("Quit Compound +")
self.PB_07_Quit.setObjectName(_fromUtf8("PB_06_Quit"))
self.PB_07_Quit.clicked.connect(self.on_PB_07_Quit) #
self.label_01_Titre = QtGui.QLabel(self.centralwidget)
self.label_01_Titre.setGeometry(QtCore.QRect(10, 10, 231, 16))
fontTitle = QtGui.QFont()
fontTitle.setPointSize(12)
self.label_01_Titre.setFont(fontTitle)
self.label_01_Titre.setObjectName(_fromUtf8("label_01_Titre"))
self.label_02_Type_1 = QtGui.QLabel(self.centralwidget)
self.label_02_Type_1.setGeometry(QtCore.QRect(100, 40, 111, 16))
self.label_02_Type_1.setFont(self.fontGlobal_08)
self.label_02_Type_1.setObjectName(_fromUtf8("label_02_Type_1"))
self.label_03_Type_2 = QtGui.QLabel(self.centralwidget)
self.label_03_Type_2.setGeometry(QtCore.QRect(100, 70, 141, 16))
self.label_03_Type_2.setFont(self.fontGlobal_08)
self.label_03_Type_2.setObjectName(_fromUtf8("label_03_Type_2"))
self.label_04_Color = QtGui.QLabel(self.groupBox_00)
self.label_04_Color.setGeometry(QtCore.QRect(100, 30, 121, 16))
self.label_04_Color.setFont(self.fontGlobal_08)
self.label_04_Color.setObjectName(_fromUtf8("label_04_Color"))
self.label_05_DSBox = QtGui.QLabel(self.groupBox_00)
self.label_05_DSBox.setGeometry(QtCore.QRect(100, 60, 121, 16))
self.label_05_DSBox.setFont(self.fontGlobal_08)
self.label_05_DSBox.setObjectName(_fromUtf8("label_05_DSBox"))
self.label_06_Convert = QtGui.QLabel(self.centralwidget)
self.label_06_Convert.setGeometry(QtCore.QRect(100, 200, 141, 16))
self.label_06_Convert.setFont(self.fontGlobal_08)
self.label_06_Convert.setObjectName(_fromUtf8("label_06_Convert"))
self.label_08_Convert_Line = QtGui.QLabel(self.centralwidget)
self.label_08_Convert_Line.setGeometry(QtCore.QRect(100, 260, 141, 16))
self.label_08_Convert_Line.setFont(self.fontGlobal_08)
self.label_08_Convert_Line.setObjectName(_fromUtf8("label_08_Convert_Line"))
self.groupBox_01 = QtGui.QGroupBox(self.centralwidget)
self.groupBox_01.setGeometry(QtCore.QRect(10, 290, 231, 81))
self.groupBox_01.setFont(self.fontGlobal_08)
self.groupBox_01.setObjectName(_fromUtf8("groupBox_01"))
self.RB_01_Default = QtGui.QRadioButton(self.groupBox_01)
self.RB_01_Default.setGeometry(QtCore.QRect(10, 20, 141, 17))
self.RB_01_Default.setFont(self.fontGlobal_08)
self.RB_01_Default.setToolTip("The line stay tel quel\n"
"For Compound I and Convert text to String")
self.RB_01_Default.setChecked(True)
self.RB_01_Default.setObjectName(_fromUtf8("RB_01_Default"))
self.RB_02_Hidden = QtGui.QRadioButton(self.groupBox_01)
self.RB_02_Hidden.setGeometry(QtCore.QRect(10, 40, 141, 17))
self.RB_02_Hidden.setFont(self.fontGlobal_08)
self.RB_02_Hidden.setToolTip("The original line are hidden after transform\n"
"For Compound I and Convert text to String")
self.RB_02_Hidden.setObjectName(_fromUtf8("RB_02_Hidden"))
self.RB_03_Delete = QtGui.QRadioButton(self.groupBox_01)
self.RB_03_Delete.setGeometry(QtCore.QRect(10, 60, 141, 17))
self.RB_03_Delete.setFont(self.fontGlobal_08)
self.RB_03_Delete.setToolTip("The original line are deleted after transform\n"
"For Compound I and Convert text to String")
# self.RB_03_Delete.setChecked(True)
self.RB_03_Delete.setObjectName(_fromUtf8("RB_03_Delete"))
self.progressBar = QtGui.QProgressBar(self.centralwidget)
self.progressBar.setGeometry(QtCore.QRect(10, 380, 231, 20))
self.progressBar.setFont(self.fontGlobal_08)
self.progressBar.setValue(0)
self.progressBar.setAlignment(QtCore.Qt.AlignCenter)
self.progressBar.setObjectName(_fromUtf8("progressBar"))
Compound.setCentralWidget(self.centralwidget)
self.retranslateUi(Compound)
QtCore.QMetaObject.connectSlotsByName(Compound)
def retranslateUi(self, Compound):
Compound.setWindowFlags(PySide.QtCore.Qt.WindowStaysOnTopHint) # PySide cette fonction met la fenetre en avant
Compound.setWindowIcon(QtGui.QIcon(self.path + 'Macro_Compound_Plus.png')) # change l'icone de la fenetre principale
Compound.setWindowTitle("Compound +")
self.PB_01_Compound_01.setText("Compound I")
self.PB_02_Compound_02.setText("Compound II")
self.groupBox_00.setTitle("Options lines")
self.PB_03_Color.setText("Color")
self.PB_04_Convert.setText("Convert (A)")
self.PB_04c_Convert_Edge.setText("Convert Edge")
self.label_01_Titre.setText("Compound +")
self.label_02_Type_1.setText("Type I [ 1 + 1 = 1 ]")
self.label_03_Type_2.setText("Type II [ 1 + 1 = A (1 + 1) ]")
self.label_04_Color.setText("Line color")
self.label_05_DSBox.setText("Width line")
self.label_06_Convert.setText("Convert Text to String")
self.label_08_Convert_Line.setText("Convert Edge to Line")
self.groupBox_01.setTitle("For Compound I and Convert")
self.RB_01_Default.setText("None")
self.RB_02_Hidden.setText("Hidden original line(s) ")
self.RB_03_Delete.setText("Delete original line(s)")
self.PB_05_Reset.setText("Reset")
self.PB_06_Downgrade.setText("DownGrade")
self.PB_07_Quit.setText("Quit")
def on_PB_01_Compound_01(self):
self.selectionObjects = FreeCADGui.Selection.getSelection()
if len(self.selectionObjects) > 0:
try:
self.nameL = []
self.comP = []
del self.nameL[:]
del self.comP[:]
self.progressBar.setMaximum(len(self.selectionObjects))
compteur = 0
for i in self.selectionObjects:
self.nameL.append(i.Name)
self.comP.append(i.Shape)
compteur += 1
self.progressBar.setValue(compteur)
Gui.updateGui()
print "Object : ",i.Name
comp = Part.makeCompound(self.comP)
Part.show(comp)
if self.groupBox_00.isChecked:
FreeCADGui.ActiveDocument.ActiveObject.LineWidth = self.lineWidth
FreeCADGui.ActiveDocument.ActiveObject.LineColor = (float(self.red)/255, float(self.green)/255, float(self.blue)/255)
FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (float(self.red)/255, float(self.green)/255, float(self.blue)/255)
FreeCADGui.ActiveDocument.ActiveObject.PointColor = (float(self.red)/255, float(self.green)/255, float(self.blue)/255)
App.ActiveDocument.ActiveObject.Label = "reproShape_TI"
if self.RB_01_Default.isChecked():
None
if self.RB_02_Hidden.isChecked():
for i in range(len(self.nameL)):
print "Hidden : ",self.nameL[i]
FreeCADGui.ActiveDocument.getObject(self.nameL[i]).Visibility = False
if self.RB_03_Delete.isChecked():
for i in range(len(self.nameL)):
print "Delete : ",self.nameL[i]
doc.removeObject(self.nameL[i])
self.progressBar.setValue(0)
except Exception:
FreeCAD.Console.PrintError("Error objects "+"\n")
else:
FreeCAD.Console.PrintError("Not objects selected "+"\n")
# FreeCAD.Console.PrintMessage(str("on_PB_01_Compound_01 ")+"\n")
def on_PB_02_Compound_02(self):
self.selectionObjects = FreeCADGui.Selection.getSelection()
if len(self.selectionObjects) > 0:
try:
self.nameL = []
self.comP = []
del self.nameL[:]
del self.comP[:]
App.activeDocument().addObject("Part::Compound","Compound")
self.progressBar.setMaximum(len(self.selectionObjects))
compteur = 0
for i in self.selectionObjects:
self.nameL.append(App.ActiveDocument.getObject(i.Name))
compteur += 1
self.progressBar.setValue(compteur)
Gui.updateGui()
print i.Name
self.progressBar.setValue(0)
App.activeDocument().Compound.Links = self.nameL
App.activeDocument().recompute()
if self.groupBox_00.isChecked:
FreeCADGui.ActiveDocument.ActiveObject.LineWidth = self.lineWidth
FreeCADGui.ActiveDocument.ActiveObject.LineColor = (float(self.red)/255, float(self.green)/255, float(self.blue)/255)
FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (float(self.red)/255, float(self.green)/255, float(self.blue)/255)
FreeCADGui.ActiveDocument.ActiveObject.PointColor = (float(self.red)/255, float(self.green)/255, float(self.blue)/255)
App.ActiveDocument.ActiveObject.Label = "reproShape_TII"
except Exception:
FreeCAD.Console.PrintError("Error objects "+"\n")
else:
FreeCAD.Console.PrintError("Not objects selected "+"\n")
# FreeCAD.Console.PrintMessage(str("on_PB_02_Compound_02 ")+"\n")
def on_PB_03_Color(self):
self.PB_03_Color.setStyleSheet("background-color: QPalette.Base") # origin system
self.window.hide() # hide the window open color
couleur = QtGui.QColorDialog.getColor()
if couleur.isValid():
self.red = int(str(couleur.name()[1:3]),16)
self.green = int(str(couleur.name()[3:5]),16)
self.blue = int(str(couleur.name()[5:7]),16)
self.PB_03_Color.setStyleSheet("background-color: rgb("+str(self.red)+","+str(self.green)+","+str(self.blue)+"); color: cmj("+str(255)+","+str(255)+","+str(255)+")")
self.window.show() # show the window and close color
# FreeCAD.Console.PrintMessage(str("PB_03_Color ")+"\n")
def on_PB_04_Convert(self):
global PolicePath
global nomPolice
self.selectionObjects = FreeCADGui.Selection.getSelection()
self.progressBar.setMaximum(len(self.selectionObjects))
compteur = 0
if len(self.selectionObjects) > 0:
objA = self.selectionObjects[0]
for objA in self.selectionObjects:
try:
self.TextLabel = objA.Label
self.TextLabelText = objA.LabelText[0]
self.TextPosition = objA.Position
self.TextFontSize = objA.ViewObject.FontSize
if self.manuel:
self.TextFontSize = self.FontSize
self.TextTextColor = objA.ViewObject.TextColor
texte = unicode(self.TextLabelText)
ss=Draft.makeShapeString(String = texte, FontFile=PolicePath, Size=float(self.TextFontSize), Tracking=0)
plm=FreeCAD.Placement()
plm.Base=self.TextPosition
plm.Rotation.Q=(0.0,-0.0,-0.0,1.0)
ss.Placement=plm
ss.Support=None
ss.Label = "SString_"+texte[:30]
FreeCADGui.ActiveDocument.getObject(ss.Name).ShapeColor = (float(self.red)/255, float(self.green)/255, float(self.blue)/255)
FreeCADGui.ActiveDocument.getObject(ss.Name).LineColor = (float(self.red)/255, float(self.green)/255, float(self.blue)/255)
FreeCADGui.ActiveDocument.getObject(ss.Name).PointColor = (float(self.red)/255, float(self.green)/255, float(self.blue)/255)
compteur += 1
self.progressBar.setValue(compteur)
if self.RB_01_Default.isChecked():
None
if self.RB_02_Hidden.isChecked():
print "Hidden : ",objA.Name
FreeCADGui.ActiveDocument.getObject(objA.Name).Visibility = False
if self.RB_03_Delete.isChecked():
print "Delete : ",objA.Name
doc.removeObject(objA.Name)
Gui.updateGui()
except Exception:
FreeCAD.Console.PrintError("Not object TEXT or error" + "\n")
self.progressBar.setValue(0)
FreeCAD.ActiveDocument.recompute()
else:
FreeCAD.Console.PrintError("Select one or more objects TEXT" + "\n")
# FreeCAD.Console.PrintMessage(str("on_PB_04_Convert ")+"\n")
def on_PB_Fonte_Win01(self): # New Font Windows (menu deroulant) fonctionne ok
global PolicePath
global nomPolice
Compound.hide()
fonte = self.fontComboBox.currentFont()
nomPolice = fonte.rawName()
self.fontComboBox.setToolTip("New font.\nActual : "+nomPolice)
pathFont = QtGui.QDesktopServices.storageLocation(QtGui.QDesktopServices.FontsLocation) # path font search bon pour Windows
fonteComp = pathFont + "/" + nomPolice + ".TTF"
PolicePath = fonteComp.replace("\\","/")
font = QtGui.QFont()
font.setFamily(nomPolice)
font.setPointSize(self.FontSize)
self.fontComboBox.setFont(font)
self.PB_04_Convert.setText("Convert (M)")
self.manuel = True
Compound.show()
# App.Console.PrintMessage("New Font " + (PolicePath)+"\n")
def on_DS_02_Width_Font_valueChanged(self,value):
self.FontSize = value
self.PB_04_Convert.setText("Convert (M)")
font = QtGui.QFont()
font.setFamily(nomPolice)
font.setPointSize(self.FontSize)
if platform.system() == "Windows" :
self.fontComboBox.setFont(font)
else:
self.PB_Fonte_Linux.setFont(font)
self.PB_Fonte_Linux.setText(_fromUtf8(nomPolice))
self.manuel = True
# App.Console.PrintMessage("New FontSize " + str(self.FontSize)+"\n")
def on_PB_Fonte_Win02(self): # New Font Windows (menu avec fenetres)
global PolicePath
global nomPolice
Compound.hide()
font, ok = QtGui.QFontDialog.getFont(QFont(nomPolice, self.FontSize))
if ok:
fonte = font
nomPolice = fonte.rawName()
self.FontSize = fonte.pointSizeF()
pathFont = QtGui.QDesktopServices.storageLocation(QtGui.QDesktopServices.FontsLocation) # path font search bon pour Windows
fonteComp = pathFont + "/" + nomPolice + ".TTF"
PolicePath = fonteComp.replace("\\","/")
font = QtGui.QFont()
font.setFamily(nomPolice)
font.setPointSize(self.FontSize)
self.label_07_Font.setFont(font)
self.label_07_Font.setText("Actual (" + str(self.FontSize) + ") " + nomPolice)
self.label_07_Font.setToolTip("Actual (" + str(self.FontSize) + ") " + nomPolice)
self.PB_04_Convert.setText("Convert (M)")
self.manuel = True
Compound.show()
def on_PB_Fonte_Linux(self): # New Font Linux
global PolicePath
global nomPolice
Compound.hide()
OpenName = ""
OpenName, Filter = PySide.QtGui.QFileDialog.getOpenFileName(None, "New Font", PolicePath, "*.ttf") #PySide
try:
if OpenName != "":
PolicePath = str(OpenName)
import os.path
nomPolice = os.path.basename(PolicePath).split('.')[0]
font = QtGui.QFont()
font.setFamily(nomPolice)
font.setPointSize(self.FontSize)
self.PB_Fonte_Linux.setText(nomPolice)
self.PB_Fonte_Linux.setFont(font)
self.PB_Fonte_Linux.setToolTip(_fromUtf8("New font.\nActual : "+nomPolice))
except Exception:
None
Compound.show()
# App.Console.PrintMessage("New Font " + (PolicePath)+"\n")
def on_PB_04c_Convert_Edge(self): # Convert Edge to line
import Draft
points = []
points[:] = []
selectionObjects = FreeCADGui.Selection.getSelectionEx() # Select an object or sub object getSelectionEx
for selection in selectionObjects:
for selectedEdge in selection.SubObjects:
if (str(selectedEdge.Curve)[1:5]) == "Line" :
numberCut = 1 # line
else:
numberCut = 20 # not line cut in 20 parts
points = selectedEdge.Edges[0].discretize(int(numberCut + 1)) # Dicretize
for lin in range(len(points)-1):
creaLine = [FreeCAD.Vector(points[lin]),FreeCAD.Vector(points[lin+1])]
wire = Draft.makeLine(FreeCAD.Vector(creaLine[0]),FreeCAD.Vector(creaLine[1]))
if self.groupBox_00.isChecked:
FreeCADGui.ActiveDocument.ActiveObject.LineWidth = self.lineWidth
FreeCADGui.ActiveDocument.ActiveObject.LineColor = (float(self.red)/255, float(self.green)/255, float(self.blue)/255)
FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (float(self.red)/255, float(self.green)/255, float(self.blue)/255)
FreeCADGui.ActiveDocument.ActiveObject.PointColor = (float(self.red)/255, float(self.green)/255, float(self.blue)/255)
points[:] = []
FreeCAD.ActiveDocument.recompute()
# FreeCAD.Console.PrintMessage(str("on_PB_04c_Convert_Edge")+"\n")
def on_DS_01_Width_valueChanged(self,LineWidth):
self.lineWidth = LineWidth
# FreeCAD.Console.PrintMessage(str("on_DS_01_Width_valueChanged ")+str(self.lineWidth)+"\n")
def on_PB_05_Reset(self): #
global PolicePath
global nomPolice
self.red = 255.0
self.green = 0.0
self.blue = 0.0
self.PB_03_Color.setStyleSheet("background-color: rgb("+str(self.red)+","+str(self.green)+","+str(self.blue)+"); color: cmj("+str(255)+","+str(255)+","+str(255)+")")
# self.RB_01_Default.setChecked(True)
self.RB_03_Delete.setChecked(True)
self.lineWidth = 2.0
self.DS_01_Width.setValue(self.lineWidth)
self.FontSize = 8.0
if platform.system() == "Windows" :
PolicePath = "C:/Windows/Fonts/ARIAL.TTF"
nomPolice = os.path.basename(PolicePath).split('.')[0]
self.DS_02_Width_Font.setValue(self.FontSize)
font = QtGui.QFont()
font.setFamily(nomPolice)
font.setPointSize(self.FontSize)
self.fontComboBox.setCurrentFont(font)
else:
if platform.system() == "Linux" :
PolicePath = "/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-M.ttf"
elif platform.system() == "Darwin":
PolicePath = "/Library/Fonts/Arial.ttf"
else:
PolicePath = FreeCAD.ConfigGet("AppHomePath")
self.PB_Fonte_Linux.setText("New Font")
nomPolice = os.path.basename(PolicePath).split('.')[0]
font = QtGui.QFont()
font.setFamily(nomPolice)
font.setPointSize(self.FontSize)
self.PB_Fonte_Linux.setFont(font)
self.PB_Fonte_Linux.setText(nomPolice)
self.PB_Fonte_Linux.setToolTip(_fromUtf8("New font.\nActual : "+nomPolice))
self.DS_02_Width_Font.setValue(self.FontSize)
self.manuel = False
self.PB_04_Convert.setText("Convert (A)")
self.fonte = PolicePath + "/" + nomPolice + ".TTF"
# FreeCAD.Console.PrintMessage(str("on_PB_05_Reset ")+"\n")
def on_PB_06_Downgrade(self): #
try:
import Draft
Draft.downgrade(FreeCADGui.Selection.getSelection(),delete=True)
FreeCAD.ActiveDocument.recompute()
print
except Exception:
None
# FreeCAD.Console.PrintMessage(str("on_PB_06_Downgrade ")+"\n")
def on_PB_07_Quit(self): #
FreeCAD.Console.PrintMessage("End Compound +"+"\n")
self.window.hide()
# FreeCAD.Console.PrintMessage(str("on_PB_06_Quit ")+"\n")
Compound = QtGui.QMainWindow()
ui = Ui_Compound()
ui.setupUi(Compound)
Compound.show()
@mario52a
Copy link
Author

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_compound_plus rename the image in ** Macro_Compound_Plus.png**

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment