Macro BoundingBox Tracing: Difference between revisions

From FreeCAD Documentation
(ver 0.5 le 08/05/2017)
(Use {{MacroCode}})
(32 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<languages/>
<translate>
<translate>
<!--T:1-->
<!--T:1-->
{{Macro
{{Macro|Icon=BoundBoxTracing|Name=Macro BoundingBox Tracing|Description=This macro red trace (editable) around the BoundingBox with 6 rectangles.|Author=Mario52|Version=0.5 (08/05/2016)}}
|Name=Macro BoundingBox Tracing
|Icon=BoundBoxTracing.png
|Description=This macro red trace (editable) around the BoundingBox with 6 rectangles.
|Author=Mario52
|Version=0.11
|Date=2019/05/29
|FCVersion=All
|Download=[https://www.freecadweb.org/wiki/images/6/60/BoundBoxTracing.png ToolBar Icon]
}}


==Description== <!--T:2-->
==Description== <!--T:2-->
Line 7: Line 17:


<!--T:5-->
<!--T:5-->
[[File:Macro BoundingBox_Tracing_00.png|480px|CenterFace]]
[[File:Macro BoundingBox_Tracing_00.png|480px]]
{{Caption|CenterFace}}
{{clear}}

==Usage== <!--T:3-->
Select the object and launch the macro. 6 rectangles are coloured red (can be changed)


==Use== <!--T:3-->
<!--T:15-->
[[File:Macro_BoundingBox_Tracing_01.png|480px]]
Select the object and launch the macro. 6 rectangles are colored red (can be changed)
{{Caption|Info contener}}


<!--T:6-->
<!--T:6-->
If '''createVol''' = 1 (Line 29) one volume is created
If '''createVol''' = 1 (Line 33) one volume is created


<!--T:10-->
To change the color of the dot change the lines 37, 38, 39
</translate>
<!--T:11-->
{{Code|code=
red = 1.0 # 1 = 255
green = 0.0 #
blue = 0.0 #
}}
<translate>
==Icon== <!--T:7-->
==Icon== <!--T:7-->
Download the file image and copy in your macro repertory.
Download the file image and copy in your macro repertory.
Line 32: Line 36:
Click the image, in the new window position the mouse over the image, click the right mouse and do "Save target as ..."
Click the image, in the new window position the mouse over the image, click the right mouse and do "Save target as ..."


<!--T:9-->
<!--T:23-->
[[Image:BoundBoxTracing.png|Button]]
ToolBar Icon [[Image:BoundBoxTracing.png]]


==Macro== <!--T:4-->
==Script== <!--T:4-->
</translate>
</translate>


'''Macro_BoundingBox_Tracing.FCMacro'''
'''Macro_BoundingBox_Tracing.FCMacro'''


{{Code|code=
{{MacroCode|code=
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

# cette macro trace en rouge (modifiable) le tour du boundingbox avec 6 rectangles
# cette macro trace en rouge (modifiable) le tour du boundingbox avec 6 rectangles
# si "createVol" = 1 il sera cree un volume (rouge) de la dimension du BoundBox
# si "createVol" = 1 il sera cree un volume (rouge) de la dimension du BoundBox
Line 48: Line 54:
# Macro_BoundingBox_Tracing
# Macro_BoundingBox_Tracing
#
#
#OS: Windows Vista #OS: Windows 8.1 #OS: Windows 10
#OS: Windows Vista #OS: Windows 8.1 #OS: Windows 10 #OS: Windows 10
#Platform: 32-bit #Word size of OS: 64-bit #Word size of OS: 64-bit
#Platform: 32-bit #Word size of OS: 64-bit #Word size of OS: 64-bit #Word size of OS: 64-bit
#Version: 0.14.3389 #Word size of FreeCAD: 64-bit #Word size of FreeCAD: 64-bit
#Version: 0.14.3389 #Word size of FreeCAD: 64-bit #Word size of FreeCAD: 64-bit #Word size of FreeCAD: 64-bit
#Python version: 2.6.2 #Version: 0.15.4671 (Git) #Version: 0.16.6700 (Git)
#Python version: 2.6.2 #Version: 0.15.4671 (Git) #Version: 0.16.6700 (Git) #Version: 0.17.13528 (Git)
#Qt version: 4.5.2 #Branch: releases/FreeCAD-0-15 #Build type: Release
#Qt version: 4.5.2 #Branch: releases/FreeCAD-0-15 #Build type: Release #Build type: Release
#Coin version: 3.1.0 #Hash: 244b3aef360841646cbfe80a1b225c8b39c8380c #Branch: releases/FreeCAD-0-16
#Coin version: 3.1.0 #Hash: 244b3aef360841646cbfe80a1b225c8b39c8380c #Branch: releases/FreeCAD-0-16 #Branch: releases/FreeCAD-0-17
#SoQt version: 1.4.1 #Python version: 2.7.8 #Hash: 7b925d11aa69ac405b423635adb1e2833f18a817
#SoQt version: 1.4.1 #Python version: 2.7.8 #Hash: 7b925d11aa69ac405b423635adb1e2833f18a817 #Hash: 5c3f7bf8ec51e2c7187789f7edba71a7aa82a88b
#OCC version: 6.5.1 #Qt version: 4.8.6 #Python version: 2.7.8
#OCC version: 6.5.1 #Qt version: 4.8.6 #Python version: 2.7.8 #Python version: 2.7.14
# #Coin version: 4.0.0a #Qt version: 4.8.6
# #Coin version: 4.0.0a #Qt version: 4.8.6 #Qt version: 4.8.7
# #OCC version: 6.8.0.oce-0.17 #Coin version: 4.0.0a
# #OCC version: 6.8.0.oce-0.17 #Coin version: 4.0.0a #Coin version: 4.0.0a
#OCC version: 6.8.0.oce-0.17
# #OCC version: 6.8.0.oce-0.17 #OCC version: 7.2.0
###############################################################################################################################################
#OS: Windows 10 (10.0)
#Word size of OS: 64-bit
#Word size of FreeCAD: 64-bit
#Version: 0.19.16624 (Git)
#Build type: Release
#Branch: master
#Hash: 222ae7305fdf1097e4ef3d050f69dff47dbd8786
#Python version: 3.6.8
#Qt version: 5.12.1
#Coin version: 4.0.0a
#OCC version: 7.3.0
###############################################################################################################################################


__title__ = "BoundingBox_Tracing"
__title__ = "BoundingBox_Tracing"
__author__ = "Mario52"
__author__ = "Mario52"
__url__ = "http://www.freecadweb.org/index-fr.html"
__url__ = "http://www.freecadweb.org/index-fr.html"
__Wiki__ = "https://www.freecadweb.org/wiki/Macro_BoundingBox_Tracing"
__version__ = "0.5"
__version__ = "0.11"
__date__ = "08/05/2017"
__date__ = "2019/05/29" # YYYY/MM/DD



import PySide
import FreeCAD, FreeCADGui, Draft, Part
import FreeCAD, FreeCADGui, Draft, Part
App = FreeCAD
App = FreeCAD


##### Section configuration begin ##################
createVol = 1 # give 1 for create Volume # mettre a 1 pour creer un volume
##### for volume begin ###################
createVol = 1 # give 1 for create Volume # mettre a 1 pour creer un volume
createDimVol = 1 # 1 = create dimension info : 0 = not dimension info
##### for volume end ###################

##### for dimensions info begin ##########
createDim = 1 # 1 = create dimension info : 0 = not create dimension info

if int(FreeCAD.Version()[1]) > 17: # Version de FreeCAD
DisplayModeText = str(u"3D text") # available : u"2D text" or u"3D text"
else:
DisplayModeText = str(u"Screen") # available : u"Screen" or u"World"

JustificationText = str(u"Center") # available : "Center" or "Left" or "Right"
FontSizeText = 10.0 # text info dimension
TextColorText_R = 0.0 # text color info red 1 = 255
TextColorText_G = 0.0 # text color info green 1 = 255
TextColorText_B = 0.0 # text color info blue 1 = 255
arondi = 3 # round the info ex: 3 = 3 decimals

##### for dimensions info end ##########
##### Section configuration end ####################

def objectRealPlacement3D(obj, mode = 0): # search the real Placement
try:
objectPlacement = obj.Shape.Placement
objectPlacementBase = FreeCAD.Vector(objectPlacement.Base)

####
if mode == 0: # Base
objectWorkCenter = objectPlacementBase
elif mode == 1: # BoundBox
objectBoundBoxCenter = FreeCAD.Vector(obj.Shape.BoundBox.Center)
objectWorkCenter = objectBoundBoxCenter
elif mode == 2: # CenterOfMass
objectCenterOfMass = FreeCAD.Vector(obj.Shape.CenterOfMass)
objectWorkCenter = objectCenterOfMass
####
if hasattr(obj, "getGlobalPlacement"):
globalPlacement = obj.getGlobalPlacement()
globalPlacementBase = FreeCAD.Vector(globalPlacement.Base)
# objectRealPlacement3D = globalPlacementBase.add(objectWorkCenter).sub(objectPlacementBase)#ori
objectRealPlacement3D = globalPlacementBase.sub(objectWorkCenter)# adapte pour BB
else:
objectRealPlacement3D = objectWorkCenter

return objectRealPlacement3D
except Exception:
return FreeCAD.Vector(0.0, 0.0, 0.0)



sel = FreeCADGui.Selection.getSelection()
selEx = FreeCADGui.Selection.getSelectionEx()
selEx = FreeCADGui.Selection.getSelectionEx()
objs = [selobj.Object for selobj in selEx]
objs = [selobj.Object for selobj in selEx]
if len(objs) >= 1:
if len(objs) >= 1:
if hasattr(objs[0], "Shape"):
if hasattr(objs[0], "Shape"):
Line 81: Line 156:
s = objs[0].Points
s = objs[0].Points


# LineColor
try:
red = 1.0 # 1 = 255
# LineColor
green = 0.0 #
red = 1.0 # 1 = 255
blue = 0.0 #
green = 0.0 #
blue = 0.0 #
# boundBox
boundBox_ = s.BoundBox
boundBoxLX = boundBox_.XLength
boundBoxLY = boundBox_.YLength
boundBoxLZ = boundBox_.ZLength
nameLabel = sel[0].Label


# boundBox
try:
import unicodedata
boundBox_ = s.BoundBox
nameLabel = str(unicodedata.normalize('NFKD', nameLabel).encode('ascii','ignore'))[2:]
boundBoxLX = boundBox_.XLength
except Exception:
boundBoxLY = boundBox_.YLength
None
boundBoxLZ = boundBox_.ZLength


a = str(boundBox_)
a = str(boundBox_)
a,b = a.split('(')
a,b = a.split('(')
c = b.split(',')
c = b.split(',')
oripl_X = float(c[0])
oripl_X = float(c[0])
oripl_Y = float(c[1])
oripl_Y = float(c[1])
oripl_Z = float(c[2])
oripl_Z = float(c[2])
try:
if objs[0].getParentGeoFeatureGroup() == None:
placementOrigine = FreeCAD.Vector(0.0, 0.0, 0.0)
else:
placementOrigine = objectRealPlacement3D(FreeCAD.ActiveDocument.getObject(objs[0].Name),0)# search the real Placement
oripl_X += placementOrigine[0]
oripl_Y += placementOrigine[1]
oripl_Z += placementOrigine[2]
except Exception:
None
App.Console.PrintMessage(str(boundBox_)+"\r\n")
App.Console.PrintMessage("Rectangle : "+str(boundBoxLX)+" x "+str(boundBoxLY)+" x "+str(boundBoxLZ)+"\r\n")
if (createVol == 1) and (boundBoxLX > 0) and (boundBoxLY > 0) and (boundBoxLZ > 0): # Create Volume
BDvol = App.ActiveDocument.addObject("Part::Box",nameLabel + "_BoundBoxVolume")
#BDvol.Label = "BoundBoxVolume"
BDvol.Length.Value = boundBoxLX
BDvol.Width.Value = boundBoxLY
BDvol.Height.Value = boundBoxLZ
BDvol.Placement=App.Placement(App.Vector(oripl_X,oripl_Y,oripl_Z), App.Rotation(App.Vector(0,0,1),0), App.Vector(0,0,0))
FreeCADGui.ActiveDocument.getObject(BDvol.Name).LineColor = (red, green, blue)
FreeCADGui.ActiveDocument.getObject(BDvol.Name).PointColor = (red, green, blue)
FreeCADGui.ActiveDocument.getObject(BDvol.Name).ShapeColor = (red, green, blue)
FreeCADGui.ActiveDocument.getObject(BDvol.Name).Transparency = 80
App.Console.PrintMessage(nameLabel + "_BoundBoxVolume : " + str(BDvol.Shape.Volume)+"\r\n")
if createDimVol == 1: # section create dimension info for volume
conteneurVol = []
del conteneurVol[:]
conteneurVol = App.activeDocument().addObject("App::DocumentObjectGroup",nameLabel + "_BoundBoxVolume_Info")
pl_0C1 = Draft.makeText([str(round(boundBoxLX,arondi))],point=FreeCAD.Vector(oripl_X + (boundBoxLX/2), oripl_Y, oripl_Z))
pl_0C1.ViewObject.DisplayMode = DisplayModeText
pl_0C1.ViewObject.Justification = JustificationText
pl_0C1.ViewObject.TextColor = (TextColorText_R, TextColorText_G, TextColorText_B)
pl_0C1.ViewObject.FontSize = FontSizeText
pl_0C1.Label = nameLabel + "_Volume_X_" + str(round(boundBoxLX,arondi))
conteneurVol.addObject(pl_0C1)
pl_0C2 = Draft.makeText([str(round(boundBoxLY,arondi))],point=FreeCAD.Vector(oripl_X, oripl_Y + (boundBoxLY/2), oripl_Z))
pl_0C2.ViewObject.DisplayMode = DisplayModeText
pl_0C2.ViewObject.Justification = JustificationText
pl_0C2.ViewObject.TextColor = (TextColorText_R, TextColorText_G, TextColorText_B)
pl_0C2.ViewObject.FontSize = FontSizeText
pl_0C2.Label = nameLabel + "_Volume_Y_" + str(round(boundBoxLY,arondi))
conteneurVol.addObject(pl_0C2)
pl_0C3 = Draft.makeText([str(round(boundBoxLZ,arondi))],point=FreeCAD.Vector(oripl_X, oripl_Y, oripl_Z + (boundBoxLZ/2)))
pl_0C3.ViewObject.DisplayMode = DisplayModeText
pl_0C3.ViewObject.Justification = JustificationText
pl_0C3.ViewObject.TextColor = (TextColorText_R, TextColorText_G, TextColorText_B)
pl_0C3.ViewObject.FontSize = FontSizeText
pl_0C3.Label = nameLabel + "_Volume_Z_" + str(round(boundBoxLZ,arondi))
conteneurVol.addObject(pl_0C3)
# else:
# App.Console.PrintMessage("Not Volume BoundBox possible"+"\r\n")
App.Console.PrintMessage("_____________________"+"\r\n")


App.Console.PrintMessage(str(boundBox_)+"\r\n")
#####
App.Console.PrintMessage("Rectangle : "+str(boundBox_.XLength)+" x "+str(boundBox_.YLength)+" x "+str(boundBox_.ZLength)+"\r\n")
conteneurRectangle = []
del conteneurRectangle[:]
conteneurRectangle = App.activeDocument().addObject("App::DocumentObjectGroup",nameLabel + "_BoundBoxRectangle")
if createDim == 1: # conteneur dimension info
conteneurInfo = []
del conteneurInfo[:]
conteneurInfo = App.activeDocument().addObject("App::DocumentObjectGroup",nameLabel + "_BoundBoxRectangle_Info")
try:
if (boundBoxLX and boundBoxLY) > 0.0:
pl_0 = App.Placement(App.Vector(oripl_X,oripl_Y,oripl_Z), App.Rotation(0.0,0.0,0.0))
double = Draft.makeRectangle(length=boundBoxLX,height=boundBoxLY,placement=pl_0,face=False,support=None) #OK
double.Label = nameLabel + "_BoundBoxRectangle_Bo"
FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
conteneurRectangle.addObject(double)
# else:
# App.Console.PrintError("not value 0"+"\n")
if createDim == 1: # section create dimension info
pl_0C1 = Draft.makeText([str(round(boundBoxLX,arondi))],point=FreeCAD.Vector(pl_0.Base.x + (boundBoxLX/2), pl_0.Base.y, pl_0.Base.z))
pl_0C1.ViewObject.DisplayMode = DisplayModeText
pl_0C1.ViewObject.Justification = JustificationText
pl_0C1.ViewObject.TextColor = (TextColorText_R, TextColorText_G, TextColorText_B)
pl_0C1.ViewObject.FontSize = FontSizeText
pl_0C1.Label = nameLabel + "_Rectangle_Bo_0X_" + str(round(boundBoxLX,arondi))
conteneurInfo.addObject(pl_0C1)
pl_0C2 = Draft.makeText([str(round(boundBoxLY,arondi))],point=FreeCAD.Vector(pl_0.Base.x, pl_0.Base.y + (boundBoxLY/2), pl_0.Base.z))
pl_0C2.ViewObject.DisplayMode = DisplayModeText
pl_0C2.ViewObject.Justification = JustificationText
pl_0C2.ViewObject.TextColor = (TextColorText_R, TextColorText_G, TextColorText_B)
pl_0C2.ViewObject.FontSize = FontSizeText
pl_0C2.Label = nameLabel + "_Rectangle_Bo_0Y_" + str(round(boundBoxLY,arondi))
conteneurInfo.addObject(pl_0C2)
except:
App.Console.PrintError("not done 0"+"\n")


try:
if (createVol == 1) and (boundBoxLX > 0) and (boundBoxLY > 0) and (boundBoxLZ > 0): # Create Volume
if (boundBoxLX and boundBoxLY) > 0.0:
BDvol = App.ActiveDocument.addObject("Part::Box","BoundBoxVolume")
pl_1 = App.Placement(App.Vector(oripl_X,oripl_Y,oripl_Z+boundBoxLZ), App.Rotation(0.0,0.0,0.0))
#BDvol.Label = "BoundBoxVolume"
double = Draft.makeRectangle(length=boundBoxLX,height=boundBoxLY,placement=pl_1,face=False,support=None) #Ok
BDvol.Length.Value = boundBoxLX
double.Label = nameLabel + "_BoundBoxRectangle_To"
BDvol.Width.Value = boundBoxLY
FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
BDvol.Height.Value = boundBoxLZ
conteneurRectangle.addObject(double)
BDvol.Placement=App.Placement(App.Vector(oripl_X,oripl_Y,oripl_Z), App.Rotation(App.Vector(0,0,1),0), App.Vector(0,0,0))
# else:
FreeCADGui.ActiveDocument.getObject(BDvol.Name).LineColor = (red, green, blue)
# App.Console.PrintError("not value 1"+"\n")
FreeCADGui.ActiveDocument.getObject(BDvol.Name).PointColor = (red, green, blue)
FreeCADGui.ActiveDocument.getObject(BDvol.Name).ShapeColor = (red, green, blue)
if createDim == 1: # section create dimension info
FreeCADGui.ActiveDocument.getObject(BDvol.Name).Transparency = 80
pl_0C1 = Draft.makeText([str(round(boundBoxLX,arondi))],point=FreeCAD.Vector(pl_1.Base.x + (boundBoxLX/2), pl_1.Base.y, pl_1.Base.z))
App.Console.PrintMessage("BoundBoxVolume : " + str(BDvol.Shape.Volume)+"\r\n")
pl_0C1.ViewObject.DisplayMode = DisplayModeText
else:
pl_0C1.ViewObject.Justification = JustificationText
App.Console.PrintMessage("Not BoundBox possible"+"\r\n")
pl_0C1.ViewObject.TextColor = (TextColorText_R, TextColorText_G, TextColorText_B)
App.Console.PrintMessage("_____________________"+"\r\n")
pl_0C1.ViewObject.FontSize = FontSizeText
pl_0C1.Label = nameLabel + "_Rectangle_To_1X_" + str(round(boundBoxLX,arondi))
conteneurInfo.addObject(pl_0C1)
pl_0C2 = Draft.makeText([str(round(boundBoxLY,arondi))],point=FreeCAD.Vector(pl_1.Base.x, pl_1.Base.y + (boundBoxLY/2), pl_1.Base.z))
pl_0C2.ViewObject.DisplayMode = DisplayModeText
pl_0C2.ViewObject.Justification = JustificationText
pl_0C2.ViewObject.TextColor = (TextColorText_R, TextColorText_G, TextColorText_B)
pl_0C2.ViewObject.FontSize = FontSizeText
pl_0C2.Label = nameLabel + "_Rectangle_To_1Y_" + str(round(boundBoxLY,arondi))
conteneurInfo.addObject(pl_0C2)
except:
App.Console.PrintError("not done 1"+"\n")


#####
try:
if (boundBoxLX and boundBoxLZ) > 0.0:
try:
pl_2 = App.Placement(App.Vector(oripl_X,oripl_Y,oripl_Z), App.Rotation(0.0,0.0,90))
if (boundBox_.XLength and boundBox_.YLength) > 0.0:
double = Draft.makeRectangle(length=boundBoxLX,height=boundBoxLZ,placement=pl_2,face=False,support=None) #Ok
pl_0 = App.Placement(App.Vector(oripl_X,oripl_Y,oripl_Z), App.Rotation(0.0,0.0,0.0))
double.Label = nameLabel + "_BoundBoxRectangle_Fr"
double = Draft.makeRectangle(length=boundBox_.XLength,height=boundBox_.YLength,placement=pl_0,face=False,support=None) #OK
FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
double.Label = "BoundBoxRectangle_Bo"
conteneurRectangle.addObject(double)
FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
# else:
# else:
# App.Console.PrintError("not value 0"+"\n")
# App.Console.PrintError("not value 2"+"\n")
except:
if createDim == 1: # section create dimension info
App.Console.PrintError("not done 0"+"\n")
pl_0C1 = Draft.makeText([str(round(boundBoxLX,arondi))],point=FreeCAD.Vector(pl_2.Base.x + (boundBoxLX/2), pl_2.Base.y, pl_2.Base.z))
try:
pl_0C1.ViewObject.DisplayMode = DisplayModeText
if (boundBox_.XLength and boundBox_.YLength) > 0.0:
pl_0C1.ViewObject.Justification = JustificationText
pl_1 = App.Placement(App.Vector(oripl_X,oripl_Y,oripl_Z+boundBoxLZ), App.Rotation(0.0,0.0,0.0))
pl_0C1.ViewObject.TextColor = (TextColorText_R, TextColorText_G, TextColorText_B)
double = Draft.makeRectangle(length=boundBox_.XLength,height=boundBox_.YLength,placement=pl_1,face=False,support=None) #Ok
double.Label = "BoundBoxRectangle_To"
pl_0C1.ViewObject.FontSize = FontSizeText
pl_0C1.Label = nameLabel + "_Rectangle_Fr_2X_" + str(round(boundBoxLX,arondi))
FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
conteneurInfo.addObject(pl_0C1)
# else:
# App.Console.PrintError("not value 1"+"\n")
pl_0C2 = Draft.makeText([str(round(boundBoxLZ,arondi))],point=FreeCAD.Vector(pl_2.Base.x, pl_2.Base.y, pl_2.Base.z + (boundBoxLZ/2)))
except:
pl_0C2.ViewObject.DisplayMode = DisplayModeText
App.Console.PrintError("not done 1"+"\n")
pl_0C2.ViewObject.Justification = JustificationText
try:
pl_0C2.ViewObject.TextColor = (TextColorText_R, TextColorText_G, TextColorText_B)
if (boundBox_.XLength and boundBox_.ZLength) > 0.0:
pl_0C2.ViewObject.FontSize = FontSizeText
pl_2 = App.Placement(App.Vector(oripl_X,oripl_Y,oripl_Z), App.Rotation(0.0,0.0,90))
pl_0C2.Label = nameLabel + "_Rectangle_Fr_2Z_" + str(round(boundBoxLZ,arondi))
double = Draft.makeRectangle(length=boundBox_.XLength,height=boundBox_.ZLength,placement=pl_2,face=False,support=None) #Ok
double.Label = "BoundBoxRectangle_Fr"
conteneurInfo.addObject(pl_0C2)
FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
# else:
except:
# App.Console.PrintError("not value 2"+"\n")
App.Console.PrintError("not done 2"+"\n")

except:
try:
App.Console.PrintError("not done 2"+"\n")
if (boundBoxLX and boundBoxLZ) > 0.0:
try:
pl_3 = App.Placement(App.Vector(oripl_X,oripl_Y+boundBoxLY,oripl_Z), App.Rotation(0.0,0.0,90))
if (boundBox_.XLength and boundBox_.ZLength) > 0.0:
double = Draft.makeRectangle(length=boundBoxLX,height=boundBoxLZ,placement=pl_3,face=False,support=None) #Ok
pl_3 = App.Placement(App.Vector(oripl_X,oripl_Y+boundBoxLY,oripl_Z), App.Rotation(0.0,0.0,90))
double.Label = nameLabel + "_BoundBoxRectangle_Re"
double = Draft.makeRectangle(length=boundBox_.XLength,height=boundBox_.ZLength,placement=pl_3,face=False,support=None) #Ok
FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
double.Label = "BoundBoxRectangle_Re"
conteneurRectangle.addObject(double)
FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
# else:
# else:
# App.Console.PrintError("not value 3"+"\n")
# App.Console.PrintError("not value 3"+"\n")
except:
if createDim == 1: # section create dimension info
App.Console.PrintError("not done 3"+"\n")
pl_0C1 = Draft.makeText([str(round(boundBoxLX,arondi))],point=FreeCAD.Vector(pl_3.Base.x + (boundBoxLX/2), pl_3.Base.y, pl_3.Base.z))
try:
pl_0C1.ViewObject.DisplayMode = DisplayModeText
if (boundBoxLY and boundBox_.ZLength) > 0.0:
pl_0C1.ViewObject.Justification = JustificationText
pl_4 = App.Placement(App.Vector(oripl_X,oripl_Y,oripl_Z), App.Rotation(90,0.0,90))
pl_0C1.ViewObject.TextColor = (TextColorText_R, TextColorText_G, TextColorText_B)
double = Draft.makeRectangle(length=boundBoxLY,height=boundBox_.ZLength,placement=pl_4,face=False,support=None) #Ok
double.Label = "BoundBoxRectangle_Le"
pl_0C1.ViewObject.FontSize = FontSizeText
pl_0C1.Label = nameLabel + "_Rectangle_Re_3X_" + str(round(boundBoxLX,arondi))
FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
conteneurInfo.addObject(pl_0C1)
# else:
# App.Console.PrintError("not value 4"+"\n")
pl_0C2 = Draft.makeText([str(round(boundBoxLZ,arondi))],point=FreeCAD.Vector(pl_3.Base.x, pl_3.Base.y, pl_3.Base.z + (boundBoxLZ/2)))
except:
pl_0C2.ViewObject.DisplayMode = DisplayModeText
App.Console.PrintError("not done 4"+"\n")
pl_0C2.ViewObject.Justification = JustificationText
try:
pl_0C2.ViewObject.TextColor = (TextColorText_R, TextColorText_G, TextColorText_B)
if (boundBoxLY and boundBoxLZ) > 0.0:
pl_0C2.ViewObject.FontSize = FontSizeText
pl_5 = App.Placement(App.Vector(oripl_X+boundBoxLX,oripl_Y,oripl_Z), App.Rotation(90,0.0,90))
pl_0C2.Label = nameLabel + "_Rectangle_Re_3Z_" + str(round(boundBoxLZ,arondi))
double = Draft.makeRectangle(length=boundBoxLY,height=boundBoxLZ,placement=pl_5,face=False,support=None) #Ok
double.Label = "BoundBoxRectangle_Ri"
conteneurInfo.addObject(pl_0C2)
FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
# else:
except:
# App.Console.PrintError("not value 5"+"\n")
App.Console.PrintError("not done 3"+"\n")

except:
try:
App.Console.PrintError("not done 5"+"\n")
if (boundBoxLY and boundBoxLZ) > 0.0:
#####
pl_4 = App.Placement(App.Vector(oripl_X,oripl_Y,oripl_Z), App.Rotation(90,0.0,90))
App.ActiveDocument.recompute()
double = Draft.makeRectangle(length=boundBoxLY,height=boundBoxLZ,placement=pl_4,face=False,support=None) #Ok
double.Label = nameLabel + "_BoundBoxRectangle_Le"
FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
conteneurRectangle.addObject(double)
# else:
# App.Console.PrintError("not value 4"+"\n")
if createDim == 1: # section create dimension info
pl_0C1 = Draft.makeText([str(round(boundBoxLY,arondi))],point=FreeCAD.Vector(pl_4.Base.x, pl_4.Base.y + (boundBoxLY/2), pl_4.Base.z))
pl_0C1.ViewObject.DisplayMode = DisplayModeText
pl_0C1.ViewObject.Justification = JustificationText
pl_0C1.ViewObject.TextColor = (TextColorText_R, TextColorText_G, TextColorText_B)
pl_0C1.ViewObject.FontSize = FontSizeText
pl_0C1.Label = nameLabel + "_Rectangle_Le_4Y_" + str(round(boundBoxLY,arondi))
conteneurInfo.addObject(pl_0C1)
pl_0C2 = Draft.makeText([str(round(boundBoxLZ,arondi))],point=FreeCAD.Vector(pl_4.Base.x, pl_4.Base.y, pl_4.Base.z + (boundBoxLZ/2)))
pl_0C2.ViewObject.DisplayMode = DisplayModeText
pl_0C2.ViewObject.Justification = JustificationText
pl_0C2.ViewObject.TextColor = (TextColorText_R, TextColorText_G, TextColorText_B)
pl_0C2.ViewObject.FontSize = FontSizeText
pl_0C2.Label = nameLabel + "_Rectangle_Le_4Z_" + str(round(boundBoxLZ,arondi))
conteneurInfo.addObject(pl_0C2)
except:
App.Console.PrintError("not done 4"+"\n")

try:
if (boundBoxLY and boundBoxLZ) > 0.0:
pl_5 = App.Placement(App.Vector(oripl_X+boundBoxLX,oripl_Y,oripl_Z), App.Rotation(90,0.0,90))
double = Draft.makeRectangle(length=boundBoxLY,height=boundBoxLZ,placement=pl_5,face=False,support=None) #Ok
double.Label = nameLabel + "_BoundBoxRectangle_Ri"
FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
conteneurRectangle.addObject(double)
# else:
# App.Console.PrintError("not value 5"+"\n")
if createDim == 1: # section create dimension info
pl_0C1 = Draft.makeText([str(round(boundBoxLY,arondi))],point=FreeCAD.Vector(pl_5.Base.x, pl_5.Base.y + (boundBoxLY/2), pl_5.Base.z))
pl_0C1.ViewObject.DisplayMode = DisplayModeText
pl_0C1.ViewObject.Justification = JustificationText
pl_0C1.ViewObject.TextColor = (TextColorText_R, TextColorText_G, TextColorText_B)
pl_0C1.ViewObject.FontSize = FontSizeText
pl_0C1.Label = nameLabel + "_Rectangle_Ri_5Y_" + str(round(boundBoxLY,arondi))
conteneurInfo.addObject(pl_0C1)
pl_0C2 = Draft.makeText([str(round(boundBoxLZ,arondi))],point=FreeCAD.Vector(pl_5.Base.x, pl_5.Base.y, pl_5.Base.z + (boundBoxLZ/2)))
pl_0C2.ViewObject.DisplayMode = DisplayModeText
pl_0C2.ViewObject.Justification = JustificationText
pl_0C2.ViewObject.TextColor = (TextColorText_R, TextColorText_G, TextColorText_B)
pl_0C2.ViewObject.FontSize = FontSizeText
pl_0C2.Label = nameLabel + "_Rectangle_Ri_5Z_" + str(round(boundBoxLZ,arondi))
conteneurInfo.addObject(pl_0C2)
except:
App.Console.PrintError("not done 5"+"\n")
#####
App.ActiveDocument.recompute()
except Exception:
App.Console.PrintError("Bad selection"+"\n")
else:
else:
App.Console.PrintMessage("Select an object !"+"\n")
App.Console.PrintMessage("Select an object !"+"\n")


}}
}}

<translate>
<translate>

==Version== <!--T:12-->
==Version== <!--T:12-->
Version: 0.11 le Date: 2019/05/29: "nameLabel = str(unicodedata.normalize('NFKD', nameLabel).encode('ascii','ignore'))" instead "def()"


<!--T:22-->
ver 0.10 le 2019/05/23 upgrade > 0.19 and supp the "éçà.." with def() not encode()....

<!--T:21-->
ver 0.9 le 2018-10-12: add test > 17
</translate>
{{Code|code=
if int(FreeCAD.Version()[1]) > 17: # Version de FreeCAD
DisplayModeText = str(u"2D text") # available : u"2D text" or u"3D text"
else:
DisplayModeText = str(u"Screen") # available : u"Screen" or u"World"
}}
<translate>

<!--T:19-->
ver 0.8 le 05/10/2018: upgrade the ver 0.8 compatible with FC 0.17 (getGlobalPlacement)

<!--T:17-->
ver 0.7 le 28/01/2018: correct error with label accent "nameLabel = unicodedata.normalize('NFKD', nameLabel).encode('ascii','ignore')"

<!--T:14-->
ver 0.6 le 08/08/2017: add text info dimension , contener for rectangles, info rectangles, info volume, add section configuration color , label object selected

<!--T:16-->
ver 0.5 le 08/05/2017 : upgrade now accept the "mesh" and "Points" thanks wmayer [http://forum.freecadweb.org/viewtopic.php?f=13&t=22331 Makro Bounding-Box für STL importierte Teile und für Punktewolken]
ver 0.5 le 08/05/2017 : upgrade now accept the "mesh" and "Points" thanks wmayer [http://forum.freecadweb.org/viewtopic.php?f=13&t=22331 Makro Bounding-Box für STL importierte Teile und für Punktewolken]


<!--T:13-->
<!--T:13-->
ver 0.4 le 04/06/2016 : test if value = 0 then not create boundbox (ex: object Draft)
ver 0.4 le 04/06/2016 : test if value = 0 then not create boundbox (ex: object Draft)

</translate>
</translate>
<languages/>

Revision as of 01:22, 8 May 2020

Macro BoundingBox Tracing

Description
This macro red trace (editable) around the BoundingBox with 6 rectangles.

Macro version: 0.11
Last modified: 2019/05/29
FreeCAD version: All
Download: ToolBar Icon
Author: Mario52
Author
Mario52
Download
ToolBar Icon
Links
Macro Version
0.11
Date last modified
2019/05/29
FreeCAD Version(s)
All
Default shortcut
None
See also
None

Description

This macro red trace (editable) around the BoundingBox 6 Faces with 6 rectangles.

CenterFace

Usage

Select the object and launch the macro. 6 rectangles are coloured red (can be changed)

Info contener

If createVol = 1 (Line 33) one volume is created

Icon

Download the file image and copy in your macro repertory.

Click the image, in the new window position the mouse over the image, click the right mouse and do "Save target as ..."

ToolBar Icon

Script

Macro_BoundingBox_Tracing.FCMacro

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

# cette macro trace en rouge (modifiable) le tour du boundingbox avec 6 rectangles
# si "createVol" = 1 il sera cree un volume (rouge) de la dimension du BoundBox
# this macro red trace (editable) around the BoundingBox with 6 rectangles
# if "createVol" = 1 on volume (red) is created 
# Macro_BoundingBox_Tracing
#
#OS: Windows Vista     #OS: Windows 8.1                                #OS: Windows 10                                 #OS: Windows 10
#Platform: 32-bit      #Word size of OS: 64-bit                        #Word size of OS: 64-bit                        #Word size of OS: 64-bit
#Version: 0.14.3389    #Word size of FreeCAD: 64-bit                   #Word size of FreeCAD: 64-bit                   #Word size of FreeCAD: 64-bit
#Python version: 2.6.2 #Version: 0.15.4671 (Git)                       #Version: 0.16.6700 (Git)                       #Version: 0.17.13528 (Git)
#Qt version: 4.5.2     #Branch: releases/FreeCAD-0-15                  #Build type: Release                            #Build type: Release
#Coin version: 3.1.0   #Hash: 244b3aef360841646cbfe80a1b225c8b39c8380c #Branch: releases/FreeCAD-0-16                  #Branch: releases/FreeCAD-0-17
#SoQt version: 1.4.1   #Python version: 2.7.8                          #Hash: 7b925d11aa69ac405b423635adb1e2833f18a817 #Hash: 5c3f7bf8ec51e2c7187789f7edba71a7aa82a88b
#OCC version: 6.5.1    #Qt version: 4.8.6                              #Python version: 2.7.8                          #Python version: 2.7.14
#                      #Coin version: 4.0.0a                           #Qt version: 4.8.6                              #Qt version: 4.8.7
#                      #OCC version: 6.8.0.oce-0.17                    #Coin version: 4.0.0a                           #Coin version: 4.0.0a
#                                                                      #OCC version: 6.8.0.oce-0.17                    #OCC version: 7.2.0
###############################################################################################################################################
#OS: Windows 10 (10.0)
#Word size of OS: 64-bit
#Word size of FreeCAD: 64-bit
#Version: 0.19.16624 (Git)
#Build type: Release
#Branch: master
#Hash: 222ae7305fdf1097e4ef3d050f69dff47dbd8786
#Python version: 3.6.8
#Qt version: 5.12.1
#Coin version: 4.0.0a
#OCC version: 7.3.0
###############################################################################################################################################

__title__   = "BoundingBox_Tracing"
__author__  = "Mario52"
__url__     = "http://www.freecadweb.org/index-fr.html"
__Wiki__    = "https://www.freecadweb.org/wiki/Macro_BoundingBox_Tracing"
__version__ = "0.11"
__date__    = "2019/05/29" #  YYYY/MM/DD


import PySide
import FreeCAD, FreeCADGui, Draft, Part
App = FreeCAD

##### Section configuration begin ##################
##### for volume begin ###################
createVol         = 1           # give 1 for create Volume # mettre a 1 pour creer un volume
createDimVol      = 1           # 1 = create dimension info : 0 = not dimension info
##### for volume end   ###################

##### for dimensions info begin ##########
createDim         = 1           # 1 = create dimension info : 0 = not create dimension info

if int(FreeCAD.Version()[1]) > 17:      # Version de FreeCAD
    DisplayModeText   = str(u"3D text") # available : u"2D text" or u"3D text" 
else:
    DisplayModeText   = str(u"Screen")  # available : u"Screen" or u"World" 

JustificationText = str(u"Center")    # available : "Center" or "Left" or "Right"
FontSizeText      = 10.0        # text info dimension
TextColorText_R   = 0.0         # text color info red      1 = 255
TextColorText_G   = 0.0         # text color info green    1 = 255
TextColorText_B   = 0.0         # text color info blue     1 = 255
arondi            = 3           # round the info ex: 3 = 3 decimals

##### for dimensions info end   ##########
##### Section configuration end ####################

def objectRealPlacement3D(obj, mode = 0):    # search the real Placement
    try:
        objectPlacement      = obj.Shape.Placement
        objectPlacementBase  = FreeCAD.Vector(objectPlacement.Base)

        #### 
        if   mode == 0:    # Base
            objectWorkCenter     = objectPlacementBase
        elif mode == 1:    # BoundBox
            objectBoundBoxCenter = FreeCAD.Vector(obj.Shape.BoundBox.Center)
            objectWorkCenter     = objectBoundBoxCenter
        elif mode == 2:    # CenterOfMass
            objectCenterOfMass   = FreeCAD.Vector(obj.Shape.CenterOfMass)
            objectWorkCenter     = objectCenterOfMass
        ####
        
        if hasattr(obj, "getGlobalPlacement"):
            globalPlacement       = obj.getGlobalPlacement()
            globalPlacementBase   = FreeCAD.Vector(globalPlacement.Base)
#            objectRealPlacement3D = globalPlacementBase.add(objectWorkCenter).sub(objectPlacementBase)#ori
            objectRealPlacement3D = globalPlacementBase.sub(objectWorkCenter)# adapte pour BB
        else:
            objectRealPlacement3D = objectWorkCenter

        return objectRealPlacement3D
    except Exception:
        return FreeCAD.Vector(0.0, 0.0, 0.0)


sel   = FreeCADGui.Selection.getSelection()
selEx = FreeCADGui.Selection.getSelectionEx()
objs  = [selobj.Object for selobj in selEx]
    
if len(objs) >= 1:
    if hasattr(objs[0], "Shape"):
        s = objs[0].Shape
    elif hasattr(objs[0], "Mesh"):      # upgrade with wmayer thanks #http://forum.freecadweb.org/viewtopic.php?f=13&t=22331
        s = objs[0].Mesh
    elif hasattr(objs[0], "Points"):
        s = objs[0].Points

    try:
        # LineColor
        red   = 1.0  # 1 = 255
        green = 0.0  #
        blue  = 0.0  #
    
        # boundBox
        boundBox_ = s.BoundBox
        boundBoxLX = boundBox_.XLength
        boundBoxLY = boundBox_.YLength
        boundBoxLZ = boundBox_.ZLength
        nameLabel  = sel[0].Label

        try:
            import unicodedata    
            nameLabel = str(unicodedata.normalize('NFKD', nameLabel).encode('ascii','ignore'))[2:]
        except Exception:
            None

        a = str(boundBox_)
        a,b = a.split('(')
        c = b.split(',')
        oripl_X = float(c[0])
        oripl_Y = float(c[1])
        oripl_Z = float(c[2])
    
        try:
            if objs[0].getParentGeoFeatureGroup() == None:
                placementOrigine = FreeCAD.Vector(0.0, 0.0, 0.0)
            else:
                placementOrigine = objectRealPlacement3D(FreeCAD.ActiveDocument.getObject(objs[0].Name),0)# search the real Placement
    
            oripl_X += placementOrigine[0]
            oripl_Y += placementOrigine[1]
            oripl_Z += placementOrigine[2]
        except Exception:
            None
    
        App.Console.PrintMessage(str(boundBox_)+"\r\n")
        App.Console.PrintMessage("Rectangle      : "+str(boundBoxLX)+" x "+str(boundBoxLY)+" x "+str(boundBoxLZ)+"\r\n")
        
        if (createVol == 1) and (boundBoxLX > 0) and (boundBoxLY > 0) and (boundBoxLZ > 0):  # Create Volume
            BDvol = App.ActiveDocument.addObject("Part::Box",nameLabel + "_BoundBoxVolume")
            #BDvol.Label = "BoundBoxVolume"
            BDvol.Length.Value = boundBoxLX
            BDvol.Width.Value  = boundBoxLY
            BDvol.Height.Value = boundBoxLZ
            BDvol.Placement=App.Placement(App.Vector(oripl_X,oripl_Y,oripl_Z), App.Rotation(App.Vector(0,0,1),0), App.Vector(0,0,0))
            FreeCADGui.ActiveDocument.getObject(BDvol.Name).LineColor  = (red, green, blue)
            FreeCADGui.ActiveDocument.getObject(BDvol.Name).PointColor = (red, green, blue)
            FreeCADGui.ActiveDocument.getObject(BDvol.Name).ShapeColor = (red, green, blue)
            FreeCADGui.ActiveDocument.getObject(BDvol.Name).Transparency = 80
            App.Console.PrintMessage(nameLabel + "_BoundBoxVolume : " + str(BDvol.Shape.Volume)+"\r\n")
    
            if createDimVol == 1:    # section create dimension info for volume
                conteneurVol = []
                del conteneurVol[:]
                conteneurVol = App.activeDocument().addObject("App::DocumentObjectGroup",nameLabel + "_BoundBoxVolume_Info")
    
                pl_0C1 = Draft.makeText([str(round(boundBoxLX,arondi))],point=FreeCAD.Vector(oripl_X + (boundBoxLX/2), oripl_Y, oripl_Z))
                pl_0C1.ViewObject.DisplayMode   = DisplayModeText
                pl_0C1.ViewObject.Justification = JustificationText
                pl_0C1.ViewObject.TextColor     = (TextColorText_R, TextColorText_G, TextColorText_B)
                pl_0C1.ViewObject.FontSize      = FontSizeText
                pl_0C1.Label      = nameLabel + "_Volume_X_" + str(round(boundBoxLX,arondi))
                conteneurVol.addObject(pl_0C1)
    
                pl_0C2 = Draft.makeText([str(round(boundBoxLY,arondi))],point=FreeCAD.Vector(oripl_X, oripl_Y + (boundBoxLY/2), oripl_Z))
                pl_0C2.ViewObject.DisplayMode   = DisplayModeText
                pl_0C2.ViewObject.Justification = JustificationText
                pl_0C2.ViewObject.TextColor     = (TextColorText_R, TextColorText_G, TextColorText_B)
                pl_0C2.ViewObject.FontSize      = FontSizeText
                pl_0C2.Label      = nameLabel + "_Volume_Y_" + str(round(boundBoxLY,arondi))
                conteneurVol.addObject(pl_0C2)
        
                pl_0C3 = Draft.makeText([str(round(boundBoxLZ,arondi))],point=FreeCAD.Vector(oripl_X, oripl_Y, oripl_Z + (boundBoxLZ/2)))
                pl_0C3.ViewObject.DisplayMode   = DisplayModeText
                pl_0C3.ViewObject.Justification = JustificationText
                pl_0C3.ViewObject.TextColor     = (TextColorText_R, TextColorText_G, TextColorText_B)
                pl_0C3.ViewObject.FontSize      = FontSizeText
                pl_0C3.Label      = nameLabel + "_Volume_Z_" + str(round(boundBoxLZ,arondi))
                conteneurVol.addObject(pl_0C3)
    
    #    else:
    #        App.Console.PrintMessage("Not Volume BoundBox possible"+"\r\n")
        App.Console.PrintMessage("_____________________"+"\r\n")

    
        #####
        conteneurRectangle = []
        del conteneurRectangle[:]
        conteneurRectangle = App.activeDocument().addObject("App::DocumentObjectGroup",nameLabel + "_BoundBoxRectangle")
    
        if createDim == 1:    # conteneur dimension info
            conteneurInfo = []
            del conteneurInfo[:]
            conteneurInfo = App.activeDocument().addObject("App::DocumentObjectGroup",nameLabel + "_BoundBoxRectangle_Info")
        try:
            if (boundBoxLX and boundBoxLY) > 0.0:
                pl_0 = App.Placement(App.Vector(oripl_X,oripl_Y,oripl_Z), App.Rotation(0.0,0.0,0.0))
                double = Draft.makeRectangle(length=boundBoxLX,height=boundBoxLY,placement=pl_0,face=False,support=None) #OK
                double.Label = nameLabel + "_BoundBoxRectangle_Bo"
                FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
                conteneurRectangle.addObject(double)
    #        else:
    #            App.Console.PrintError("not value 0"+"\n")
    
            if createDim == 1:    # section create dimension info
                pl_0C1 = Draft.makeText([str(round(boundBoxLX,arondi))],point=FreeCAD.Vector(pl_0.Base.x + (boundBoxLX/2), pl_0.Base.y, pl_0.Base.z))
                pl_0C1.ViewObject.DisplayMode   = DisplayModeText
                pl_0C1.ViewObject.Justification = JustificationText
                pl_0C1.ViewObject.TextColor     = (TextColorText_R, TextColorText_G, TextColorText_B)
                pl_0C1.ViewObject.FontSize      = FontSizeText
                pl_0C1.Label      = nameLabel + "_Rectangle_Bo_0X_" + str(round(boundBoxLX,arondi))
                conteneurInfo.addObject(pl_0C1)
        
                pl_0C2 = Draft.makeText([str(round(boundBoxLY,arondi))],point=FreeCAD.Vector(pl_0.Base.x, pl_0.Base.y + (boundBoxLY/2), pl_0.Base.z))
                pl_0C2.ViewObject.DisplayMode   = DisplayModeText
                pl_0C2.ViewObject.Justification = JustificationText
                pl_0C2.ViewObject.TextColor     = (TextColorText_R, TextColorText_G, TextColorText_B)
                pl_0C2.ViewObject.FontSize      = FontSizeText
                pl_0C2.Label      = nameLabel + "_Rectangle_Bo_0Y_" + str(round(boundBoxLY,arondi))
                conteneurInfo.addObject(pl_0C2)
    
        except:
            App.Console.PrintError("not done 0"+"\n")

        try:
            if (boundBoxLX and boundBoxLY) > 0.0:
                pl_1 = App.Placement(App.Vector(oripl_X,oripl_Y,oripl_Z+boundBoxLZ), App.Rotation(0.0,0.0,0.0))
                double = Draft.makeRectangle(length=boundBoxLX,height=boundBoxLY,placement=pl_1,face=False,support=None) #Ok
                double.Label = nameLabel + "_BoundBoxRectangle_To"
                FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
                conteneurRectangle.addObject(double)
    #        else:
    #            App.Console.PrintError("not value 1"+"\n")
    
            if createDim == 1:    # section create dimension info
                pl_0C1 = Draft.makeText([str(round(boundBoxLX,arondi))],point=FreeCAD.Vector(pl_1.Base.x + (boundBoxLX/2), pl_1.Base.y, pl_1.Base.z))
                pl_0C1.ViewObject.DisplayMode   = DisplayModeText
                pl_0C1.ViewObject.Justification = JustificationText
                pl_0C1.ViewObject.TextColor     = (TextColorText_R, TextColorText_G, TextColorText_B)
                pl_0C1.ViewObject.FontSize      = FontSizeText
                pl_0C1.Label      = nameLabel + "_Rectangle_To_1X_" + str(round(boundBoxLX,arondi))
                conteneurInfo.addObject(pl_0C1)
        
                pl_0C2 = Draft.makeText([str(round(boundBoxLY,arondi))],point=FreeCAD.Vector(pl_1.Base.x, pl_1.Base.y + (boundBoxLY/2), pl_1.Base.z))
                pl_0C2.ViewObject.DisplayMode   = DisplayModeText
                pl_0C2.ViewObject.Justification = JustificationText
                pl_0C2.ViewObject.TextColor     = (TextColorText_R, TextColorText_G, TextColorText_B)
                pl_0C2.ViewObject.FontSize      = FontSizeText
                pl_0C2.Label      = nameLabel + "_Rectangle_To_1Y_" + str(round(boundBoxLY,arondi))
                conteneurInfo.addObject(pl_0C2)
    
        except:
            App.Console.PrintError("not done 1"+"\n")

        try:
            if (boundBoxLX and boundBoxLZ) > 0.0:
                pl_2 = App.Placement(App.Vector(oripl_X,oripl_Y,oripl_Z), App.Rotation(0.0,0.0,90))
                double = Draft.makeRectangle(length=boundBoxLX,height=boundBoxLZ,placement=pl_2,face=False,support=None) #Ok
                double.Label = nameLabel + "_BoundBoxRectangle_Fr"
                FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
                conteneurRectangle.addObject(double)
    #        else:
    #            App.Console.PrintError("not value 2"+"\n")
    
            if createDim == 1:    # section create dimension info
                pl_0C1 = Draft.makeText([str(round(boundBoxLX,arondi))],point=FreeCAD.Vector(pl_2.Base.x + (boundBoxLX/2), pl_2.Base.y, pl_2.Base.z))
                pl_0C1.ViewObject.DisplayMode   = DisplayModeText
                pl_0C1.ViewObject.Justification = JustificationText
                pl_0C1.ViewObject.TextColor     = (TextColorText_R, TextColorText_G, TextColorText_B)
                pl_0C1.ViewObject.FontSize      = FontSizeText
                pl_0C1.Label      = nameLabel + "_Rectangle_Fr_2X_" + str(round(boundBoxLX,arondi))
                conteneurInfo.addObject(pl_0C1)
       
                pl_0C2 = Draft.makeText([str(round(boundBoxLZ,arondi))],point=FreeCAD.Vector(pl_2.Base.x, pl_2.Base.y, pl_2.Base.z + (boundBoxLZ/2)))
                pl_0C2.ViewObject.DisplayMode   = DisplayModeText
                pl_0C2.ViewObject.Justification = JustificationText
                pl_0C2.ViewObject.TextColor     = (TextColorText_R, TextColorText_G, TextColorText_B)
                pl_0C2.ViewObject.FontSize      = FontSizeText
                pl_0C2.Label      = nameLabel + "_Rectangle_Fr_2Z_" + str(round(boundBoxLZ,arondi))
                conteneurInfo.addObject(pl_0C2)
    
        except:
            App.Console.PrintError("not done 2"+"\n")

        try:
            if (boundBoxLX and boundBoxLZ) > 0.0:
                pl_3 = App.Placement(App.Vector(oripl_X,oripl_Y+boundBoxLY,oripl_Z), App.Rotation(0.0,0.0,90))
                double = Draft.makeRectangle(length=boundBoxLX,height=boundBoxLZ,placement=pl_3,face=False,support=None) #Ok
                double.Label = nameLabel + "_BoundBoxRectangle_Re"
                FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
                conteneurRectangle.addObject(double)
    #        else:
    #            App.Console.PrintError("not value 3"+"\n")
    
            if createDim == 1:    # section create dimension info
                pl_0C1 = Draft.makeText([str(round(boundBoxLX,arondi))],point=FreeCAD.Vector(pl_3.Base.x + (boundBoxLX/2), pl_3.Base.y, pl_3.Base.z))
                pl_0C1.ViewObject.DisplayMode   = DisplayModeText
                pl_0C1.ViewObject.Justification = JustificationText
                pl_0C1.ViewObject.TextColor     = (TextColorText_R, TextColorText_G, TextColorText_B)
                pl_0C1.ViewObject.FontSize      = FontSizeText
                pl_0C1.Label      = nameLabel + "_Rectangle_Re_3X_" + str(round(boundBoxLX,arondi))
                conteneurInfo.addObject(pl_0C1)
        
                pl_0C2 = Draft.makeText([str(round(boundBoxLZ,arondi))],point=FreeCAD.Vector(pl_3.Base.x, pl_3.Base.y, pl_3.Base.z + (boundBoxLZ/2)))
                pl_0C2.ViewObject.DisplayMode   = DisplayModeText
                pl_0C2.ViewObject.Justification = JustificationText
                pl_0C2.ViewObject.TextColor     = (TextColorText_R, TextColorText_G, TextColorText_B)
                pl_0C2.ViewObject.FontSize      = FontSizeText
                pl_0C2.Label      = nameLabel + "_Rectangle_Re_3Z_" + str(round(boundBoxLZ,arondi))
                conteneurInfo.addObject(pl_0C2)
    
        except:
            App.Console.PrintError("not done 3"+"\n")

        try:
            if (boundBoxLY and boundBoxLZ) > 0.0:
                pl_4 = App.Placement(App.Vector(oripl_X,oripl_Y,oripl_Z), App.Rotation(90,0.0,90))
                double = Draft.makeRectangle(length=boundBoxLY,height=boundBoxLZ,placement=pl_4,face=False,support=None) #Ok
                double.Label = nameLabel + "_BoundBoxRectangle_Le"
                FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
                conteneurRectangle.addObject(double)
    #        else:
    #            App.Console.PrintError("not value 4"+"\n")
    
            if createDim == 1:    # section create dimension info
                pl_0C1 = Draft.makeText([str(round(boundBoxLY,arondi))],point=FreeCAD.Vector(pl_4.Base.x, pl_4.Base.y + (boundBoxLY/2), pl_4.Base.z))
                pl_0C1.ViewObject.DisplayMode   = DisplayModeText
                pl_0C1.ViewObject.Justification = JustificationText
                pl_0C1.ViewObject.TextColor     = (TextColorText_R, TextColorText_G, TextColorText_B)
                pl_0C1.ViewObject.FontSize      = FontSizeText
                pl_0C1.Label      = nameLabel + "_Rectangle_Le_4Y_" + str(round(boundBoxLY,arondi))
                conteneurInfo.addObject(pl_0C1)
        
                pl_0C2 = Draft.makeText([str(round(boundBoxLZ,arondi))],point=FreeCAD.Vector(pl_4.Base.x, pl_4.Base.y, pl_4.Base.z + (boundBoxLZ/2)))
                pl_0C2.ViewObject.DisplayMode   = DisplayModeText
                pl_0C2.ViewObject.Justification = JustificationText
                pl_0C2.ViewObject.TextColor     = (TextColorText_R, TextColorText_G, TextColorText_B)
                pl_0C2.ViewObject.FontSize      = FontSizeText
                pl_0C2.Label      = nameLabel + "_Rectangle_Le_4Z_" + str(round(boundBoxLZ,arondi))
                conteneurInfo.addObject(pl_0C2)
    
        except:
            App.Console.PrintError("not done 4"+"\n")

        try:
            if (boundBoxLY and boundBoxLZ) > 0.0:
                pl_5 = App.Placement(App.Vector(oripl_X+boundBoxLX,oripl_Y,oripl_Z), App.Rotation(90,0.0,90))
                double = Draft.makeRectangle(length=boundBoxLY,height=boundBoxLZ,placement=pl_5,face=False,support=None) #Ok
                double.Label = nameLabel + "_BoundBoxRectangle_Ri"
                FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
                conteneurRectangle.addObject(double)
    #            else:
    #                App.Console.PrintError("not value 5"+"\n")
    
            if createDim == 1:    # section create dimension info
                pl_0C1 = Draft.makeText([str(round(boundBoxLY,arondi))],point=FreeCAD.Vector(pl_5.Base.x, pl_5.Base.y + (boundBoxLY/2), pl_5.Base.z))
                pl_0C1.ViewObject.DisplayMode   = DisplayModeText
                pl_0C1.ViewObject.Justification = JustificationText
                pl_0C1.ViewObject.TextColor     = (TextColorText_R, TextColorText_G, TextColorText_B)
                pl_0C1.ViewObject.FontSize      = FontSizeText
                pl_0C1.Label      = nameLabel + "_Rectangle_Ri_5Y_" + str(round(boundBoxLY,arondi))
                conteneurInfo.addObject(pl_0C1)
        
                pl_0C2 = Draft.makeText([str(round(boundBoxLZ,arondi))],point=FreeCAD.Vector(pl_5.Base.x, pl_5.Base.y, pl_5.Base.z + (boundBoxLZ/2)))
                pl_0C2.ViewObject.DisplayMode   = DisplayModeText
                pl_0C2.ViewObject.Justification = JustificationText
                pl_0C2.ViewObject.TextColor     = (TextColorText_R, TextColorText_G, TextColorText_B)
                pl_0C2.ViewObject.FontSize      = FontSizeText
                pl_0C2.Label      = nameLabel + "_Rectangle_Ri_5Z_" + str(round(boundBoxLZ,arondi))
                conteneurInfo.addObject(pl_0C2)
    
        except:
            App.Console.PrintError("not done 5"+"\n")
    
        #####
        App.ActiveDocument.recompute()
    except Exception:
        App.Console.PrintError("Bad selection"+"\n")
else:
    App.Console.PrintMessage("Select an object !"+"\n")


Version

Version: 0.11 le Date: 2019/05/29: "nameLabel = str(unicodedata.normalize('NFKD', nameLabel).encode('ascii','ignore'))" instead "def()"

ver 0.10 le 2019/05/23 upgrade > 0.19 and supp the "éçà.." with def() not encode()....

ver 0.9 le 2018-10-12: add test > 17

if int(FreeCAD.Version()[1]) > 17:      # Version de FreeCAD
    DisplayModeText   = str(u"2D text") # available : u"2D text" or u"3D text" 
else:
    DisplayModeText   = str(u"Screen")  # available : u"Screen" or u"World"

ver 0.8 le 05/10/2018: upgrade the ver 0.8 compatible with FC 0.17 (getGlobalPlacement)

ver 0.7 le 28/01/2018: correct error with label accent "nameLabel = unicodedata.normalize('NFKD', nameLabel).encode('ascii','ignore')"

ver 0.6 le 08/08/2017: add text info dimension , contener for rectangles, info rectangles, info volume, add section configuration color , label object selected

ver 0.5 le 08/05/2017 : upgrade now accept the "mesh" and "Points" thanks wmayer Makro Bounding-Box für STL importierte Teile und für Punktewolken

ver 0.4 le 04/06/2016 : test if value = 0 then not create boundbox (ex: object Draft)