Macro PropertyMemo/fr: Difference between revisions

From FreeCAD Documentation
(Created page with "* '''Memo''' : Titre de la propriété ici Memo (par défaut) * '''Name''' : Nom de la propriété ici, Name * Le champ libre nouvellement créé est à compléter manuellement")
No edit summary
(32 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<languages/>
{{Macro/fr|Icon=PropertyMemo|Name=Macro_PropertyMemo|Name/fr=Macro_PropertyMemo|Description=Cette petite macro vous permet d'ajouter une Propriété (mémo ou autre texte) à un objet Draft.|Author=Mario52}}
{{Macro/fr
|Name=Macro_PropertyMemo
|Icon=PropertyMemo.png
|Description={{ColoredText|#ff0000|#ffffff|Nouvelle interface graphique modifiée pour fonctionner en HD dpi (QGridLayout), uniquement la version FC 0.19 et plus (PySide2 Qt5)}} <br/> <br/>
Pour la version précédente, voir [https://gist.githubusercontent.com/mario52a/eafcf79703fab64b8da5/raw/51702c17fb4b205da52488bf2a239011bbbc9da5/Macro_FCPropertyMemo.FCMacro Macro_FCPropertyMemo.FCMacro] et l'installer manuellement.
Cette petite macro vous permet d'ajouter une Propriété (mémo ou autre texte) uniquement à un objet Draft.
|Author=Mario52
|Version=2020-05-17
|FCVersion=0.19
|Download=[https://www.freecadweb.org/wiki/images/f/f2/PropertyMemo.png ToolBar Icon]
}}


==Description==
==Description==
Cette petite macro vous permet d'ajouter une Propriété (mémo ou autre texte) à un objet Draft (pour le moment uniquement sur objet Draft)
Cette petite macro vous permet d'ajouter une Propriété (mémo ou autre texte) à un objet Draft (pour le moment uniquement sur objet Draft)


[[Image:Macro_FCPropertyMemo_00.png|Ajoute une propriété Memo > Name]]
[[Image:Macro_FCPropertyMemo_00.png]]
{{Caption|Addin one property Memo → Name}}

==Utilisation==
==Utilisation==
Lancez la macro sélectionnez un objet Draft complétez les champs et appliquez la modification. Une nouvelle propriété est créée dans la Vue combinée '''Vue combinée > Property > Data tab'''
Lancez la macro sélectionnez un objet Draft complétez les champs et appliquez la modification. Une nouvelle propriété est créée dans la Vue combinée '''Vue combinée Property Data tab'''


*'''Property title''' = Titre de la nouvelle propriété (Defaut: Memo)
*'''Property title''' : Titre de la nouvelle propriété (Defaut: Memo)
*'''Property name''' = nom de la nouvelle propriété
*'''Property name''' ! nom de la nouvelle propriété
*{{CheckBox|TRUE|UnCheck for String}} : checkBox pour le choix de la chaîne ou de la liste (par défaut)


[[File:Macro_FCPropertyMemo_01.png|left|Une propriété Memo est créée]]
[[File:Macro_FCPropertyMemo_01.png|left|Une propriété Memo est créée]]
Line 17: Line 31:
* Le champ libre nouvellement créé est à compléter manuellement
* Le champ libre nouvellement créé est à compléter manuellement
{{clear}}
{{clear}}
La case à cocher vous donne le choix entre deux options. Si la case à cocher est activé, vous avez la possibilité de créer une liste de mémos que vous pouvez modifier dans une fenêtre si non le mémo sera affiché dans une ligne (option par défaut)

<center>
<gallery widths="400" heights="200">
Image:Macro_FCPropertyMemo_02.png|Property Mémo liste.
Image:Macro_FCPropertyMemo_03.png|La fenêtre Mémo liste.
</gallery>
</center>
{{clear}}

==Script==
==Script==
L'icône disponible pour votre barre d'outils [[File:PropertyMemo.png]]


'''Macro_FCPropertyMemo.FCMacro'''
'''Macro_FCPropertyMemo.FCMacro'''


{{MacroCode|code=
The icon for the ToolBar [[File:PropertyMemo.png]]

<syntaxhighlight>
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import unicode_literals
"""
"""
***************************************************************************
***************************************************************************
* Copyright (c) 2015 <mario52> *
* Copyright (c) 2015, 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 36: 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 51: Line 80:
***************************************************************************
***************************************************************************
"""
"""
#Macro_FCMemo 28/09/2015 /_00
#Macro_FCPropertyMemo 28/09/2015, 19/10/2015, 2020/05/17
#
#
#

#OS: Windows 8
#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.15.4671 (Git)
#Version: 0.19.20887 (Git)
#Build type: Release
#Branch: releases/FreeCAD-0-15
#Branch: master
#Hash: 244b3aef360841646cbfe80a1b225c8b39c8380c
#Hash: 42c56d9fef82b484448e3730eb7da69c48fe1374
#Python version: 2.7.8
#Qt version: 4.8.6
#Python version: 3.6.8
#Qt version: 5.12.1
#Coin version: 4.0.0a
#Coin version: 4.0.0a
#OCC version: 6.8.0.oce-0.17
#OCC version: 7.3.0
#Locale: French/Mars (fr_MA)
#
#
#
__title__ = "Macro_FCPropertyMemo"
__author__ = "Mario52"
__url__ = "https://wiki.freecadweb.org/Macro_PropertyMemo"
__urlGist = "https://gist.github.com/mario52a/eafcf79703fab64b8da5"
__version__ = "00.03"
__date__ = "2020/05/17" #YYYY/MM/DD


#### Test FreeCAD.Version simple ############################################################################################################
__title__="Macro_FCPropertyMemo"
if int(FreeCAD.Version()[1]) < 19: # Version de FreeCAD
__author__ = "Mario52"
FreeCAD.Console.PrintMessage("This version " + __title__ + " rmu work with the FreeCAD 0.19 or higher." + "\n\n")
__url__ = "http://www.freecadweb.org/index-fr.html"
FreeCAD.Console.PrintMessage("For the precedent version see the page " + "\n\n")
__version__ = "00.00"
FreeCAD.Console.PrintMessage("https://gist.githubusercontent.com/mario52a/eafcf79703fab64b8da5/raw/51702c17fb4b205da52488bf2a239011bbbc9da5/Macro_FCPropertyMemo.FCMacro" + "\n\n")
__date__ = "28/09/2015"


#### Test FreeCAD.Version simple ############################################################################################################
try:

import PyQt4
import PySide2
from PyQt4 import QtGui ,QtCore
from PySide2 import (QtWidgets, QtCore, QtGui)
from PyQt4.QtGui import *
from PySide2.QtWidgets import (QWidget, QApplication, QSlider, QGraphicsView, QGraphicsScene, QVBoxLayout, QStyle)
from PyQt4.QtCore import *
from PySide2.QtGui import (QPainter, QColor, QIcon)
except Exception:
import PySide
from PySide2.QtSvg import *
from PySide import QtGui ,QtCore
from PySide.QtGui import *
from PySide.QtCore import *
#import Draft, Part, FreeCAD, math, PartGui, FreeCADGui, FreeCAD
#import Draft, Part, FreeCAD, math, PartGui, FreeCADGui, FreeCAD


Line 88: Line 123:
path = FreeCAD.ConfigGet("UserAppData")
path = FreeCAD.ConfigGet("UserAppData")


global title_01 ; title_01 = "Memo" # title of menu
global title_01 ; title_01 = "Memo" # title of menu
global title_02 ; title_02 = "" # title of propriety
global title_02 ; title_02 = "" # title of propriety
global memo_01 ; memo_01 = "" # memo
global memo_01 ; memo_01 = "" # memo
global forString; forString = 1 # memo for String or List
global ui ; ui = "" #


try:
try:
Line 114: Line 151:
global title_02
global title_02
global memo_01
global memo_01

##path###########################################################################
#path = FreeCAD.ConfigGet("AppHomePath")
#path = FreeCAD.ConfigGet("UserAppData")
#path = "your path"
param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro")# macro path
self.path = param.GetString("MacroPath","") + "/" # macro path
self.path = self.path.replace("\\","/")
#App.Console.PrintMessage(str("Path for the icons : ") + self.path + "\n" + __title__ + " : " +__version__ + " " + __date__ + "\n")
# #################################################################################


MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(254, 163)
# MainWindow.resize(260, 200)
# MainWindow.resize(241, 211)
# MainWindow.setMinimumSize(QtCore.QSize(254, 163))
MainWindow.setMinimumSize(QtCore.QSize(254, 163))
# MainWindow.setMaximumSize(QtCore.QSize(254, 163))

MainWindow.setMaximumSize(QtCore.QSize(254, 163))
###### Read Configuration begin ####
self.centralwidget = QtGui.QWidget(MainWindow)
title_01 = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).GetString("LE_Edit_01")
title_02 = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).GetString("LE_Edit_02")
CBString = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).GetBool("CB_String")
###### Read Configuration end ####

self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))


self.PB_Button_01 = QtGui.QPushButton(self.centralwidget)
self.groupBox = QtWidgets.QGroupBox()
self.PB_Button_01.setGeometry(QtCore.QRect(20, 130, 61, 23))
# self.PB_Button_01.setGeometry(QtCore.QRect(20, 180, 61, 23))
self.PB_Button_01.setObjectName(_fromUtf8("PB_Button_01"))
self.PB_Button_01.clicked.connect(self.on_PB_Button_01_clicked) #


self.PB_Button_02 = QtGui.QPushButton(self.centralwidget)
self.label_00 = QtWidgets.QLabel()
self.PB_Button_02.setGeometry(QtCore.QRect(95, 130, 61, 23))
self.label_00.setAlignment(QtCore.Qt.AlignCenter)
font = QtGui.QFont()
# self.PB_Button_02.setGeometry(QtCore.QRect(90, 180, 61, 23))
font.setPointSize(10)
self.PB_Button_02.setObjectName(_fromUtf8("PB_Button_02"))
font.setBold(True)
self.PB_Button_02.clicked.connect(self.on_PB_Button_02_clicked) #
font.setUnderline(True)
font.setWeight(80)
self.label_00.setFont(font)


self.PB_Button_03 = QtGui.QPushButton(self.centralwidget)
self.label_01 = QtWidgets.QLabel()
self.PB_Button_03.setGeometry(QtCore.QRect(170, 130, 61, 23))
# self.PB_Button_03.setGeometry(QtCore.QRect(160, 180, 61, 23))
self.PB_Button_03.setObjectName(_fromUtf8("PB_Button_03"))
self.PB_Button_03.clicked.connect(self.on_PB_Button_03_clicked) #


self.LE_Edit_01 = QtGui.QLineEdit(self.centralwidget) # title
self.LE_Edit_01 = QtWidgets.QLineEdit() # title property
self.LE_Edit_01.setGeometry(QtCore.QRect(20, 50, 211, 20))
# self.LE_Edit_01.setGeometry(QtCore.QRect(20, 50, 201, 20))
self.LE_Edit_01.setObjectName(_fromUtf8("LE_Edit_01"))
self.LE_Edit_01.setText(_fromUtf8(title_01))
self.LE_Edit_01.setText(_fromUtf8(title_01))
self.LE_Edit_01.setToolTip("Title of menu property")
self.LE_Edit_01.textChanged.connect(self.on_LE_Edit_01_Pressed)
self.LE_Edit_01.textChanged.connect(self.on_LE_Edit_01_Pressed) # title property


self.LE_Edit_02 = QtGui.QLineEdit(self.centralwidget)
self.label_02 = QtWidgets.QLabel()

self.LE_Edit_02.setGeometry(QtCore.QRect(20, 100, 211, 20))
# self.LE_Edit_02.setGeometry(QtCore.QRect(20, 100, 201, 20))
self.LE_Edit_02 = QtWidgets.QLineEdit() # title name
self.LE_Edit_02.setObjectName(_fromUtf8("LE_Edit_02"))
self.LE_Edit_02.setText(_fromUtf8(title_02))
self.LE_Edit_02.setText(_fromUtf8(""))
self.LE_Edit_02.setToolTip("Title of property")
self.LE_Edit_02.textChanged.connect(self.on_LE_Edit_02_Pressed) #
self.LE_Edit_02.textChanged.connect(self.on_LE_Edit_02_Pressed) #


# self.LE_Edit_03 = QtGui.QLineEdit(self.centralwidget) # memo
# self.label_03 = QtWidgets.QLabel()

# self.LE_Edit_03.setGeometry(QtCore.QRect(20, 150, 201, 20))
# self.LE_Edit_03.setObjectName(_fromUtf8("LE_Edit_03"))
# self.LE_Edit_03 = QtWidgets.QLineEdit() # memo
# self.LE_Edit_03.setText(_fromUtf8(""))
# self.LE_Edit_03.setToolTip("Text memo for property")
# self.LE_Edit_03.textChanged.connect(self.on_LE_Edit_03_Pressed) #
# self.LE_Edit_03.textChanged.connect(self.on_LE_Edit_03_Pressed) #


self.CB_String = QtWidgets.QCheckBox() # for String or List
MainWindow.setCentralWidget(self.centralwidget)
self.CB_String.setChecked(CBString)
self.CB_String.clicked.connect(self.on_CB_String_clicked) # connect on def "on_checkBox_1_clicked"


self.label_00 = QtGui.QLabel(self.centralwidget)
self.PB_Help = QtWidgets.QPushButton()
self.PB_Help.setToolTip(_fromUtf8("Help on line " + __version__ + " " + __date__ + " rmu"))
self.label_00.setGeometry(QtCore.QRect(70, 10, 120, 21))
self.PB_Help.setIcon(QtGui.QIcon.fromTheme("help",QtGui.QIcon(":/icons/help-browser.svg")))
font = QtGui.QFont()
self.PB_Help.clicked.connect(self.on_PB_Help) #
font.setPointSize(10)
font.setBold(True)
font.setUnderline(True)
font.setWeight(75)
self.label_00.setFont(font)
self.label_00.setObjectName(_fromUtf8("label_00"))


self.label_01 = QtGui.QLabel(self.centralwidget)
self.PB_Button_01 = QtWidgets.QPushButton()
self.PB_Button_01.setIcon(QtGui.QIcon.fromTheme("refresh",QtGui.QIcon(":/icons/view-refresh.svg")))
self.label_01.setGeometry(QtCore.QRect(20, 30, 111, 16))
self.label_01.setObjectName(_fromUtf8("label_01"))
self.PB_Button_01.clicked.connect(self.on_PB_Button_01_clicked) #


self.label_02 = QtGui.QLabel(self.centralwidget)
self.PB_Button_02 = QtWidgets.QPushButton()
# self.PB_Button_02.setIcon(QIcon(QApplication.style().standardIcon(QStyle.SP_DialogOkButton))) #
self.label_02.setGeometry(QtCore.QRect(20, 80, 111, 16))
self.PB_Button_02.setIcon(QtGui.QIcon.fromTheme("execute",QtGui.QIcon(":/icons/button_valid.svg")))
self.label_02.setObjectName(_fromUtf8("label_02"))
self.PB_Button_02.clicked.connect(self.on_PB_Button_02_clicked) #


# self.label_03 = QtGui.QLabel(self.centralwidget)
self.PB_Button_03 = QtWidgets.QPushButton()
self.PB_Button_03.setIcon(QtGui.QIcon.fromTheme("close",QtGui.QIcon(":/icons/application-exit.svg")))
# self.label_03.setGeometry(QtCore.QRect(20, 130, 121, 16))
self.PB_Button_03.clicked.connect(self.on_PB_Button_03_clicked) #
# self.label_03.setObjectName(_fromUtf8("label_03"))


#### Layout debut ########################
self.grid0 = QtWidgets.QGridLayout(self.centralwidget)
self.grid0.setContentsMargins(10, 10, 10, 10)
self.grid0.addWidget(self.groupBox, 0, 0, 1, 1)
self.gridLayout = QtWidgets.QGridLayout(self.groupBox)
self.gridLayout.addWidget(self.label_00, 1, 0, 1, 4)
self.gridLayout.addWidget(self.label_01, 2, 0, 1, 4)
self.gridLayout.addWidget(self.LE_Edit_01, 3, 0, 1, 4)
self.gridLayout.addWidget(self.label_02, 4, 0, 1, 2)
self.gridLayout.addWidget(self.CB_String, 4, 2, 1, 2)
self.gridLayout.addWidget(self.LE_Edit_02, 5, 0, 1, 4)
# self.gridLayout.addWidget(self.label_03, 6, 0, 1, 4)
# self.gridLayout.addWidget(self.LE_Edit_03, 7, 0, 1, 3)
self.gridLayout.addWidget(self.PB_Help, 8, 0, 1, 1)
self.gridLayout.addWidget(self.PB_Button_01, 8, 1, 1, 1)
self.gridLayout.addWidget(self.PB_Button_02, 8, 2, 1, 1)
self.gridLayout.addWidget(self.PB_Button_03, 8, 3, 1, 1)
#### Layout fin ###########################

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


def retranslateUi(self, MainWindow):
def retranslateUi(self, MainWindow):
MainWindow.setWindowFlags(PySide2.QtCore.Qt.WindowStaysOnTopHint) # PySide2 cette fonction met la fenetre en avant
try:
MainWindow.setWindowFlags(PyQt4.QtCore.Qt.WindowStaysOnTopHint) # PyQt4 cette fonction met la fenêtre en avant
except Exception:
MainWindow.setWindowFlags(PySide.QtCore.Qt.WindowStaysOnTopHint) # PySide cette fonction met la fenêtre en avant
MainWindow.setWindowTitle("FCPropertyMemo")
self.PB_Button_01.setText("Reset")
self.PB_Button_01.setToolTip("Reset the TextEdit")
self.PB_Button_02.setText("Validate")
self.PB_Button_02.setToolTip("Validate and apply")
self.PB_Button_03.setText("Quit")


MainWindow.setWindowIcon(QtGui.QIcon(_fromUtf8(self.path + "PropertyMemo.png"))) # change l'icone de la fenetre principale
self.PB_Button_03.setToolTip("Quit the FCPropertyMemo")
_translate = QtCore.QCoreApplication.translate
self.label_00.setText("FCPropertyMemo")
MainWindow.setWindowTitle(_translate("MainWindow", "FCPropertyMemo"))
self.label_01.setText("Property title")

self.label_02.setText("Property name")
self.groupBox.setTitle(_translate("MainWindow", "ver : " + __version__ + " : " + __date__ + " (rmu)"))
# self.label_03.setText("Memo")
self.label_00.setText(_translate("MainWindow", "FCProperty Memo"))
self.label_01.setText(_translate("MainWindow", "Property title"))
self.label_02.setText(_translate("MainWindow", "Property name"))
self.CB_String.setText(_translate("MainWindow", "UnCheck for String"))
self.LE_Edit_02.setToolTip("Title of property")
# self.label_03.setText(_translate("MainWindow", "Memo"))
# self.LE_Edit_03.setText(_fromUtf8(""))
# self.LE_Edit_03.setToolTip("Text memo")
self.PB_Help.setText(_translate("MainWindow", "Wiki"))
self.PB_Button_01.setText(_translate("MainWindow", "Reset"))
self.PB_Button_02.setText(_translate("MainWindow", "Validate"))
self.PB_Button_03.setText(_translate("MainWindow", "Quit"))
self.CB_String.setToolTip("The memo is a string by default"+"\n"+
"If the checkBox is checked the memo is a list in one window"+"\n"+
"Clic the '...' in ComboView > Data")


def on_LE_Edit_01_Pressed(self): # Line edit 01 title
def on_LE_Edit_01_Pressed(self): # Line edit 01 title
global title_01
global title_01

title_01 = self.LE_Edit_01.text()
title_01 = self.LE_Edit_01.text()
# App.Console.PrintMessage(title_01+"\n")
# App.Console.PrintMessage(title_01+"\n")
Line 216: Line 281:
def on_LE_Edit_02_Pressed(self): # Line edit 02 title property
def on_LE_Edit_02_Pressed(self): # Line edit 02 title property
global title_02
global title_02

title_02 = self.LE_Edit_02.text()
title_02 = self.LE_Edit_02.text()
# App.Console.PrintMessage(title_02+"\n")
# App.Console.PrintMessage(title_02+"\n")
Line 223: Line 289:
# memo_01 = self.LE_Edit_03.text()
# memo_01 = self.LE_Edit_03.text()
# App.Console.PrintMessage(memo_01+"\n")
# App.Console.PrintMessage(memo_01+"\n")

def on_CB_String_clicked(self): # connection on_checkBox_1_clicked
global forString

if self.CB_String.isChecked(): # if checkbox_01 is checked then ....
forString = 1
self.CB_String.setText("UnCheck for String")
else :
forString = 0
self.CB_String.setText("Check for List")
# App.Console.PrintMessage("on_CB_String_clicked "+str(forString)+"\n")


def on_PB_Button_01_clicked(self): # Button Reset
def on_PB_Button_01_clicked(self): # Button Reset
Line 228: Line 305:
global title_02
global title_02
global memo_01
global memo_01
global forString

self.LE_Edit_01.clear()
self.LE_Edit_01.clear()
title_01 = "Memo"
title_01 = "Memo"
Line 235: Line 314:
# self.LE_Edit_03.clear()
# self.LE_Edit_03.clear()
# memo_01 = ""
# memo_01 = ""
self.CB_String.setChecked(True)

forString = 1
self.CB_String.setText("UnCheck for String")
# App.Console.PrintMessage("on_PB_Button_01_clicked\n")
# App.Console.PrintMessage("on_PB_Button_01_clicked\n")


def on_PB_Button_02_clicked(self): # Button Validate
def on_PB_Button_02_clicked(self): # Button Validate
global ui
global title_01
global title_01
global title_02
global title_02
global memo_01
global memo_01
try:
global forString

obj = FreeCADGui.Selection.getSelection()[0]
# try:
obj = App.ActiveDocument.ActiveObject
op = obj.PropertiesList
obj = ""
pas = 0
obj = FreeCADGui.Selection.getSelection()[0]
if (title_02 != ""):
op = obj.PropertiesList
for p in op:
pas = 0
if str(p) == title_02:
if (title_02 != ""):
for p in op:
App.Console.PrintWarning("This Property is already present"+"\n")
pas = 0
if str(p) == title_02:
break
App.Console.PrintWarning("This Property is already present"+"\n")
pas = 0
break
else :
pas = 1
if pas == 1:
if forString == 0 : # title_02 = sous titre, title_01 = titre
a = obj.addProperty("App::PropertyString",title_02, title_01, "_Memo") # create a memo string
#FreeCAD.ActiveDocument.getObject(obj.Name) = memo_01
else :
else :
pas = 1
a = obj.addProperty("App::PropertyStringList",title_02, title_01, "_Memo") # Create a list in window
if pas == 1:
Gui.Selection.clearSelection(obj.Name)
a = obj.addProperty("App::PropertyString",title_02,title_01,"_Memo")
Gui.Selection.addSelection(obj)
Gui.Selection.clearSelection(obj.Name)
App.activeDocument().recompute()
#ui.on_PB_Button_01_clicked() # Reset
Gui.Selection.addSelection(obj)
else:
App.activeDocument().recompute()
App.Console.PrintMessage("Field empty"+"\n")
ff = ui # Reset
ff.on_PB_Button_01_clicked() # Reset
else:
App.Console.PrintMessage("Field empty"+"\n")


except Exception:
# except Exception:
App.Console.PrintWarning("Object not selected or not Draft object"+"\n")
# App.Console.PrintWarning("Object not selected or not Draft object"+"\n")
# App.Console.PrintMessage("on_PB_Button_02_clicked\n")
App.Console.PrintMessage("on_PB_Button_02_clicked\n")


def on_PB_Button_03_clicked(self): # Button Quit
def on_PB_Button_03_clicked(self): # Button Quit
App.Console.PrintMessage("End FCPropertyMemo"+"\n\n")
App.Console.PrintMessage("End FCPropertyMemo"+"\n\n")
###### Write Configuration begin ####
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetBool("CB_String", self.CB_String.isChecked())# True or False
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetString("LE_Edit_01", title_01) # ""
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetString("LE_Edit_02", "") # title_02
###### Write Configuration end ####
self.window.hide()
self.window.hide()


def on_PB_Help(self): # Button Help
MainWindow = QtGui.QMainWindow()
import WebGui
WebGui.openBrowser(__url__)
App.Console.PrintMessage(__url__ + "\n")

FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetString("Version",__version__ + " (" + __date__ + ")")#

MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
ui.setupUi(MainWindow)
Line 280: Line 379:




</syntaxhighlight>
==Link==


}}
The discussion on the forum [http://forum.freecadweb.org/viewtopic.php?f=3&t=12282 Object description field]

<languages/>
==Liens==

La discussion sur le forum [http://forum.freecadweb.org/viewtopic.php?f=3&t=12282 Object description field]

Mes macros sur [https://gist.github.com/mario52a mario52a ] gists

==Version==

* ver 00.03 2020/05/17 : disposition de la grille pour 0.19
* ver 00.02 19/10/2015 : ajout d'un checkBox pour mémo String ou mémo Liste

Revision as of 14:02, 23 May 2020

Other languages:

Macro_PropertyMemo

Description
Nouvelle interface graphique modifiée pour fonctionner en HD dpi (QGridLayout), uniquement la version FC 0.19 et plus (PySide2 Qt5)

Pour la version précédente, voir Macro_FCPropertyMemo.FCMacro et l'installer manuellement. Cette petite macro vous permet d'ajouter une Propriété (mémo ou autre texte) uniquement à un objet Draft.

Version macro : 2020-05-17
Version FreeCAD : 0.19
Téléchargement : ToolBar Icon
Auteur: Mario52

Auteur
Mario52
Téléchargement
ToolBar Icon
Liens
Version Macro
2020-05-17
Dernière modification
None
Version(s) FreeCAD
0.19
Raccourci clavier
None
Voir aussi
None

Description

Cette petite macro vous permet d'ajouter une Propriété (mémo ou autre texte) à un objet Draft (pour le moment uniquement sur objet Draft)

Addin one property Memo → Name

Utilisation

Lancez la macro sélectionnez un objet Draft complétez les champs et appliquez la modification. Une nouvelle propriété est créée dans la Vue combinée Vue combinée → Property → Data tab

  • Property title : Titre de la nouvelle propriété (Defaut: Memo)
  • Property name ! nom de la nouvelle propriété
  • UnCheck for String : checkBox pour le choix de la chaîne ou de la liste (par défaut)
Une propriété Memo est créée
Une propriété Memo est créée
  • Memo : Titre de la propriété ici Memo (par défaut)
  • Name : Nom de la propriété ici, Name
  • Le champ libre nouvellement créé est à compléter manuellement

La case à cocher vous donne le choix entre deux options. Si la case à cocher est activé, vous avez la possibilité de créer une liste de mémos que vous pouvez modifier dans une fenêtre si non le mémo sera affiché dans une ligne (option par défaut)

Script

L'icône disponible pour votre barre d'outils

Macro_FCPropertyMemo.FCMacro

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
"""
***************************************************************************
*   Copyright (c) 2015, 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_FCPropertyMemo 28/09/2015, 19/10/2015, 2020/05/17
#
#
#OS: Windows 10 (10.0)
#Word size of OS: 64-bit
#Word size of FreeCAD: 64-bit
#Version: 0.19.20887 (Git)
#Build type: Release
#Branch: master
#Hash: 42c56d9fef82b484448e3730eb7da69c48fe1374
#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)
#
#
__title__   = "Macro_FCPropertyMemo"
__author__  = "Mario52"
__url__     = "https://wiki.freecadweb.org/Macro_PropertyMemo"
__urlGist   = "https://gist.github.com/mario52a/eafcf79703fab64b8da5"
__version__ = "00.03"
__date__    = "2020/05/17"  #YYYY/MM/DD

#### Test FreeCAD.Version simple ############################################################################################################
if int(FreeCAD.Version()[1]) < 19:      # Version de FreeCAD
    FreeCAD.Console.PrintMessage("This version " + __title__ + " rmu  work with the FreeCAD 0.19 or higher." + "\n\n")
    FreeCAD.Console.PrintMessage("For the precedent version see the page " + "\n\n")
    FreeCAD.Console.PrintMessage("https://gist.githubusercontent.com/mario52a/eafcf79703fab64b8da5/raw/51702c17fb4b205da52488bf2a239011bbbc9da5/Macro_FCPropertyMemo.FCMacro" + "\n\n")

#### Test FreeCAD.Version simple ############################################################################################################

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 Draft, Part, FreeCAD, math, PartGui, FreeCADGui, FreeCAD

global path
#path = FreeCAD.ConfigGet("AppHomePath")
path = FreeCAD.ConfigGet("UserAppData")

global title_01 ; title_01  = "Memo"    # title of menu
global title_02 ; title_02  = ""        # title of propriety
global memo_01  ; memo_01   = ""        # memo
global forString; forString = 1         # memo for String or List
global ui       ; ui        = ""        # 

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 setupUi(self, MainWindow):
        self.window = MainWindow
        global path
        global title_01
        global title_02
        global memo_01

        ##path###########################################################################
        #path = FreeCAD.ConfigGet("AppHomePath")
        #path = FreeCAD.ConfigGet("UserAppData")
        #path = "your path"
        param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro")# macro path
        self.path = param.GetString("MacroPath","") + "/"                   # macro path
        self.path = self.path.replace("\\","/")
        #App.Console.PrintMessage(str("Path for the icons : ") + self.path + "\n" + __title__ + " : " +__version__ + " " + __date__ + "\n")
       # #################################################################################

        MainWindow.setObjectName(_fromUtf8("MainWindow"))
#        MainWindow.resize(260, 200)
#        MainWindow.setMinimumSize(QtCore.QSize(254, 163))
#        MainWindow.setMaximumSize(QtCore.QSize(254, 163))

        ###### Read Configuration begin ####
        title_01 = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).GetString("LE_Edit_01")
        title_02 = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).GetString("LE_Edit_02")
        CBString = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).GetBool("CB_String")
        ###### Read Configuration end   ####

        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))

        self.groupBox = QtWidgets.QGroupBox()

        self.label_00 = QtWidgets.QLabel()
        self.label_00.setAlignment(QtCore.Qt.AlignCenter)
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setUnderline(True)
        font.setWeight(80)
        self.label_00.setFont(font)

        self.label_01 = QtWidgets.QLabel()

        self.LE_Edit_01 = QtWidgets.QLineEdit()              # title property
        self.LE_Edit_01.setText(_fromUtf8(title_01))
        self.LE_Edit_01.textChanged.connect(self.on_LE_Edit_01_Pressed)

        self.label_02 = QtWidgets.QLabel()

        self.LE_Edit_02 = QtWidgets.QLineEdit()              # title name
        self.LE_Edit_02.setText(_fromUtf8(title_02))
        self.LE_Edit_02.textChanged.connect(self.on_LE_Edit_02_Pressed)    #

#        self.label_03 = QtWidgets.QLabel()

#        self.LE_Edit_03 = QtWidgets.QLineEdit()              # memo 
#        self.LE_Edit_03.textChanged.connect(self.on_LE_Edit_03_Pressed)    #

        self.CB_String = QtWidgets.QCheckBox()                      # for String or List
        self.CB_String.setChecked(CBString)
        self.CB_String.clicked.connect(self.on_CB_String_clicked)   # connect on def "on_checkBox_1_clicked"

        self.PB_Help = QtWidgets.QPushButton()
        self.PB_Help.setToolTip(_fromUtf8("Help on line  " + __version__ + "  " + __date__ + " rmu"))
        self.PB_Help.setIcon(QtGui.QIcon.fromTheme("help",QtGui.QIcon(":/icons/help-browser.svg")))
        self.PB_Help.clicked.connect(self.on_PB_Help)    #

        self.PB_Button_01 = QtWidgets.QPushButton()
        self.PB_Button_01.setIcon(QtGui.QIcon.fromTheme("refresh",QtGui.QIcon(":/icons/view-refresh.svg")))
        self.PB_Button_01.clicked.connect(self.on_PB_Button_01_clicked)    #

        self.PB_Button_02 = QtWidgets.QPushButton()
#        self.PB_Button_02.setIcon(QIcon(QApplication.style().standardIcon(QStyle.SP_DialogOkButton))) #
        self.PB_Button_02.setIcon(QtGui.QIcon.fromTheme("execute",QtGui.QIcon(":/icons/button_valid.svg")))
        self.PB_Button_02.clicked.connect(self.on_PB_Button_02_clicked)    #

        self.PB_Button_03 = QtWidgets.QPushButton()
        self.PB_Button_03.setIcon(QtGui.QIcon.fromTheme("close",QtGui.QIcon(":/icons/application-exit.svg")))
        self.PB_Button_03.clicked.connect(self.on_PB_Button_03_clicked)    #

        #### Layout debut ########################
        self.grid0 = QtWidgets.QGridLayout(self.centralwidget)
        self.grid0.setContentsMargins(10, 10, 10, 10)
        self.grid0.addWidget(self.groupBox, 0, 0, 1, 1)
        self.gridLayout = QtWidgets.QGridLayout(self.groupBox)
        self.gridLayout.addWidget(self.label_00, 1, 0, 1, 4)
        self.gridLayout.addWidget(self.label_01, 2, 0, 1, 4)
        self.gridLayout.addWidget(self.LE_Edit_01, 3, 0, 1, 4)
        self.gridLayout.addWidget(self.label_02, 4, 0, 1, 2)
        self.gridLayout.addWidget(self.CB_String, 4, 2, 1, 2)
        self.gridLayout.addWidget(self.LE_Edit_02, 5, 0, 1, 4)
#        self.gridLayout.addWidget(self.label_03, 6, 0, 1, 4)
#        self.gridLayout.addWidget(self.LE_Edit_03, 7, 0, 1, 3)
        self.gridLayout.addWidget(self.PB_Help, 8, 0, 1, 1)
        self.gridLayout.addWidget(self.PB_Button_01, 8, 1, 1, 1)
        self.gridLayout.addWidget(self.PB_Button_02, 8, 2, 1, 1)
        self.gridLayout.addWidget(self.PB_Button_03, 8, 3, 1, 1)
        #### Layout fin ###########################

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

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowFlags(PySide2.QtCore.Qt.WindowStaysOnTopHint)                 # PySide2 cette fonction met la fenetre en avant

        MainWindow.setWindowIcon(QtGui.QIcon(_fromUtf8(self.path + "PropertyMemo.png")))  # change l'icone de la fenetre principale
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "FCPropertyMemo"))

        self.groupBox.setTitle(_translate("MainWindow", "ver : " + __version__ + " : " + __date__ + " (rmu)"))
        self.label_00.setText(_translate("MainWindow", "FCProperty Memo"))
        self.label_01.setText(_translate("MainWindow", "Property title"))
        self.label_02.setText(_translate("MainWindow", "Property name"))
        self.CB_String.setText(_translate("MainWindow", "UnCheck for String"))
        self.LE_Edit_02.setToolTip("Title of property")
#        self.label_03.setText(_translate("MainWindow", "Memo"))
#        self.LE_Edit_03.setText(_fromUtf8(""))
#        self.LE_Edit_03.setToolTip("Text memo")
        self.PB_Help.setText(_translate("MainWindow", "Wiki"))
        self.PB_Button_01.setText(_translate("MainWindow", "Reset"))
        self.PB_Button_02.setText(_translate("MainWindow", "Validate"))
        self.PB_Button_03.setText(_translate("MainWindow", "Quit"))
        self.CB_String.setToolTip("The memo is a string by default"+"\n"+
                                  "If the checkBox is checked the memo is a list in one window"+"\n"+
                                  "Clic the '...' in ComboView > Data")

    def on_LE_Edit_01_Pressed(self):        # Line edit 01 title
        global title_01

        title_01 = self.LE_Edit_01.text()
#        App.Console.PrintMessage(title_01+"\n")

    def on_LE_Edit_02_Pressed(self):        # Line edit 02 title property
        global title_02

        title_02 = self.LE_Edit_02.text()
#        App.Console.PrintMessage(title_02+"\n")

#    def on_LE_Edit_03_Pressed(self):        # Line edit 03 memo
#        global memo_01
#        memo_01 = self.LE_Edit_03.text()
#        App.Console.PrintMessage(memo_01+"\n")

    def on_CB_String_clicked(self):         # connection on_checkBox_1_clicked
        global forString

        if self.CB_String.isChecked():      # if checkbox_01 is checked then ....
            forString = 1
            self.CB_String.setText("UnCheck for String")
        else :
            forString = 0
            self.CB_String.setText("Check for List")
#        App.Console.PrintMessage("on_CB_String_clicked "+str(forString)+"\n")

    def on_PB_Button_01_clicked(self):      # Button Reset
        global title_01
        global title_02
        global memo_01
        global forString

        self.LE_Edit_01.clear()
        title_01 = "Memo"
        self.LE_Edit_01.setText(_fromUtf8(title_01))
        self.LE_Edit_02.clear()
        title_02 = ""
#        self.LE_Edit_03.clear()
#        memo_01 = ""
        self.CB_String.setChecked(True)
        forString = 1
        self.CB_String.setText("UnCheck for String")
#        App.Console.PrintMessage("on_PB_Button_01_clicked\n")

    def on_PB_Button_02_clicked(self):      # Button Validate
        global ui
        global title_01
        global title_02
        global memo_01
        global forString

#        try:
        obj = ""
        obj = FreeCADGui.Selection.getSelection()[0]
        op  = obj.PropertiesList
        pas = 0
        if (title_02 != ""):
            for p in op:
                if str(p) == title_02:
                    App.Console.PrintWarning("This Property is already present"+"\n")
                    pas = 0
                    break
                else :
                    pas = 1
            if pas == 1:
                    if forString == 0 :                         # title_02 = sous titre, title_01 = titre
                        a = obj.addProperty("App::PropertyString",title_02, title_01, "_Memo")       # create a memo string
                        #FreeCAD.ActiveDocument.getObject(obj.Name) = memo_01
                    else :
                        a = obj.addProperty("App::PropertyStringList",title_02, title_01, "_Memo")   # Create a list in window
                    Gui.Selection.clearSelection(obj.Name)
                    Gui.Selection.addSelection(obj)
                    App.activeDocument().recompute()
            #ui.on_PB_Button_01_clicked()    # Reset
        else:
            App.Console.PrintMessage("Field empty"+"\n")

#        except Exception:
#                    App.Console.PrintWarning("Object not selected or not Draft object"+"\n")
                
        App.Console.PrintMessage("on_PB_Button_02_clicked\n")

    def on_PB_Button_03_clicked(self):      # Button Quit
        App.Console.PrintMessage("End FCPropertyMemo"+"\n\n")
        ###### Write Configuration begin ####
        FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetBool("CB_String", self.CB_String.isChecked())# True or False
        FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetString("LE_Edit_01", title_01) # ""
        FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetString("LE_Edit_02", "") # title_02
        ###### Write Configuration end   ####
        self.window.hide()

    def on_PB_Help(self): # Button Help
        import WebGui
        WebGui.openBrowser(__url__)
        App.Console.PrintMessage(__url__ + "\n")

FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetString("Version",__version__ + " (" + __date__ + ")")# 

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

Liens

La discussion sur le forum Object description field

Mes macros sur mario52a gists

Version

  • ver 00.03 2020/05/17 : disposition de la grille pour 0.19
  • ver 00.02 19/10/2015 : ajout d'un checkBox pour mémo String ou mémo Liste