Macro SimpleProperties: Difference between revisions

From FreeCAD Documentation
(icon and <translate>)
(Marked this version for translation)
 
(8 intermediate revisions by 5 users not shown)
Line 1: Line 1:
<languages/>
<languages/>
<translate>
<translate>
<!--T:1-->
{{Macro
{{Macro
|Name=SimpleProperties
|Name=SimpleProperties
Line 8: Line 9:
|Date=2019-06-10
|Date=2019-06-10
|Version=0.7
|Version=0.7
|FCVersion= 0.17+
|FCVersion=0.17+
|Download=[https://www.freecadweb.org/wiki/images/d/da/Macro_SimpleProperties.png ToolBar Icon]
|Download=[https://www.freecadweb.org/wiki/images/d/da/Macro_SimpleProperties.png ToolBar Icon]
|SeeAlso=[[Arch_Survey|Arch_Survey]] [[Image:Arch_Survey.svg|24px]]<br />[[Macro_FCInfo|Macro_FCInfo]] [[Image:FCInfo.png|24px]]
|SeeAlso=[[Arch_Survey|Arch Survey]], [[Macro_FCInfo|Macro FCInfo]]
}}
}}
</translate>
<div style="border-style: solid; border-color: red; border-width: 5px; background-color: pink; text-align: center; font-size: 3em; font-weight: bold; display: none;">This page is under construction/update</div>
<translate>


==Description==
==Description== <!--T:2-->


===Context===
===Context=== <!--T:3-->


<!--T:4-->
This macro has been written mainly so user can access a quick & concise information about an object physical properties. This aims particularly at preparing object packaging & shipping.
This macro has been written mainly so user can access a quick & concise information about an object physical properties. This aims particularly at preparing object packaging & shipping.


===Usage===
===Usage=== <!--T:5-->


<!--T:6-->
Select an object and run the macro. It will display in a message box :
Select an object and run the macro. It will display in a message box :
* Object volume in liters
* Object volume in liters
Line 30: Line 30:
* If object has been selected by clicking a face, its area is displayed in meter squares
* If object has been selected by clicking a face, its area is displayed in meter squares


===Installation===
===Installation=== <!--T:7-->


<!--T:8-->
At the moment, the macro isn't available from the addon manager => PR submitted : https://github.com/FreeCAD/FreeCAD-macros/pull/52
The macro is available through [[Std_AddonMgr|Addon Manager]].
So you have to copy the below code and paste it in FreeCAD macro editor.
Code is provided on this page for convenience in case user system doesn't have git-python. Though it should be up-to-date, latest release is always available at [https://github.com/FreeCAD/FreeCAD-macros/blob/master/Information/SimpleProperties.FCMacro FreeCAD-macro repository]


<!--T:9-->
For more detailed explanations, see the [[How to install macros]] page.
For more detailed explanations, see the [[How_to_install_macros|How to install macros]] page.


==Script==
==Script== <!--T:10-->


===Limitations===
===Limitations=== <!--T:11-->

<!--T:13-->
* Only one object at a time
* Only one object at a time


===Code===
===Code=== <!--T:12-->
</translate>


<!--T:14-->
ToolBar Icon [[Image:Macro_SimpleProperties.png]]
ToolBar Icon
</translate>
[[Image:Macro_SimpleProperties.png]]


'''Macro_SimpleProperties.FCMacro'''
'''Macro_SimpleProperties.FCMacro'''


{{Code|code=
{{MacroCode|code=
#!/usr/bin/python
#!/usr/bin/python
#####################################
#####################################

Latest revision as of 10:38, 22 January 2022

SimpleProperties

Description
This macro gives simple properties of selected object (volume, boundbox, ...)

Macro version: 0.7
Last modified: 2019-06-10
FreeCAD version: 0.17+
Download: ToolBar Icon
Author: OpenBrain
Author
OpenBrain
Download
ToolBar Icon
Links
Macro Version
0.7
Date last modified
2019-06-10
FreeCAD Version(s)
0.17+
Default shortcut
None
See also
Arch Survey, Macro FCInfo

Description

Context

This macro has been written mainly so user can access a quick & concise information about an object physical properties. This aims particularly at preparing object packaging & shipping.

Usage

Select an object and run the macro. It will display in a message box :

  • Object volume in liters
  • Object boundbox dimensions in millimeters
  • If object has been selected by clicking an edge, its length is displayed in millimeters
  • If object has been selected by clicking a face, its area is displayed in meter squares

Installation

The macro is available through Addon Manager. Code is provided on this page for convenience in case user system doesn't have git-python. Though it should be up-to-date, latest release is always available at FreeCAD-macro repository

For more detailed explanations, see the How to install macros page.

Script

Limitations

  • Only one object at a time

Code

ToolBar Icon

Macro_SimpleProperties.FCMacro

#!/usr/bin/python
#####################################
# Copyright (c) openBrain 2019
# Licensed under LGPL v2
#
# This FreeCAD macro will give basic properties of the selected object (volume, boundbox, ...)
#
#
# Version history :
# *0.7 : some typo improvement + commenting
# *0.6 : check if selected object has a valid shape
# *0.5 : beta release
#
#####################################

__Name__ = 'SimpleProperties'
__Comment__ = 'Gives basic properties of object (volume, boundbox, ...)'
__Author__ = 'openBrain'
__Version__ = '0.7'
__Date__ = '2019-06-10'
__License__ = 'LGPL v2'
__Web__ = 'https://www.freecadweb.org/wiki/Macro_SimpleProperties'
__Wiki__ = 'https://www.freecadweb.org/wiki/Macro_SimpleProperties'
__Icon__ = ''
__Help__ = 'Select an object and run the macro'
__Status__ = 'Beta'
__Requires__ = 'FreeCAD >= 0.17'

__dbg__ = False #True for debugging
SIGNUM = '%.3g' #Set the display format of numbers

from PySide import QtGui

def cslM(msg): #Print message in console
    FreeCAD.Console.PrintMessage('\n')
    FreeCAD.Console.PrintMessage(msg)

def cslW(msg): #Print warning in console
    FreeCAD.Console.PrintMessage('\n')
    FreeCAD.Console.PrintWarning(msg)

def cslE(msg): #Print error in console
    FreeCAD.Console.PrintMessage('\n')
    FreeCAD.Console.PrintError(msg)

def cslD(msg): #Print debug message in console
    if __dbg__:
        FreeCAD.Console.PrintMessage('\n')
        FreeCAD.Console.PrintMessage("Debug : " + str(msg))

if __dbg__:  ##Clear report view in debug mode
    FreeCADGui.getMainWindow().findChild(QtGui.QTextEdit, "Report view").clear()

cslM("Starting Simple Properties macro")

if len(Gui.Selection.getSelection()) != 1: ##If not exactly one object selected, warn user & quit
    cslE("One and only one object shall be selected ... Exiting")
elif not ("Shape" in Gui.Selection.getSelection()[0].PropertiesList): ##If selected object has no shape, warn user & exit
    cslE("Selected object has no valid shape ... Exiting") 
else:
    obj = Gui.Selection.getSelection()[0] #Get selected object
    retStr = ""
    if len(Gui.Selection.getSelectionEx()[0].SubObjects) != 1: #If several object subobjects have been selected, ignore & warn user
        cslW("No or several subobject(s) selected, will be ignored")
    else:
        objEx = Gui.Selection.getSelectionEx()[0].SubObjects[0] #If one subobject selected
        if isinstance(objEx, Part.Edge): ##If it's an edge, print its length
            retStr += "Edge length : " + '%s' % float(SIGNUM % (objEx.Length)) + " mm\n"
        elif isinstance(objEx, Part.Face): ##If it's a face, print its area
            retStr += "Face area : " + '%s' % float(SIGNUM % (objEx.Area/1000000)) + " m2\n"
        else: ##If other (unsupported) type, warn user
            cslD("Subobject type : " + str(objEx.ShapeType))
            cslW("Unsupported type of subobject")
    retStr += "Object volume : " + '%s' % float(SIGNUM % (obj.Shape.Volume/1000000)) + " l\n" #Print object volume
    bb = obj.Shape.BoundBox #Get object boundbox
    retStr += "Object boundbox : " + '%s' % float(SIGNUM % (bb.XLength)) + " x " + '%s' % float(SIGNUM % (bb.YLength)) + " x " + '%s' % float(SIGNUM % (bb.ZLength)) + " mm" + "\n" #Print object boundbox dimensions
    QtGui.QMessageBox(QtGui.QMessageBox.Information, "Object Simple Props",retStr).exec_() #Display information in a message box
    cslM("End")