Macro BoundingBox Tracing/cs: Difference between revisions

From FreeCAD Documentation
(Updating to match new version of source page)
(Updating to match new version of source page)
Line 1: Line 1:
{{Macro/cs|Icon=Text-x-python|Name=Macro BoundingBox Tracing|Name/cs=Macro BoundingBox Tracing|Description=This macro red trace (editable) around the BoundingBox with 6 rectangles.|Author=Mario52}}
{{Macro|Icon=BoundBoxTracing|Name=Macro BoundingBox Tracing|Description=This macro red trace (editable) around the BoundingBox with 6 rectangles.|Author=Mario52}}


==Description==
==Description==
Line 10: Line 10:
Select the object and launch the macro. 6 rectangles are colored red (can be changed)
Select the object and launch the macro. 6 rectangles are colored red (can be changed)


If '''createVol''' = 1 (Line 27) one volume is created
To change the color of the dot change the lines 42, 43, 44

To change the color of the dot change the lines 35, 36, 37


<syntaxhighlight>
<syntaxhighlight>
Line 31: Line 33:
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# 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
# this macro red trace (editable) around the BoundingBox with 6 rectangles
# this macro red trace (editable) around the BoundingBox with 6 rectangles
# if "createVol" = 1 on volume (red) is created
# To change the color of the dot change the lines 42, 43, 44
# red = 1.0 # 1 = 255
# green = 0.0 #
# blue = 0.0 #
# Macro_BoundingBox_Tracing
# Macro_BoundingBox_Tracing
# ver 0.2
# Mario52
#
#
#OS: Windows Vista
#OS: Windows Vista #OS: Windows 8.1
#Platform: 32-bit
#Platform: 32-bit #Word size of OS: 64-bit
#Version: 0.14.3389
#Version: 0.14.3389 #Word size of FreeCAD: 64-bit
#Python version: 2.6.2
#Python version: 2.6.2 #Version: 0.15.4671 (Git)
#Qt version: 4.5.2
#Qt version: 4.5.2 #Branch: releases/FreeCAD-0-15
#Coin version: 3.1.0
#Coin version: 3.1.0 #Hash: 244b3aef360841646cbfe80a1b225c8b39c8380c
#SoQt version: 1.4.1
#SoQt version: 1.4.1 #Python version: 2.7.8
#OCC version: 6.5.1
#OCC version: 6.5.1 #Qt version: 4.8.6
# #Coin version: 4.0.0a
# #OCC version: 6.8.0.oce-0.17

__title__ = "BoundingBox_Tracing"
__author__ = "Mario52"
__url__ = "http://www.freecadweb.org/index-fr.html"
__version__ = "0.3"
__date__ = "14/07/2015"


import FreeCAD, FreeCADGui, Draft, Part
import FreeCAD, FreeCADGui, Draft, Part

createVol = 0 # give 1 for create Volume # mettre a 1 pour creer un volume


selEx = FreeCADGui.Selection.getSelectionEx()
selEx = FreeCADGui.Selection.getSelectionEx()
Line 55: Line 63:
if len(objs) >= 1:
if len(objs) >= 1:
s = objs[0].Shape
s = objs[0].Shape

# LineColor
red = 1.0 # 1 = 255
green = 0.0 #
blue = 0.0 #


# boundBox
# boundBox
Line 70: Line 83:


App.Console.PrintMessage(str(boundBox_)+"\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")
App.Console.PrintMessage("Rectangle : "+str(boundBox_.XLength)+" x "+str(boundBox_.YLength)+" x "+str(boundBox_.ZLength)+"\r\n")
App.Console.PrintMessage("_____________________"+"\r\n")


if createVol == 1: # Create Volume
# LineColor
BDvol = App.ActiveDocument.addObject("Part::Box","BoundBoxVolume")
red = 1.0 # 1 = 255
#BDvol.Label = "BoundBoxVolume"
green = 0.0 #
blue = 0.0 #
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)
App.Console.PrintMessage("BoundBoxVolume : " + str(BDvol.Shape.Volume)+"\r\n")

App.Console.PrintMessage("_____________________"+"\r\n")


#####
#####
Line 82: Line 103:
pl_0 = App.Placement(App.Vector(oripl_X,oripl_Y,oripl_Z), App.Rotation(0.0,0.0,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=boundBox_.XLength,height=boundBox_.YLength,placement=pl_0,face=False,support=None) #OK
double = Draft.makeRectangle(length=boundBox_.XLength,height=boundBox_.YLength,placement=pl_0,face=False,support=None) #OK
double.Label = "BoundBoxRectangle_Bo"
FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
except:
except:
Line 88: Line 110:
pl_1 = App.Placement(App.Vector(oripl_X,oripl_Y,oripl_Z+boundBoxLZ), App.Rotation(0.0,0.0,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=boundBox_.XLength,height=boundBox_.YLength,placement=pl_1,face=False,support=None) #Ok
double = Draft.makeRectangle(length=boundBox_.XLength,height=boundBox_.YLength,placement=pl_1,face=False,support=None) #Ok
double.Label = "BoundBoxRectangle_To"
FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
except:
except:
Line 94: Line 117:
pl_2 = App.Placement(App.Vector(oripl_X,oripl_Y,oripl_Z), App.Rotation(0.0,0.0,90))
pl_2 = App.Placement(App.Vector(oripl_X,oripl_Y,oripl_Z), App.Rotation(0.0,0.0,90))
double = Draft.makeRectangle(length=boundBox_.XLength,height=boundBox_.ZLength,placement=pl_2,face=False,support=None) #Ok
double = Draft.makeRectangle(length=boundBox_.XLength,height=boundBox_.ZLength,placement=pl_2,face=False,support=None) #Ok
double.Label = "BoundBoxRectangle_Fr"
FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
except:
except:
Line 100: Line 124:
pl_3 = App.Placement(App.Vector(oripl_X,oripl_Y+boundBoxLY,oripl_Z), App.Rotation(0.0,0.0,90))
pl_3 = App.Placement(App.Vector(oripl_X,oripl_Y+boundBoxLY,oripl_Z), App.Rotation(0.0,0.0,90))
double = Draft.makeRectangle(length=boundBox_.XLength,height=boundBox_.ZLength,placement=pl_3,face=False,support=None) #Ok
double = Draft.makeRectangle(length=boundBox_.XLength,height=boundBox_.ZLength,placement=pl_3,face=False,support=None) #Ok
double.Label = "BoundBoxRectangle_Re"
FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
except:
except:
Line 106: Line 131:
pl_4 = App.Placement(App.Vector(oripl_X,oripl_Y,oripl_Z), App.Rotation(90,0.0,90))
pl_4 = App.Placement(App.Vector(oripl_X,oripl_Y,oripl_Z), App.Rotation(90,0.0,90))
double = Draft.makeRectangle(length=boundBoxLY,height=boundBox_.ZLength,placement=pl_4,face=False,support=None) #Ok
double = Draft.makeRectangle(length=boundBoxLY,height=boundBox_.ZLength,placement=pl_4,face=False,support=None) #Ok
double.Label = "BoundBoxRectangle_Le"
FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
except:
except:
Line 112: Line 138:
pl_5 = App.Placement(App.Vector(oripl_X+boundBoxLX,oripl_Y,oripl_Z), App.Rotation(90,0.0,90))
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 = Draft.makeRectangle(length=boundBoxLY,height=boundBoxLZ,placement=pl_5,face=False,support=None) #Ok
double.Label = "BoundBoxRectangle_Ri"
FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
except:
except:
Line 122: Line 149:


</syntaxhighlight>
</syntaxhighlight>


<languages/>
<languages/>

Revision as of 22:06, 18 July 2015

File:BoundBoxTracing Macro BoundingBox Tracing

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

Author: Mario52
Author
Mario52
Download
None
Links
Macro Version
1.0
Date last modified
None
FreeCAD Version(s)
None
Default shortcut
None
See also
None

Description

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

CenterFace

Use

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

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

To change the color of the dot change the lines 35, 36, 37

    red   = 1.0  # 1 = 255
    green = 0.0  #
    blue  = 0.0  #

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 ..."

Button

Macro

Macro_BoundingBox_Tracing.FCMacro

# -*- coding: utf-8 -*-
# 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
#Platform: 32-bit        #Word size of OS: 64-bit
#Version: 0.14.3389      #Word size of FreeCAD: 64-bit
#Python version: 2.6.2   #Version: 0.15.4671 (Git)
#Qt version: 4.5.2       #Branch: releases/FreeCAD-0-15
#Coin version: 3.1.0     #Hash: 244b3aef360841646cbfe80a1b225c8b39c8380c
#SoQt version: 1.4.1     #Python version: 2.7.8
#OCC version: 6.5.1      #Qt version: 4.8.6
#                        #Coin version: 4.0.0a
#                        #OCC version: 6.8.0.oce-0.17

__title__   = "BoundingBox_Tracing"
__author__  = "Mario52"
__url__     = "http://www.freecadweb.org/index-fr.html"
__version__ = "0.3"
__date__    = "14/07/2015"

import FreeCAD, FreeCADGui, Draft, Part

createVol = 0            # give 1 for create Volume # mettre a 1 pour creer un volume

selEx = FreeCADGui.Selection.getSelectionEx()
objs = [selobj.Object for selobj in selEx]
if len(objs) >= 1:
    s = objs[0].Shape

    # 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

    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])

    App.Console.PrintMessage(str(boundBox_)+"\r\n")
    App.Console.PrintMessage("Rectangle      : "+str(boundBox_.XLength)+" x "+str(boundBox_.YLength)+" x "+str(boundBox_.ZLength)+"\r\n")

    if createVol == 1:  # Create Volume
        BDvol = App.ActiveDocument.addObject("Part::Box","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)
        App.Console.PrintMessage("BoundBoxVolume : " + str(BDvol.Shape.Volume)+"\r\n")

    App.Console.PrintMessage("_____________________"+"\r\n")

    #####
    try:
        pl_0 = App.Placement(App.Vector(oripl_X,oripl_Y,oripl_Z), App.Rotation(0.0,0.0,0.0))
        double = Draft.makeRectangle(length=boundBox_.XLength,height=boundBox_.YLength,placement=pl_0,face=False,support=None) #OK
        double.Label = "BoundBoxRectangle_Bo"
        FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
    except:
        App.Console.PrintError("not done 0"+"\n")
    try:
        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=boundBox_.XLength,height=boundBox_.YLength,placement=pl_1,face=False,support=None) #Ok
        double.Label = "BoundBoxRectangle_To"
        FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
    except:
        App.Console.PrintError("not done 1"+"\n")
    try:
        pl_2 = App.Placement(App.Vector(oripl_X,oripl_Y,oripl_Z), App.Rotation(0.0,0.0,90))
        double = Draft.makeRectangle(length=boundBox_.XLength,height=boundBox_.ZLength,placement=pl_2,face=False,support=None) #Ok
        double.Label = "BoundBoxRectangle_Fr"
        FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
    except:
        App.Console.PrintError("not done 2"+"\n")
    try:
        pl_3 = App.Placement(App.Vector(oripl_X,oripl_Y+boundBoxLY,oripl_Z), App.Rotation(0.0,0.0,90))
        double = Draft.makeRectangle(length=boundBox_.XLength,height=boundBox_.ZLength,placement=pl_3,face=False,support=None) #Ok
        double.Label = "BoundBoxRectangle_Re"
        FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
    except:
        App.Console.PrintError("not done 3"+"\n")
    try:
        pl_4 = App.Placement(App.Vector(oripl_X,oripl_Y,oripl_Z), App.Rotation(90,0.0,90))
        double = Draft.makeRectangle(length=boundBoxLY,height=boundBox_.ZLength,placement=pl_4,face=False,support=None) #Ok
        double.Label = "BoundBoxRectangle_Le"
        FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
    except:
        App.Console.PrintError("not done 4"+"\n")
    try:
        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 = "BoundBoxRectangle_Ri"
        FreeCADGui.activeDocument().activeObject().LineColor = (red, green, blue)
    except:
        App.Console.PrintError("not done 5"+"\n")
    #####
    App.ActiveDocument.recompute()
else:
    App.Console.PrintMessage("Select an object !"+"\n")