# Bounding Rectangle instead of Bounding Box?

Hi Everyone
I am wondering if there is any trick to have a bounding rectangle instead of a box when applying `CageEdit` over an object.

Hi Clive,

Iâ€™m not sure what you mean by trick. If this is a usability issue, please move the topic to either the Rhino for Windows or Rhino for Mac category.

â€“ Dale

Hi Dale,
My apologies for the confusion,
I am certainly looking for an algorithm in RhinoScript to provide a Bounding 2D CageEdit for Objects rather than â€śBounding Boxâ€ť

Hi Clive,

The CageEdit command does has an option for creating a `Rectangle` control object. Or am I confused?

â€“ Dale

It does have the option you mentioned,
But it wont let you make a â€śbounding Frameâ€ť just like a â€śbounding Boxâ€ť whereas it asks for either 3Points, Vertical frame or the Center of the frame.

Hi Clive,

Use RhinoScriptâ€™s `BoundingBox` method to calculate the bounding box of the object. Then use the points returned by the method as input when scripting the Rectangle option of CageEdit.

â€“ Dale

Hi again Dale
Thanks
following what you suggested, the goal is to take the highlighted control points in the image,

I did the code below:

``````Option Explicit

Call Main()
Sub Main()
Dim strObject,arrObjects,arrGrips,intCount,i

strObject = Rhino.GetObject("Pick an Object")
Rhino.SelectObject strObject
Rhino.Command("CageEdit _Boundingbox _World _X=2 _Y=2 _Z=3 _Enter _Global _Enter")
arrObjects = Rhino.LastCreatedObjects
If Not IsNull(arrObjects) Then

Rhino.EnableObjectGrips arrObjects(0)
intCount = Rhino.ObjectGripCount(arrObjects(0))
For i = 1 To intCount Step 3
Rhino.SelectObjectGrip arrObjects(0), i
Next
arrGrips = Rhino.SelectedObjectGrips(arrObjects(0))

If IsArray(arrGrips) Then

Rhino.Print CStr(UBound(arrGrips)) +1 & " grips selected."
End If
End If

End Sub
``````

So The following control points get selected: (as long as Z=3 in `CageEdit`)

Would you please walk me through

1. how to extract the selected control points Coordinates (`Rhino.Pt2Str` did not work)
2. how to take the same control points if X and Y in `CageEdit` equal anything other than 2
Thanks

below might help to get the 4 points. To pick the rectangle in `_CageEdit` via a script, you only need two of them:

``````Option Explicit

Call Main()
Sub Main()

Dim strObject, strView, arrBBox, arrPoints(3)

strObject = Rhino.GetObject("Curve to CageEdit", 4, True, False)
If IsNull(strObject) Then Exit Sub

strView = Rhino.CurrentView()
arrBBox = Rhino.BoundingBox(strObject, strView, True)
If Not IsArray(arrBBox) Then Exit Sub

arrPoints(0) = MidPt(arrBBox(0), arrBBox(4))
arrPoints(1) = MidPt(arrBBox(1), arrBBox(5))
arrPoints(2) = MidPt(arrBBox(2), arrBBox(6))
arrPoints(3) = MidPt(arrBBox(3), arrBBox(7))

End Sub

Private Function MidPt (ByRef v1, ByRef v2)
MidPt = Array((v1(0) + v2(0)) / 2, (v1(1) + v2(1)) / 2, (v1(2) + v2(2)) / 2)
End Function
``````

c.

1 Like

Thanks,
But Since `CageEdit` is run via `Rhino.Command` I think I can not use `Rhino.Pt2str` to insert the coordinates into the command like:

``````strObject = Rhino.GetObject("Select captive Object(s)", 4, True, False)
arrPoints(0) = MidPt(arrBBox(0), arrBBox(4))
arrPoints(2) = MidPt(arrBBox(2), arrBBox(6))

strPt0 = Rhino.Pt2Str(arrPoints(0))
strPt2 = Rhino.Pt2Str(arrPoints(2))

Rhino.SelectObject strObject
Rhino.Command("CageEdit _Rectangle strPt0 strPt2 Enter Global")``````

@Clive, you almost got it. Try below with a planar curve or any other object:

``````Option Explicit

Call Main()
Sub Main()

Dim strObject, strView, arrBBox, arrPoints(3)
Dim strCmd, strPtA, strPtB

strObject = Rhino.GetObject("Object to CageEdit", 4 + 8 + 16 + 32, True, True)
If IsNull(strObject) Then Exit Sub

strView = Rhino.CurrentView()
arrBBox = Rhino.BoundingBox(strObject, strView, True)
If Not IsArray(arrBBox) Then Exit Sub

strPtA = Rhino.Pt2Str(MidPt(arrBBox(0), arrBBox(4)))
strPtB = Rhino.Pt2Str(MidPt(arrBBox(2), arrBBox(6)))

strCmd = "_CageEdit _Rectangle " & strPtA & " " & strPtB & " "
strCmd = strCmd + "_UDegree=1 _VDegree=1 _UPointCount=2 _VPointCount=2 "
strCmd = strCmd + "_Global _Enter _Enter"

Rhino.Command strCmd, False

End Sub

Private Function MidPt (ByRef v1, ByRef v2)
MidPt = Array((v1(0) + v2(0)) / 2, (v1(1) + v2(1)) / 2, (v1(2) + v2(2)) / 2)
End Function
``````

c.

1 Like

Got it,
Thanks a lot