BBox on planar Object

Hi all,

I need to create a BBox on any Objects, i use boundingbox and AddBox, that’s work on 3D Objects ( curves/Surfaces/polysurfaces) , but if my object is planar (2D) i can’t , the Rhino.BoundingBox() return 8 ¨points, but AddBox fail , i think because 4 points are at the same exact place.

In Rhino boundingBox command, we can choose 2D cuves as output , but i don’t find same possibility in rhinoscript.

Is there a way to use Addbox ( or something similar) on planar objects ?

Thx !

Call Main()
Sub Main()
Dim strObject, arrBox, sfrBox

strObject = Rhino.GetObject("Select object",, True, True)
arrBox = Rhino.BoundingBox(strObject)
sfrBox = Rhino.AddBox(arrBox)

End Sub

Hi @Cyver
You can check for duplicate points in your arrBox and see if there are 4 unique points - that will be the case for planar 2D objects. See the sample code below:

Dim idObject : idObject = Rhino.GetObject()
Dim arrBbox : arrBbox = Rhino.BoundingBox(idObject)
Dim arrCulled : arrCulled = Rhino.CullDuplicatePoints(arrBbox)

'checking if 4 unique points were left after culling duplicates
If Ubound(arrCulled) = 3 Then
	'getting planar-object-plane aligned bounding box for correct sorting of not-in-Cplane planar objects
	'otherwise the polyline points may not be connected in the right order
	Dim arrPlane : arrPlane = Rhino.PlaneFitFromPoints(arrCulled)
	arrBbox = Rhino.BoundingBox(idObject, arrPlane)
	arrCulled = Rhino.CullDuplicatePoints(arrBbox)
	Dim idBoundingRectangle
	idBoundingRectangle = Rhino.AddPolyline(Rhino.JoinArrays(arrCulled, array(arrCulled(0))))
End If
1 Like

Example with AddPolyline:

Option Explicit

Call bb2d()

Sub bb2d()

Dim strObjects, arrBox, arrRectP(4), i
strObjects = Rhino.GetObjects("Select objects")
If Not IsNull(strObjects) Then
    arrBox = Rhino.BoundingBox(strObjects)
    If IsArray(arrBox) Then

        For i = 0  To 3

            arrRectP(i) = arrBox(i)

        arrRectP(4) = arrBox(0)
        Rhino.AddPolyline arrRectP
    End If
End If

End Sub

1 Like

Jarek/Eddi , Thank you both for help and solutions