Get Objects by Layout (PageView)

Hi,
is there an easy way with RhinoCommon to get all objects which are on a certain layout page?
Thanks, Jess

1 Like

Hi Jess,
I’m thinking you need to look in the ObjectAttributes class for each object - there are for example the Space and ViewportId properties which might return a specific ID of a detail viewport to match… dunno, haven’t tried, myself… :wink:

–Mitch

2 Likes

Hi Mitch,

great, thanks! I knew about the Space attribute but I was missing the addition with the ViewportID.
This seems to work:

"""Returns identifiers of objects on a PageView by ID
Parameters:
  id: guid of the PageView
  include_lights (bool, optional): include light objects
Returns:
  list(guid, ...): identifiers for objects on PageViewId.
"""

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino


def ObjectsByPageView_id(id, include_lights=False, include_references=False):
    
    settings = Rhino.DocObjects.ObjectEnumeratorSettings()
    
    settings.HiddenObjects = True
    settings.DeletedObjects = False
    settings.IncludeGrips = False
    settings.IncludePhantoms = True
    settings.IncludeLights = include_lights
    settings.ReferenceObjects = include_references
    objects = sc.doc.Objects.GetObjectList(settings)
    
    ids = []
    for obj in objects:
        objRef=sc.doc.Objects.Find(obj.Id)
        attr = objRef.Attributes
        if attr.ViewportId == id:
            ids.append(obj.Id)
    
    if ids:
        return ids
        
#--------------------------------------------------------------

if __name__=="__main__":
    
    page_views = sc.doc.Views.GetPageViews()
    if page_views:
        page_view_ids = []
        for page_view in page_views:
            page_view_ids.append(str(page_view.ActiveViewportID))
            
        page_view_id = rs.ListBox(page_view_ids,"Select Objects on Layout_ID","Objects by Layout")
        
        if page_view_id:
            objs = ObjectsByPageView_id(rs.coerceguid(page_view_id))
            print objs