Delete box Geometry C#

Hello,

This is very very basic question in Rhinocommon C# .

I have been trying to find how to delete geometry box, but I could not.
Could anyone please let me know how to do that.

public Box box;

Rhino.Input.RhinoGet.GetBox(out box);
if(box.isValid == true)
{
    //Something to do here
}

//Then, I want to delete the box
}

Thank you

Kato

Hi @f.kato,
Just after successfully getting the Box, you could use RhinoDoc.ActiveDoc.Objects.MostRecentObject(), which would be the box you just added, and then delete it using RhinoDoc.ActiveDoc.Objects.Delete()

1 Like

Hi Darryl,

Thank you for your help.

I tried the way but the geometry box was not recognized by MostRecentObject().
VS2017 said it returned null.
I guess the geometry box is not on Rhinodoc because of not being instanced.

Do you know how to set geometry object on Rhinodoc?

I need the box remains invisible, so I do not use the line of
doc.Objects.AddBox(box).

Thank you

Kato

Box is a Rhino.Geometry type. Unless you add it to the document using “doc.Objects.AddBox(box)”, it is not added to the document, so basically there is nothing to delete from the document.

If you want it in the document, then you can add it to the document, and to keep it invisible, you can use doc.Objects.Hide(). And then later delete it from the document.

        Box box;
        Rhino.Input.RhinoGet.GetBox(out box);
        Guid addedBoxId = Guid.Empty;
        if (box.IsValid)
        {
            addedBoxId= doc.Objects.AddBox(box);

            doc.Objects.Hide(addedBoxId, true);

            //Do something here.                
        }

        if (addedBoxId != Guid.Empty)
            doc.Objects.Delete(addedBoxId, true);

Thank you Darryl!
Now I understand geometry box needs to be doc.object for being deleted.

Have a good one!

Kato