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

@Clive,

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.

2 Likes

Got it,
Thanks a lot :slight_smile:

A little late to the party, however, it is possible to modify this script to work with multiple objects at the same time. Basically I do need to create one single rectangle around a bunch of geometries, that rectangle represents the material from which the objects will be cutted of.

A workaround would be to use the regular BoundingBox command, then DupFaceBorder the top or bottom face and then delete the box.

Ok, and how to put al this steps in a macro or script? The resulting rectangle I need to be on the world XY plane.

Here is a quick one…

AddWBBRectangle.py (692 Bytes)

1 Like

Good. Works well.
If I am not bothering you to much, it is possible also to add a 5mm exterior offset of the resulting curve? I do need to leave some tolerance for cutting the parts.

Best regards.

AddWBBRectangle2.py (1.5 KB)

This one will ask you to enter an offset value. Can be positive (outside) or negative (inside). Last used value is remembered (in the same session) for next use.

1 Like

Thank you. Works well.