Browse through objects in current document

using RhinoCommon, I’m looking for a way to “browse” through the objects in the current open document. Suppose I draw 3 objects in the same document: one cone, one sphere and one pyramid.
I need to be able to say: “There are 3 objects in the working area: one cone, one sphere and one pyramid”.

Is there a way to achieve this? Can anyone please give me a hint to which method or class could be helpful?

Thank you

Hi @mcollareda,

You can iterate over all objects of a document using the Objects Property on the the ObjectTable class:

import scriptcontext as sc

for obj in sc.doc.Objects:
    # do stuff

Determining the number of objects for a given geometric property can be quite more challenging. I guess it really depends on what kind of objects/features you are trying to find.
For geometric primitives you can use the primitive checks for BrepFaces

import scriptcontext as sc
import Rhino

for obj in sc.doc.Objects:
    if obj.ObjectType == Rhino.DocObjects.ObjectType.Brep:
        for face in obj.Geometry.Faces:
            if face.IsCylinder():
                print "cylinder"
            if face.IsSphere():
                print "sphere"
            if face.IsTorus():
                print "torus"
            if face.IsCone():
                print "cone"

See the Surface methods for reference:

This won’t help you finding pyramids for example, you will have to define your own algorithm for finding those. Also there can be a lot of objects in a rhino document which are not surfaces or polysurfaces, so i guess you will have to define a pretty extensive list on what objects you care about.

Thank you very much for your help, Lando.
Do you know, or does anyone know, if it’s possibile to save these 3 objects each one as a single 3dm file? Each file containing one object?

Something like

for obj in sc.doc.Objects:

Thank you