Bounding Box

Hello!

i’ve got a problem on a python script…
i have a lot of steel frame, in a doc, and i want to list them with a python script,
so my script take all metal tube, and make a bounding box around to give the lenght, and the section, but i’ve got a difference i think it’s the tolerance, but i don’t know where…

# coding: utf-8
import rhinoscriptsyntax as rs

def Orientation_Plane(Tube):
    ArrSurf=rs.ExplodePolysurfaces(Tube)
    Area=0
    for Surf in ArrSurf:
        AreaSurf=rs.SurfaceArea(Surf)
        if AreaSurf[0]>Area:
            BigSurf=Surf
            Area=AreaSurf[0]
    ArrEdge=rs.DuplicateEdgeCurves(BigSurf, select=False)
    Lg=0
    for Edge in ArrEdge:
        LgEdge=rs.CurveLength(Edge)
        if LgEdge>Lg:
            BigEdge=Edge
            Lg=LgEdge
    UDom=rs.SurfaceDomain(BigSurf,0)
    VDom=rs.SurfaceDomain(BigSurf,1)
    NormSurf=rs.SurfaceNormal(BigSurf,((UDom[1]-UDom[0])/2,(VDom[1]-VDom[0])/2))
    Origine=rs.CurveStartPoint(BigEdge)
    XVect=rs.CurveEndPoint(BigEdge)-rs.CurveStartPoint(BigEdge)
    Plane=rs.PlaneFromNormal(Origine,NormSurf,XVect)
    #rs.AddPlaneSurface(Plane, 500,500)
    rs.DeleteObjects(ArrEdge)
    rs.DeleteObjects(ArrSurf)
    BBox=rs.BoundingBox(Tube,Plane)
    rs.AddBox(BBox)
    print 'longueur', int(Lg)
    print 'Section', int(rs.Distance(BBox[3],BBox[0])),'x',int(rs.Distance(BBox[4],BBox[0]))
    


ArrTube=rs.GetObjects("selectionne l'ensemble des tubes")
PrefixTube=rs.GetString("une lettre de nommage?")
for Tube in ArrTube:
    Orientation_Plane(Tube)

it’s for square tube, i draw 70 x 70 square with 2000 lenght, and some times it’s returns 2000 x 70 x 69…

maybe you will see where is the matter…

Hi,

Python int() does not round up or down but only down so 69.9999 will become 69

the fix is to replace

print 'Section', int(rs.Distance(BBox[3],BBox[0])),'x',int(rs.Distance(BBox[4],BBox[0]))

with

print 'Section', int(round(rs.Distance(BBox[3],BBox[0]))),'x',int(round(rs.Distance(BBox[4],BBox[0])))

Does that make sense?
-Willem

ok, but can we only write round:

print 'Section', round(rs.Distance(BBox[3],BBox[0])),'x',round(rs.Distance(BBox[4],BBox[0]))

Yes that is possible yet it will print 70.0 x 70.0 and not 70 x 70

-Willem