Assign Attributes to ON_NurbsSurface


#1

I want to assign a Name to a new surface I create using a SurfaceInterpolation function I wrote. I create more than one surface so I store the new surfaces in a ON_SurfaceArray. Later on in the program I loop through those surfaces and Append them to the model.

I don’t see any way to assign a name to an ON_NurbsSurface directly. It looks like I have to assign the new surface to an object and then assign a name to it, such as:
ON_NurbsSurface* new_srf = new ON_NurbsSurface;
SurfaceInterpolation(parameters); ONX_Model_Object* obj = new ONX_Model_Object();
obj->m_object = new_srf;
obj->m_attributes.m_name = “Top Surface”;

Is that correct? If this is correct that means I can’t store my newly created surfaces in a ON_SurfaceArray to loop through later and append to model because now they are objects.

How would you suggest I do this? I guess I could create an array of objects and loop through later array but I don’t see an ON_ObjectArray class.

Help would be appreciated.

Best Regards,
Steve


(Menno Deij - van Rijswijk) #2

I suppose you could use

new_srf->SetUserString("NAME", "Top Surface");

when you create it and

ON_wString name;
if (srf->GetUserString("NAME", &name))
    obj->m_attributes.m_name = name;

when you add the surface to the document.

Disclaimer: There may be some errors here, but I hope you get the idea. I normally don’t use C++ for writing Rhino code.


(Steve Baer) #3

You could create a class

public class CNamedSurface
{
public:
  ON_NurbsSurface* m_pSurface;
  ON_wString m_name;
};

and then just create an ON_SimpleArray<CNamedSurface*>
for holding onto these objects for later use.


#4

Steve,
I think menno’s response is close to what I want to do, but I like your idea of creating a class. I want to assign a name to the new surfaces, so when I open Rhino the surface name appears in the Properties window under “Name”. Based on this example it appears geometry can contain a name but it will not necessarily be appended to the model file unless I assign the name to an object so it appears as a name in the properties window. Is there any documentation that explains these subtleties? I guess I am looking for a definition and general implementation of attributes. I’ve been through a lot of documentation, which seems to be very scarce in my opinion and haven’t come across anything that explains attributes.


(Steve Baer) #5

Rereading your original post, I think you just need to structure your code so you don’t use an ON_SurfaceArray, but rather an ON_SimpleArray<ONX_Model_Object*> since it sounds like you know the name that you want to set. Don’t use userstrings to store the name for later retrieval, just set the name where Rhino and other applications will recognize the value, on the attributes.

Every “object” in Rhino is represented as a combination of geometry and attributes. That is why the ONX_Model_Object class has the two pieces.