How to get a RhinoObject from GUID ? (C#)

Guid ObjId = doc.Objects.AddBrep(breps[0]);

I add a breps[0].
and, how to get RhinoObject and ObjRef ? :sob:

You can search the RhinoCommon SDK documentation here. Please do this before asking a question.

http://4.rhino3d.com/5/rhinocommon/

A quick search will give you the constructor of ObjRef which accepts a Guid.
http://4.rhino3d.com/5/rhinocommon/html/M_Rhino_DocObjects_ObjRef__ctor_2.htm

Thanks, menno.
I know a ObjRef class.
Originally, I write it like below, but it is wrong.

Rhino.DocObjects.ObjRef aaa(ObjId);

But, it need to alter like this.

Rhino.DocObjects.ObjRef aaa = new Rhino.DocObjects.ObjRef(ObjId);

I need learn more knowledge of C#. :sweat_smile:

2 Likes

We could start var wars, but you could also do this:

var aaa = new Rhino.DocObjects.ObjRef(ObjId);

Being that C# is a strongly typed language, many people do not like this style. I tend to write like this when it is very clear what the variable will be. In this case, we know that we are going to construct an ObjRef from the right side, so I feel it becomes redundant to have it on the left.

Its reasonable to do this (too):

var obj = doc.Objects.Find(guid);
if (null != obj)
{
   // todo...     
}
3 Likes

:smile: I got it. thanks!