Macro Wiki Object Properties List Generator

From FreeCAD Documentation
This page is a translated version of the page Macro Wiki Object Properties List Generator and the translation is 100% complete.
Other languages:

Generic macro icon Macro Wiki Object Properties List Generator

Description
Cette macro génère des listes de propriétés de l'objet sélectionné sous différentes formes au format Wiki.

Version macro : 0.15
Date dernière modification : 2021-09
Auteur: Evgeniy
Auteur
Evgeniy
Téléchargement
None
Liens
Version Macro
0.15
Dernière modification
2021-09
Version(s) FreeCAD
None
Raccourci clavier
None
Voir aussi
Version basique de cette macro, Part Feature

Description

Cette macro génère des listes de propriétés de l'objet sélectionné sous différentes formes au format Wiki. La liste est imprimée dans la Vue rapport de FreeCAD. Cette macro peut être utilisée pour simplifier le travail avec ce Wiki avec quelques restrictions. Les listes de propriétés publiées dans le Wiki ne contiennent généralement que des paramètres uniques. Les paramètres hérités des objets parents ne sont pas publiés.

Ce script supprime automatiquement les paramètres hérités de la liste. Mais en raison des limitations du logiciel FreeCAD, il ne peut pas supprimer absolument tous les paramètres hérités, donc les listes générées par ce script doivent être soigneusement vérifiées avant d'être publiées.

Introduction

Chaque objet créé dans FreeCAD est hérité de l'objet parent. La structure de ces relations est illustrée dans le diagramme ci-dessous.

Vous pouvez en lire plus à ce sujet sur la page : Part Feature

Utilisation

  • Préparation :
    • Copiez le code de la macro de cette page et placez-le dans un nouveau fichier *.FCMacro.
    • Enregistrez le fichier FCMacro et placez-le dans le dossier Macros de FreeCAD.
    • Désactivez la case à cocher Inclure un timecode pour chaque entrée dans Préférences -> Général -> Fenêtre de sortie (onglet).
  • Première utilisation :
    • Sélectionnez (ou créez et sélectionnez) un seul objet dans l'arborescence le type de dont vous avez besoin.
    • Sélectionnez l'élément Macro -> Macros... dans le menu principal.
    • Dans la fenêtre ouverte, trouvez le fichier *.FCMacro que vous avez sauvegardé et appuyez sur le bouton Lancer.
    • Dans la boîte de dialogue qui s'ouvre, sélectionnez le type de rapport que vous voulez obtenir en appuyant sur un des boutons :
      • Only Main - imprime uniquement les propriétés uniques des classes de base (parent).
      • All Properties - imprime absolument toutes les propriétés de l'objet sélectionné.
      • Inherits+Unique Properties - imprime uniquement les propriétés uniques avec le rapport d'héritage inclus.
      • Only Unique Properties - imprime uniquement les propriétés uniques.
  • Comment utiliser à nouveau :
    • Pour relancer rapidement cette macro, vous pouvez utiliser le raccourci clavier Shift+Ctrl+1 (sous Windows) qui lancera la dernière macro exécutée.

Recommendations

Ne supprimez pas les espaces entre les lignes. Cela est nécessaire pour simplifier la traduction. Chaque ligne séparée par un espace sera considérée comme une partie distincte pour la traduction. Lorsque vous créez des textes, n'oubliez jamais que les grands fragments monolithiques de texte sont difficiles à traduire pour les traducteurs.

Exemples d'utilisation

  • Par exemple, ouvrez l'atelier Part
  • Créez un objet Sphère.
  • Sélectionnez l'objet Sphère créé.
  • Exécutez la macro.
  • Appuyez sur l'un des boutons de la boîte de dialogue qui s'ouvre.

La macro génère un rapport en fonction du bouton sur lequel vous avez cliqué.

Remarquez que l'ordre des lignes dans l'éditeur de paramètres peut être différent de l'ordre des lignes faites par le générateur.

Only Unique Properties Inherits+Unique Properties All Properties

Properties

View

Data

Sphere

  • DonnéesAngle1 (Angle): The angle of the sphere
  • DonnéesAngle2 (Angle): The angle of the sphere
  • DonnéesAngle3 (Angle): The angle of the sphere
  • DonnéesRadius (Length): The radius of the sphere

Properties

View

<!--
AngularDeflection inherited from class PartDesign::Body
BoundingBox inherited from class PartDesign::Body
Deviation inherited from class PartDesign::Body
DiffuseColor inherited from class PartDesign::Body
DisplayMode inherited from class PartDesign::Body
DrawStyle inherited from class PartDesign::Body
Lighting inherited from class PartDesign::Body
LineColor inherited from class PartDesign::Body
LineColorArray inherited from class PartDesign::Body
LineMaterial inherited from class PartDesign::Body
LineWidth inherited from class PartDesign::Body
OnTopWhenSelected inherited from class PartDesign::Body
PointColor inherited from class PartDesign::Body
PointColorArray inherited from class PartDesign::Body
PointMaterial inherited from class PartDesign::Body
PointSize inherited from class PartDesign::Body
Selectable inherited from class PartDesign::Body
SelectionStyle inherited from class PartDesign::Body
ShapeColor inherited from class PartDesign::Body
ShapeMaterial inherited from class PartDesign::Body
ShowInTree inherited from class PartDesign::Body
Transparency inherited from class PartDesign::Body
Visibility inherited from class PartDesign::Body
-->

Data

<!--
AttacherType inherited from class Part::Part2DObject
AttachmentOffset inherited from class Part::Part2DObject
ExpressionEngine inherited from class PartDesign::Body
Label inherited from class PartDesign::Body
Label2 inherited from class PartDesign::Body
MapMode inherited from class Part::Part2DObject
MapPathParameter inherited from class Part::Part2DObject
MapReversed inherited from class Part::Part2DObject
Placement inherited from class PartDesign::Body
Shape inherited from class PartDesign::Body
Support inherited from class Part::Part2DObject
Visibility inherited from class PartDesign::Body
-->

Sphere

  • DonnéesAngle1 (Angle): The angle of the sphere
  • DonnéesAngle2 (Angle): The angle of the sphere
  • DonnéesAngle3 (Angle): The angle of the sphere
  • DonnéesRadius (Length): The radius of the sphere

Properties

View

Display Options

  • VueBoundingBox (Bool): Display object bounding box
  • VueDisplayMode (Enumeration): Set the display mode
  • VueShowInTree (Bool): Show the object in the tree view
  • VueVisibility (Bool): Show the object in the 3d view

Object Style

  • VueAngularDeflection (Angle): Specify how finely to generate the mesh for rendering on screen or when exporting.

The default value is 28.5 degrees, or 0.5 radians. The smaller the value the smoother the appearance in the 3D view, and the finer the mesh that will be exported.

  • VueDeviation (FloatConstraint): Sets the accuracy of the polygonal representation of the model

in the 3D view (tessellation). Lower values indicate better quality. The value is in percent of object's size.

  • VueDiffuseColor (ColorList): Object diffuse color.
  • VueDrawStyle (Enumeration): Defines the style of the edges in the 3D view.
  • VueLighting (Enumeration): Set object lighting.
  • VueLineColor (Color): Set object line color.
  • VueLineColorArray (ColorList): Object line color array.
  • VueLineMaterial (Material): Object line material.
  • VueLineWidth (FloatConstraint): Set object line width.
  • VuePointColor (Color): Set object point color
  • VuePointColorArray (ColorList): Object point color array.
  • VuePointMaterial (Material): Object point material.
  • VuePointSize (FloatConstraint): Set object point size.
  • VueShapeColor (Color): Set shape color
  • VueShapeMaterial (Material): Shape material
  • VueTransparency (Percent): Set object transparency

Selection

  • VueOnTopWhenSelected (Enumeration): Enabled: Display the object on top of any other object when selected

Object: On top only if the whole object is selected Element: On top only if some sub-element of the object is selected

  • VueSelectable (Bool): Set if the object is selectable in the 3d view
  • VueSelectionStyle (Enumeration): Set the object selection style

Data

  • Données (NoRecompute)Placement (Placement):
  • DonnéesShape (Part::PropertyPartShape):
  • Données (Hidden, Output, NoModify)Visibility (Bool):

Attachment

  • Données (Hidden)AttacherType (String): Class name of attach engine object driving the attachment.
  • Données (Hidden)AttachmentOffset (Placement): Extra placement to apply in addition to attachment (in local coordinates)
  • DonnéesMapMode (Enumeration): Mode of attachment to other object
  • Données (Hidden)MapPathParameter (Float): Sets point of curve to map the sketch to. 0..1 = start..end
  • Données (Hidden)MapReversed (Bool): Reverse Z direction (flip sketch upside down)
  • DonnéesSupport (LinkSubList): Support of the 2D geometry

Base

  • Données (Hidden)ExpressionEngine (ExpressionEngine): Property expressions
  • Données (Output)Label (String): User name of the object (UTF8)
  • Données (Output, Hidden)Label2 (String): User description of the object (UTF8)

Sphere

  • DonnéesAngle1 (Angle): The angle of the sphere
  • DonnéesAngle2 (Angle): The angle of the sphere
  • DonnéesAngle3 (Angle): The angle of the sphere
  • DonnéesRadius (Length): The radius of the sphere

Génèrer les propriétés de toutes les classes de base parentes

...

Script

#! python
# -*- coding: utf-8 -*-
# (c) 2021 <Evgeniy> LGPL

from FreeCAD import Qt
import re, FreeCAD
from PySide import QtCore, QtGui

def clear_report_view():
   main_window=Gui.getMainWindow()
   #console=main_window.findChild(QtGui.QPlainTextEdit, "Python console")
   #console.clear()
   report_view=main_window.findChild(QtGui.QTextEdit, "Report view")
   report_view.clear()

def printsr(text,show_report):
   if show_report:   
      print(text)

# Based on https://github.com/FreeCAD/FreeCAD/blob/5d49bf78de785a536f941f1a6d06d432582a95d3/src/App/PropertyFile.h
# and https://github.com/FreeCAD/FreeCAD/blob/5d49bf78de785a536f941f1a6d06d432582a95d3/src/App/PropertyContainerPyImp.cpp
status_dictionary={
0:"Touched",      # touched property
#1:"Immutable",   # can't modify property
#2:"ReadOnly",    # for property editor
#3:"Hidden",      # for property editor
#4:"Transient",   # for property container save
#5:"MaterialEdit", # to turn ON PropertyMaterial edit
#6:"NoMaterialListEdit", # to turn OFF PropertyMaterialList edit
#7:"Output",      # same effect as Prop_Output
#8:"LockDynamic", # prevent being removed from dynamic property
#9:"NoModify",    # prevent causing Gui::Document::setModified()
#10:"PartialTrigger", # allow change in partial doc
11:"NoRecompute", # touch owner for recompute on property change
12:"Single",      # for save/load of floating point numbers
13:"Ordered",     # for PropertyLists whether the order of the elements is relevant for the container using it
14:"EvalOnRestore", # In case of expression binding, evaluate the expression on restore and touch the object on value change.
# The following bits are corresponding to PropertyType set when the
# property added. These types are meant to be static, and cannot be
# changed in runtime. It is mirrored here to save the linear search
# required in PropertyContainer::getPropertyType()
21:"Dynamic",     # indicating the property is dynamically added
22:"NoPersist",   # corresponding to Prop_NoPersist
23:"NoRecompute", # corresponding to Prop_NoRecompute
24:"ReadOnly",    # corresponding to Prop_ReadOnly
25:"Transient",   # corresponding to Prop_Transient
26:"Hidden",      # corresponding to Prop_Hidden
27:"Output",      # corresponding to Prop_Output
}

def print_obj_properties(obj,typ,blacklist,show_inherits):
   prop={}
   i=1
   inherits = ""
   for pr in obj.PropertiesList:
      typeid = (obj.getTypeIdOfProperty(pr) or "").replace("App::Property","")
      # Get all possible status variants 
      stat = obj.getPropertyStatus(pr) or ("")
      if stat != (""):
         for st in stat:
            # get status without name from dictionary
            if isinstance(st, int):
               stat.insert(stat.index(st),status_dictionary[st])
               stat.remove(st)
         # remove symbols ['] from str by regexp and trim spaces
         stat = re.sub(r"[\[\]\']","",str(stat)).strip()
         # Uncomment this two strings to make the list look like the list of parameters from the editor
         #if 'Hidden' in stat:
         #   continue
      else:
         stat = ""
      if blacklist == None or (blacklist != None and pr not in blacklist):
         prop[str(i)] = pr,obj.getGroupOfProperty(pr),typeid,obj.getDocumentationOfProperty(pr),stat
         i+=1
      else:
         inherits += pr + " inherited from class " + blacklist[pr] + "\n"

   if inherits != "" and show_inherits:
      # angle brackets is masked as \x3C and \x3E to this code can be published in the wiki
      print("\n\x3C!--\n"+inherits+"--\x3E")
   sorted_prop = sorted(prop.items(), key=lambda x: x[1][1])

   title=""
   for pr in sorted_prop:
      if title != pr[1][1]:
         title = pr[1][1]
         print("\n"+"{{TitleProperty|"+title+"}}")
      # use ternary operator "|"+pr[1][4] if pr[1][4]!="" else "" to ignore status field if it not exists 
      print("\n"+"* {{Property"+typ+"|"+pr[1][0]+"|"+pr[1][2]+("|"+pr[1][4] if pr[1][4]!="" else "")+"}}: "+pr[1][3])

# Add propertyes to blacklist if it not presentet in it yet
def add_to_blacklist(data_blacklist,view_blacklist,obj_type,temp_obj_name,show_report):
   printsr("Class: '"+obj_type+"'",show_report)
   # Make tempory object
   obj = FreeCAD.activeDocument().addObject(obj_type,temp_obj_name)
   name = obj.Name
   # Get Data parametrs
   printsr("Data parameters list:",show_report)
   for pr in obj.PropertiesList:
      if not show_report or pr not in data_blacklist:
         data_blacklist[pr]=obj_type
         atr = str(obj.getPropertyStatus(pr)).replace("[]","")
         typeid = (obj.getTypeIdOfProperty(pr) or "").replace("App::Property","")
         printsr(pr+" ("+typeid+") "+atr,show_report)
   # Get View parameters if it is possible
   obj = Gui.activeDocument().getObject(name)
   try:
      test = obj.PropertiesList
      printsr("View parameters list:",show_report)
      for pr in obj.PropertiesList:
         if not show_report or pr not in view_blacklist:
            view_blacklist[pr]=obj_type
            atr = str(obj.getPropertyStatus(pr)).replace("[]","")
            typeid = (obj.getTypeIdOfProperty(pr) or "").replace("App::Property","")
            printsr(pr+" ("+typeid+") "+atr,show_report)
   except:
      printsr("This class not support View parameters.",show_report)
   # Remove object
   FreeCAD.activeDocument().removeObject(name)
   printsr("",show_report)
   return data_blacklist,view_blacklist

def fill_blacklists(show_report):
   data_blacklist={}
   view_blacklist={}
   # Interfaces are not supported
   #data_blacklist,view_blacklist = add_to_blacklist(data_blacklist,view_blacklist,"App::OriginGroupExtension","Temp",show_report)
   #data_blacklist,view_blacklist = add_to_blacklist(data_blacklist,view_blacklist,"Part::AttachExtension","Temp",show_report)
   #data_blacklist,view_blacklist = add_to_blacklist(data_blacklist,view_blacklist,"Sketcher::PropertyConstrainList","Temp",show_report)
   data_blacklist,view_blacklist = add_to_blacklist(data_blacklist,view_blacklist,"App::DocumentObject","Temp",show_report)
   data_blacklist,view_blacklist = add_to_blacklist(data_blacklist,view_blacklist,"App::GeoFeature","Temp",show_report)
   data_blacklist,view_blacklist = add_to_blacklist(data_blacklist,view_blacklist,"App::Part","Temp",show_report)
   data_blacklist,view_blacklist = add_to_blacklist(data_blacklist,view_blacklist,"Mesh::Feature","Temp",show_report)
   data_blacklist,view_blacklist = add_to_blacklist(data_blacklist,view_blacklist,"Fem::FemMeshObject","Temp",show_report)
   data_blacklist,view_blacklist = add_to_blacklist(data_blacklist,view_blacklist,"Path::Feature","Temp",show_report)
   data_blacklist,view_blacklist = add_to_blacklist(data_blacklist,view_blacklist,"Part::Part2DObject","Temp",show_report)
   # Part::Primitive is not possible to create
   #data_blacklist,view_blacklist = add_to_blacklist(data_blacklist,view_blacklist,"Part::Primitive","Temp",show_report)
   data_blacklist,view_blacklist = add_to_blacklist(data_blacklist,view_blacklist,"PartDesign::Feature","Temp",show_report)
   data_blacklist,view_blacklist = add_to_blacklist(data_blacklist,view_blacklist,"Part::BodyBase","Temp",show_report)
   data_blacklist,view_blacklist = add_to_blacklist(data_blacklist,view_blacklist,"PartDesign::Body","Temp",show_report)
   if show_report:
      print("List of all not unique properties of Data:\n"+str(data_blacklist)+"\n\nList of all not unique properties of View:\n"+str(view_blacklist)+"\n")
   return data_blacklist,view_blacklist

sel = FreeCADGui.Selection.getSelection()
if len(sel) != 1:
   msgbox = QtGui.QMessageBox(QtGui.QMessageBox.Question, u'Properties Generator', """You must select only one object in tree view!""")
   msgbox.exec_()
else:
   # Show dialog for select type of report
   msgbox = QtGui.QMessageBox(QtGui.QMessageBox.Question, u'Properties Generator', """Select type of report
   
Only Main - print only unique properties of main classes with types.
All Properties - print all properties of selected object.
Inherits+Unique Properties - print unique properties with inherits report.
Only Unique Properties - print only unique properties of selected object.
""")
   msgbox.setStandardButtons(QtGui.QMessageBox.Cancel) #|QtGui.QMessageBox.Ok
   only_main = msgbox.addButton("Only Main", QtGui.QMessageBox.AcceptRole)
   all_properties = msgbox.addButton("All Properties", QtGui.QMessageBox.AcceptRole)
   unique_prop_inherits = msgbox.addButton("Inherits+Unique Properties ", QtGui.QMessageBox.AcceptRole)
   unique_properties = msgbox.addButton("Only Unique Properties", QtGui.QMessageBox.AcceptRole)
   msgbox.exec_()
   res = msgbox.clickedButton()
   # Clear Report view
   clear_report_view()
   if res == only_main :
      data_blacklist,view_blacklist=fill_blacklists(True)
   if res == unique_properties or  res == all_properties or res == unique_prop_inherits :
      name = sel[0].Name
      act_obj = Gui.activeDocument().getObject(name)
      data_blacklist={}
      view_blacklist={}
      if res == unique_properties or res == unique_prop_inherits:
         data_blacklist,view_blacklist=fill_blacklists(False)
      print("\n"+"==Properties==")
      print("\n"+"===View===")
      print_obj_properties(act_obj,"View",view_blacklist, res == unique_prop_inherits)
      print("\n"+"===Data===")
      act_obj = FreeCAD.activeDocument().getObject(name)
      print_obj_properties(act_obj,"Data",data_blacklist, res == unique_prop_inherits)  

Liens

La discussion sur le forum : https://forum.freecadweb.org/viewtopic.php?f=21&t=61998