Fastest way to get object from 3dmFile

Hello,

i have a 3dm that i read using FileIO.Read.
In this file there are more than 100000 objects. I have to search for specific objects many times in this file.
But at this moment the only way i can find is to iterate through the object table using an enumerator and checking
attributes of the object (Name). There is a method called FindByLayer for File3dm.Objects - but objects are all on the same layer. I could place each object an a layer named by guid or something similar, but I am afraid a file with 100000 and more Layers will also not be very fast to acces. Is there a faster way to get objects by guid or name?

Thanks in advance,
Philip

Hi Philip,

The data structure behind File3dm.File3dmObjectTable is an array structure similar to a .NET System.Collections.Generic.List. So, the object table isn’t going to help you much.

I suggest that you create either a HashTable or a Dictionary that can assist you in looking up objects. Make a single pass through File3dm.File3dmObjectTable and add every object to HashTable or Dictionary. Then, when you need to retrieve an object, look up its index in your HashTable or Dictionary. This will be much faster than repeatedly iterating the object table.

Hi Dale,

I tried to use dictionaries for that, but the problem is that while the script runs, objects are added to the 3dmfile with file_3dm.Objects.Add… This returns a Guid. But with this i have no “direct link” to the object in the 3dmfile i guess.
So if I have this guid as item for the objectname (key) in a dictionary, will rs.coercegeometry(guid) provide acces to the object in the 3dmfile? For example I want to add points to an existing pointcloud in the 3dmfile. I hope I explained my problem understandable.

Philip

No. The “coerce…” function found in the rhinoscriptsyntax namespace only deal with objects in the active Rhino document, no some arbitrary File3DM you’ve read.