Object model reference

I’m struggling mightily in trying to understand how to manipulate Rhino entities like curves, points, surfaces, etc.

Is there a reference that explains how to get an object reference to one of these (or others) in order to work with them?

I hate to keep posting questions here, if there is a readily available answer in some documentation.

I’m afraid the samples are of minimal help, since they seldom apply to precisely what I’m trying to accomplish.

Are you saying that none of these tell you anything useful? Rhino - Samples and more general https://developer.rhino3d.com/

There are many samples that start with getting object references and from those say curves, then apply some sort of modification or transform to them. For instance Rhino - Divide Curve by Segments to get division points, Rhino - Reparameterize Curves to reparametrize curve and replace original with new, etc.

I’m sure they don’t do exactly what you need, but you should be able to learn the concepts from them.

Actually, I’m not saying there’s nothing of value in the samples, but I have, several times, started to glean how to do something and found that the examples don’t quite get me there.

If I understood the object model, I’d probably find the samples much more useful.

Example:

There’s a sample that examines how to rename an object, but it’s based on the user having to pick an object and the code goes:

         ObjRef obj_ref;
         var rc = RhinoGet.GetOneObject("Select object to change name", true, ObjectType.AnyObject, out obj_ref);
              rhino_object.Attributes.Name = new_object_name;
  rhino_object.CommitChanges();

In at least one case, I have an object that was added in code and I need to add a name property, before moving on to the next object:
for (i = 0; i < MaxPts; i++)
{
double x = 1;
double y = 0;
double z = 0;
Rhino.Geometry.Point3d StaPt = new Rhino.Geometry.Point3d(x, y, z);
doc.Objects.AddPoint(StaPt);
string NewName = “”;
Rhino.Input.RhinoGet.GetString(“Name of Point:”, false, ref NewName);
//some code to apply NewName to the point object
}

The problem is that my code returns a Point3d object and I don’t know how to get from that, an ObjRef to which I can apply the name attribute. In the sample code, the ObjRef comes from the user having picked the object.

With an understanding of the relationship between my StaPt and the ObjRef, I’d be able to apply the sample code to an object that wasn’t picked.

This is just an example of what I am up against in trying to apply the samples.

A thing to kind of understand–I think, ha I’m just starting to get the hang of it–is that all these different object types are largely just different ways of looking at the same geometry to suit…I dunno, the level of granularity you’re looking for, maybe? Anyway, you can be fairly sure there’s a function in the type of object you’ve got to “cast” it to the type of object you want, that you can see in the documentation.

I think more specifically to your question, which has virtually nothing to do with what I just said, is that to get a handle on the actual “rhino object” of that point, you needed to capture the return of the doc.Objects.AddPoint() function, which is the GUID from which you can get the actual “object” you can add a name to. The “point3D” by itself is just a math thing that’s not actually part of the Rhino model at all.

Thx, Jim.

As you can probaby tell, I’m very new to this, which prompted my original post about wanting to understand the object model in order to avoid having to make these posts, unnecessarily.

I understand there’s a difference between a Point3d an an ObjRef, assumedly that points to the Point3d object. As far as I can tell the doc.Objects.AddPoint() method returns a Point3d, which is not what I need in order to rename it.

In the sample code illustrating the process of renaming an object, the user is prompted to select the object to be renamed and the method used does return an objref. When my plugin is creating these points in a for next loop, it’s not very elegant for the plugin to create the point and then expect the user to then select that point.

The code that I originally posted is just an example of the type of difficulty I’m running into. I have several others.

What’s missing is the mechanism to get from the object created (Point3d, in this case) to the objref.

I’m hoping someone will chime in with a link to documenting the object model.

https://developer.rhino3d.com/api/rhinoscript/geometry_methods/addpoint.htm

here you can observe the function itself and you’ll see that it actually adds a point to the document, but returns the identifier string. With that string you’ll be able to adress the added point in the document.
In your exmaple code the string containing the GUID is just not assigned, but either way the point is added to the document.

Honestly, noone will be mad at you asking questions in a forum.

So you added your point to the document, but as you can see in the docs at ObjectTable.AddPoint Method (Point3d) AddPoint returns the GUID for the “Rhino object” that’s actually been added to the document, which is NOT your original Point3D, it’s been copied. The GUID is what you need to get. The original point you made is just a basic geometry object with no attributes like a name, it’s NOT what it refers to.

Then on the page for the ObjRef constructors, ObjRef Constructor you can see how to get the object reference from that GUID.

The solution was pretty simple:

        // the first and last points were picked and the number of 
        // points was entered.  spcg is the distance between them

        double y = 0;
        double = 0;
        string NewName = "";
        ObjectAttributes objAtt = new ObjectAttributes();

        for (int i = 0; i < stas-1; i++) //iterate through the number of stas 
        {
            //Only change the x coordinate from one pt to the next
            x = x + spcg;
            Rhino.Geometry.Point3d StaPt = new Rhino.Geometry.Point3d(x, y, z);
            Rhino.Input.RhinoGet.GetString("Name of Point:", false, ref NewName);
            objAtt.Name = NewName;
            doc.Objects.AddPoint(StaPt, objAtt);
        }

But, again, the original post was looking for how to learn about the object model. The sample codes, for the most part, don’t create the objects, but depend on the user to pick them. Getting from the object created by the code to the object reference that can be manipulated is the part that is eluding me.

I believe your last comment is exactly what I was looking for. Todays goal: dig into those constructors and see if I can wrap my head around the matter.

Thx again.

I’ll say it again, the add point function has A RETURN VALUE that you’re ignoring. It returns the guid that is your gateway to everything. See the link I sent above.

Hi All,

I would say i am confused as well. Should there not a simple function to return the objref of an object?

eg selobject.ID or selobject.ref

eg my issue is getting the return points of rs.BoundingBox(obj) as objrefs so i can convert to the layoutspace scale for automatic dimensioning detail views.

If this has a good example would love to see.
test_dimlinear_detail.py (5.3 KB)