Getting objects original variable name

Say I create a point and add it to the doc as follows:

Dim CenterPoint = new point3d(10,10,10)
Dim CenterPointID = doc.objects.addpoint(CenterPoint)

Now that the point is in the doc, is there any way for me to figure out figure out what the original name of the point’s variable was (CenterPoint). I’m asking because I am adding a huge number of objects to the doc and I haven’t set the attributes to reflect their name. And I’m trying to figure out which is which.

I’m picturing a function where, from within Rhino, I pick the object in question, and somehow I’m alerted to what the original name of it’s variable was (should be CenterPoint).



Why not set the attributes to reflect the variable name like you suggest? This should be the easiest most straightforward way

Because I have hundreds of variables and it would take a long time…

Hi Sam,

Am I interpreting it correct that you want to:

have a property on the regular Rhino point object created by the script that is the name of the original variable as a string?

pseudocode would be:
Dim CenterPoint = new point3d(10,10,10)
Dim CenterPointID = doc.objects.addpoint(CenterPoint)
SetObjectname ( CenterPointID, VariableNameToString(CenterPoint))

I have no answer just trying to understand the question.


Yup, that’s pretty much it. Though I want the user to be able to select an object in the doc (say a curve), and then be told what the variable name was for it.


Sam, I know you have been using Rhino quite a while, so I guess your question might go beyond the basics in a way I don’t quite grasp yet, but:

The Basics:

  1. Every Rhino object has a name attribute. Most of the time a lot of users don’t bother filling it in.
  2. The name, if present, is shown in the property window for a selected object.
  3. All the developer tools provide a way for a plugin to fill in the name attribute (and all the other attributes) at the time of creation by the plugin or any other time.
  4. If the property window is not the way you want to show the name, your plugin could also do it.

What am I missing?

I understand the object’s name can be set via the attributes. But I’m trying to get the name of the original variable without writing code to set the name via attributes. This is an unusual case I’m dealing with where there are hundreds of variables and I’m trying to save myself the time of going through them all… I’m picturing the user is asked to select the object and then a msgbox comes up giving the name of the original variable. Any thoughts anyone?


This is not possible as far as I know. When a script finishes all variables get dedtroyed so setting the nam while adding is exactly the solution. Is the problem that you have one line per variable that you add? (Eg 700 lines of code to add your objects). If so scripts are just text files you can write a script that opens the text file of your original script and for every variable adds the lines of code @Willem replied.

If you add your variables inside of some kind of loop you just have to add willems reply to your code and it should work

Hi @samlochner, i do not think you can get that functionality without adding code to keep track of things. Since it has been suggested to assign the variable name to the object once it is added, why not do it the other way around eg. whenever you add an object within your code, you get an object id, at this time you could add this id to a dictionary which has the variable name. This supports lists so the variable name is the key while ids are the values. (in case you add points all from the same variable name). This process requires minimal code change as you could just paste the same line of code below the line of code where you add the object and get an object id back.

If you stored the dictionary somewhere you can access it and get the variable name from the selected object id.


Code below does the trick. The crucial bit I forgot to mention is that the GUIDs are stored in an instance of a class that is shared in the main plugin class, so I have access to it even after commands finish.

Thanks everyone!

P.S. when I paste code here it sometimes comes out looking nice with tabs and then other times it doesn’t. I’ve tried code tags but that doesn’t seem to help. If anyone knows how to make it prettier, please tell :slight_smile:

'get the rhino object Dim obj_ref As Rhino.DocObjects.ObjRef = Nothing Dim rc = Rhino.Input.RhinoGet.GetOneObject("Select object", False, Rhino.DocObjects.ObjectType.AnyObject, obj_ref) If Not rc = Result.Success Then Return rc End If Dim rhino_object = obj_ref.Object()
        'search through class instance (is shared in plugin class) for a matching GUID and then name the corresponding object
        Dim PropertyInfoArray() As System.Reflection.PropertyInfo = PodoCADPlugIn.Instance.LA.GetType().GetProperties()
        For Each PropertyInfo In PropertyInfoArray
            Dim value = CallByName(PodoCADPlugIn.Instance.LA, PropertyInfo.Name, Microsoft.VisualBasic.CallType.Get)
            If Not value Is Nothing Then
                If value.GetType Is GetType(Guid) Then
                    If value = rhino_object.Id Then
                        rhino_object.Attributes.Name = PropertyInfo.Name.Substring(0, PropertyInfo.Name.Length - 2)
                        Exit For
                    End If
                End If
            End If