Get Object counts in Python Scripts

Is there a way to get the number of currently selected items into a python variable?

Also

Is there a way to get the number of items selected by rs.ObjectsByLayer() (not counting items that were already selected)

count=len(rs.SelectedObjects())
count=len(rs.ObjectsByLayer(layer_name))

Note, this will include all objects on a layer including those that are locked or hidden. If you want only ‘selectable’ objects on a layer then you would have this:

layer_sel=[obj for obj in rs.ObjectsByLayer(layer_name) if rs.IsObjectSelectable(obj)]
count=len(layer_sel)
1 Like

@Helvetosaur Thank You