How to work in session with rhinocommon

Hi,
I’m trying to figure out how to work with sessions and RhinoCommon (RH6), but I haven’t found documentation on this subject. For example:

  • How do you know if you are in a worksession or just working with a rhino file?
  • How do you list the other files referenced in the work sessions?
  • In a work session, how do you know if a layer or an object belong to your active file or if it is just another external reference?

Is there any doc available out there?

Best regards
Matthieu

@dale, can you help?

Hi @Matthieu_from_NAVINN,

You’ll want to start with this:

https://developer.rhino3d.com/api/RhinoCommon/html/P_Rhino_RhinoDoc_Worksession.htm

Objects from worksession files will have the IsReference property return true.

– Dale

Thanks @dale.
Then from an object I should test IsReference, and try to find the model it belongs to.

I think a must have would be a Layer.ReferenceIndex and RhinoObject.ReferenceIndex properties in relation to worksession.ModelPaths

I’m just researching this for a future project, so I’m not in a hurry. If needed I know that I can read the start of the layer path when it is a reference.

Best Regards

For objecrts, use RhinoObject.WorksessionReferenceSerialNumber.

– Dale

Thanks @dale ,
It should be fine with this, and I’ve also found your code sample on github.
Regards
Matthieu

Hi @dale,
I’m still a bit lost with these worksessions:
There is doc.Worksession.ModelPaths() that gives me a list of documents, but how do I know which doc a layer belongs to?

You suggested to use RhinoObject.WorksessionReferenceSerialNumber to get a model’s a serial number, but doc.worksession does not have any serial number list to match this. As for layers there is only Layer.IsReference which is of limited use in my case.

I think your Rhino.Extra api might be the solution but I don’t see where it can be downloaded

Best regards

Hi @Matthieu_from_NAVINN,

Yeah, looks like we still have some work to do.

https://mcneel.myjetbrains.com/youtrack/issue/RH-49391

– Dale