Finding an object within 75 Layouts (needle in haystack)

I have a Layer I want to delete but it’s telling me there’s one object on that Layer, do I want to delete it.

I don’t know what that object is, so I want to find it, but it’s not in model space so it can only be in one of my 75 Layouts. But I don’t really have the inclination to go through each Layout to find it!

Is there any way to locate it?

It would be great if Rhino could tell me where it is. Maybe when I try and delete the Layer Rhino could tell me what Layout/s the object/s are on?

I remember the days when I had to work with someone else’s files as a background. I can see why this is would be a pain.

I couldn’t find a built in way to ‘zoom to’ the layout (it probably exists?), but this trashy script may help reduce the haystack:

import Rhino as R
import rhinoscriptsyntax as rs
import scriptcontext as sc

layer_name = rs.GetLayer()

guids = rs.ObjectsByLayer(layer_name)

if guids:
    viewport_names = []
    for guid in guids:
            doc_obj = rs.coercerhinoobject(guid)
            vp_id = doc_obj.Attributes.ViewportId
            vp = sc.doc.Views.Find(vp_id)
            if vp:
                name = vp.ActiveViewport.Name
                if name not in viewport_names:
        except Exception as exp:
    if viewport_names:
        print('objects on layer "{}" can be found on the following layouts:'.format(layer_name))
        for vpn in sorted(viewport_names):

It should print out all layouts that objects on a layer use. It will only help for layers that have objects on a few layouts, but it sounds like that is your situation.

1 Like

Thanks Nathan!

That worked perfectly. Bravo!

Glad it worked.