How to get the scene hierarchy of all the objects?

Hi all!
So, I am using the c++ Rhino API, and am making a plugin for Rhino so that the rhino model (3dm) can be converted into another format. For that, I need the hierarchy of the scene, all the parent-child relations and the object details. How do I get that? I have been through the docs but have not found any suitable methods for doing so. Please do let me know what should I do or if there’s something on the docs that I missed. Thank you!

since you said in your pm, examples in other programming languages would also help and the fact that i don’t speak cpp i can give you the rhinocommon way (works in python and c#):

the first part is getting access to the active document, which stores, among many other things, all objects.
in python it is under ‘scriptcontext.doc.ActiveDoc’ and in c# its ‘Rhino.RhinoDoc.ActiveDoc’,
there will be something similar in cpp.

The document gives access to the object table, all objects in the document are stored here and they are of type ‘RhinoObject’ (see : ObjectTable and RhinoObject Class)

RhinoObject has a property ‘Attributes’ and in attributes there should be all the information you search for (see ObjectAttributes)

for object in sc.doc.Objects:
    attributes = object.Object().Attributes
    # material Index
    print attributes.MaterialIndex
    # object color
    print attributes.ObjectColor
    # is part of an instance definition
    print attributes.IsInstanceDefinitionObject	

I don’t know how much help this is for a cpp plugin.

Also on another node, what is a scene hierarchy and with parent-chuld relation do you mean Rhinos history?

1 Like

Hi @alexian007,

Can I assume you are creating a file export plug-in? If so, then your plug-in class will be derived from CRhinoFileExportPlugIn. And if you’ve used the Rhino plug-in wizard in Visual Studio to generate your project, your Rhino plug-in class will have overridden CRhinoFileExportPlugIn:: WriteFile. This member is called by Rhino when the user choosed your file type to save or export. This member is passed a reference to the current document, CRhinoDoc, which holds all thing pertaining to a Rhino document.

Does this help?

– Dale

1 Like

Hello @lando.schumpich , thank you so much! This does help a lot. I had been looking for a clear answer like yours ! It is a lot of help for a C++ plugin.
And regarding the scene hierarchy and parent-child relation, I was looking at a plugin for Maya that used the Asset Importer (assimp) library. In that plugin, the structure of a 3d file was represented with nodes and the children nodes. And, I assumed that in Rhino, this was the same case too. And scene is what the document is in Rhino.
But, thank you so much for your answer. I do appreciate you taking your time and helping me out. :slight_smile:

Hello @dale,
Thank you for your helpful reply. Yes, your answer does help. I am creating a file export plugin, and the first thing I needed to know what is a “scene” in Rhino. (Scene is a term used to denote the entire work and the contents in some 3D modeling softwares and Unity Game Engine, thus its a “document” here in Rhino.)
Thank you again!