algorithmic modeling for Rhino
Hi Julz,
can you clarify "position" and "index"? Position in 3D space, position in an array, in a Grasshopper Data structure?
What class does "doc.object" refer to?
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Hi Julz,
layers do not contain lists of objects. So the question "What's the Nth object on layer X" does not have an answer. The document contains a list of objects, and each object knows to which layer it belongs.
If you want to keep track of objects in the Rhino document you can do a number of things:
1) Give them a specific name. You can assign names in the ObjectAttributes. You can then later iterate over all objects, find the one with the name you're looking for and replace the geometry.
2) If you don't like to use the Name, you can instead use the UserText fields. This in fact makes it a lot easier to find objects at this very moment because you can use the FindByUserString method:
doc.Objects.FindByUserString("Julz_Index", "idx=3", False, False, True, ObjectType.Brep)
3) The benefit of (1) and (2) is that the data is stored inside the Rhino document and thus survives indefinitely. However it can be slow and is liable to corruption since your data can be accessed by others. Also, when objects are copied so are the strings you rely on.
A third option would be to maintain a local database that allows you to keep track of object/index pairs. For example, you could use a SortedList(Of Int32, Guid). Whenever you add a new object to the Rhino document, you first check whether the index is already defined inside your sortedlist, then -if it is- you replace the object. This database will need to be specifically saved by you though otherwise it will evaporate when Rhino is shut down.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Thanks David to flatten all of this in mind, the solution 1 is the shortest way for my situation and the shortest way is always the best. ;)
Thanks again.
I use option #2 for putting data on objects baked with the Geometry Cache parameter.
It's nice because the searching happens purely on the C++ side of things so there's minimal overhead, UserStrings are still accessible by everyone, but not as easily corrupeable as object names.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Welcome to
Grasshopper
© 2024 Created by Scott Davidson. Powered by