Bindingbox for named object

How can I find the bindingbox to a named Object in C#.
I have seen a sample using ObjRef and RhinoGet, but in my case the Object should be selected by name.
Thank you!

using System.Linq;

GetString gs = new GetString();
GetResult gr = gs.GetLiteralString();
if (gs.CommandResult() != Result.Success || gr != GetResult.String)
    return gs.CommandResult();

String name = gs.StringResult();

foreach (var obj in doc.Objects.Where(o => o.Name == name))
    BoundingBox bb = obj.Geometry.GetBoundingBox(true);

Check also Rhino.DocObjects.ObjectEnumeratorSettings.NameFilter see rhinocommon Rhino.DocObjects.ObjectEnumeratorSettings.NameFilter
The link provides a sample how to find objects by name ( and other filters).

(if it s possible change the Bindingbox to Boundingbox in your header / title )




Good one! This is probably faster, but slightly more complicated. In case there are many objects in the document, performance can be hampered using LINQ from .NET, because each object needs to be marshalled to .NET, whereas the ObjectEnumeratorSettings (probably?) does the filtering in the native C++ code, thereby preventing having to marshal all objects to .NET.

Thank you!
Menno’s solution works fine for me!