Component: Get Object Names from Rhino

Hi all,

Not sure if anyone would find this tool useful but I thought I’d share a small custom component that I have been using a lot lately in case it is of any help to other folks.

Quick Background: For some projects, in order to help manage certain data, we like to embed certain bits of info directly into the Rhino scene objects rather than do everything in the Grasshopper environment. While there are definitely times its nice to do everything in GH (if your running lots of scenarios, if things are changing dynamically, etc…), its seems that in many projects we’re working on in our office its been easier to manage the data within the 3D scene directly instead. For instance - for many models I’ve found I like to build the object names right into the Rhino scene, rather than add them in GH. But, in order to be able to pull that data from Rhino into GH though I had to make a quick component (not sure if this is already a tool someplace else in GH but I couldn’t find it back when I built this - so apologies if I’m duplicating here).

The tool is pretty straightforward, you just input a list of any Rhino objects and their GUID (you can use the GH ‘ID’ component to do that) and it’ll output a sorted list of the objects and their names:
(note that the ‘name’ field from the Rhino Properties is the info being pulled into GH)

I’ve used this tool to help me control / manage windows in our models mostly - for lots of our work I like to keep an eye on windows on a unit-by-unit basis for things like solar gain / transmission loss and having the names flow through the entire workflow automatically allows us to keep better control and review output better at the tail end of the simulation.

Especially for medium complexity models (where adding data on a per-window basis in Rhino isn’t a huge issue) this workflow seems to work well. Certainly if you had thousands of windows or something like that it’d be a drag - but for smaller buildings it seems to work ok. We’ve used this method to get names for Ladybug radiation analysis work, and it can also be used to get names for any of the Honeybee tools such as ‘addHBGlz’ which asks for names:

And as I said, this allows us to then keep good track of results on a window-by-window basis easier so that during design optimization we have an better handle on whats what in the model and can reconcile results with geometry faster:

Also its interesting to note that this same technique could actually grab a bunch of different info from the Rhino scene about an object and maybe most usefully for this sort of simulation modeling is that you could grab the ‘Details’ data. So - in theory - some set of data / tags could be added to the ‘Details’ on an object by object basis in Rhino, and then harvested / brought into GH automatically during the simulation phase. I’ve played with that workflow a little bit and it can work - though I don’t have a good clean component to share yet, but just by way of a simple example:

Use a quick Rhinoscript or Python script inside Rhino (just a simple setter and getter) to add some type of useful data to an object in the Rhino scene…

This data (text) then lives as ‘User Data’ in the ‘Details’ of that object and can be read at any time by GH or another script…

at any rate, in case that is of any interest or use to anyone I’ve attached an example Rhino/GH file with the simple name reader component here.

best,
-Ed

Object Names - Example.gh (8.5 KB)
Object Names - Example.3dm (61.2 KB)

8 Likes

:100: Thanks for sharing! This is very true and this component definitely help. We should consider loading model from Rhino and dumping model into Rhino for Honeybee[+].

@edpmay this is great!
Have you tested it wish Meshes as well? I do have issues with using this with more than one Mesh as the time

@edpmay,
I like your work. This is definitely a great share. Can you also share what tool you used to create the chart? Is it something from ProvingGround

Hi @edpmay,

Have a look at the human plugin. https://www.food4rhino.com/app/human
They have created a dynamic geometry pipeline node with the ability to read all information stored in the rhino geometry. You can even read and add attributes from and to the rhino geometry.

image

Hi @devang, thanks! Thats so nice of you to say - appreciate it. I’m embarrassed to say I still default to excel for charts like that one. Don’t tell anyone though.

And thats a great Human tool, I’d never noticed that object reader part of it before. Super useful. As far as the simplified code here @andrea.botti, it should work with Meshes I think? It should be able to read any object’s UserText or object name from the Rhino scene. I have a new version attached here that does, as @Erikbeeren points out, use the Attribute UserText now available in Rhino 6 along with the name. Maybe try that and see if it works better for you?

The code to do this is very simple: you just switch over to the Rhino doc, grab the data using rs.ObjectName() and rs.GetUserTetxt(), then switch back to the GH doc. Can be added to any component you might be building I’d think:

import Rhino
import scriptcontext as sc
import rhinoscriptsyntax as rs
from System import Object
from Grasshopper import DataTree
from Grasshopper.Kernel.Data import GH_Path
import Grasshopper.Kernel as ghK

sc.doc = Rhino.RhinoDoc.ActiveDoc # Switch over to the Rhino Doc
if len(_obj)>0:
    names_ = DataTree[Object]()
    params_ = DataTree[Object]()
    
    for i in range(len(_obj)):
        # Get the Object Name
    try:
        names_.Add(rs.ObjectName(_obj[i]) , GH_Path(i))
    except:
        msg = 'Something went wrong getting the Name'
        ghenv.Component.AddRuntimeMessage(ghK.GH_RuntimeMessageLevel.Warning, msg)
        names_.Add('Error', GH_Path(i))
    
    # Get the Object Attributes
    windowDataFromRhino = {} # Temp dict to store the data
    try:
        if rs.IsUserText(_obj[i]):
            for eachKey in rs.GetUserText(_obj[i]):
                windowDataFromRhino[eachKey] = rs.GetUserText(_obj[i], eachKey) 
    except:
        msg = 'Something went wrong getting the Object Params (UserText)'
        ghenv.Component.AddRuntimeMessage(ghK.GH_RuntimeMessageLevel.Warning, msg)

    # Add the Object Params to an output list
    params_.AddRange(list(windowDataFromRhino.items()), GH_Path(i))
sc.doc = ghdoc # Switch back to the Grasshopper Doc

The component can either be set up to take in a GUID directly (set the input’s type-hint to GUID - only available in Rhino 6 though I think…) or just use an ‘ID’ component to input the GUID of the objects in your Rhino scene and set the type-hint to ‘none’ on the component’s input.

For whatever its worth, we’ve been building this functionality into a lot of our custom components/workflows in order to host more and more data back in the Rhino objects rather that in the GH doc. I know you can’t then easily modify it in GH for things like variant analysis, but for lots of the types of things we’re up to it just makes the GH doc a lot cleaner and seems easier for us to manage all the data that way. Certainly not the best answer for everything, but I think it is a useful tool to have available. You can build in all sorts of param assigners to auto-populate and create standardized attributes:

anyway, hope that is useful. Give me a holler if its still giving you errors though? Happy to take a look.
best,
-Ed

GetName.3dm (57.2 KB) GetName.gh (15.5 KB)