Working with the UserDictionary on Subobjects?


I use the UserDictionary on objects a lot to store and mange data. Recently I was looking at trying to store (and then later read back) some data a the sub-object level and I am having trouble.

In particular, I have several PolylineCurves made up of multiple segments

and I need to set, store, and then later read back custom metadata on a ‘per-segment’ basis. ie: one segment has a pipe diameter or ‘x’, then the next segment has a pipe diameter of ‘y’, etc… It is important that the curves are all single objects (joined PolylineCurves), not groups of LineSegments or anything like that.

I am able to grab the sub-object curves and successfully write date to the UserDictionary for the sub-objects, which seems to get logged at first:

import Rhino
fitler_type = srf_filter=Rhino.DocObjects.ObjectType.Curve
rc, objrefs = Rhino.Input.RhinoGet.GetMultipleObjects(

for obj_ref in objrefs:
    crv = obj_ref.Curve()   
    d = crv.UserDictionary
    d["length"] = crv.GetLength() # Set a test key on the UserDictionary
    print d["length"] #< -- Works

BUT, if I then try and read (without setting) the same sub-object curves after this initial set, I get a KeyError. So it appears the data didn’t get logged on the UserDictionary?

Does anyone know if it if is possible to log UserDictionary data on LineSegment of a PolylineCurve (or another similar sub-object)? Is there another better way to do something of this sort that I am missing? Is there another method for managing the sub-object data that lives up at the parent or something like that?

Any thoughts are much appreciated!

It is possible to store a user dictionary inside a another user dictionary. So if you use as key the index of the segment, you could use a different dictionary for each segment stored on the dictionary of the polycurve.

Thanks @menno , that is an interesting idea. Yes if the data can’t be managed at the sub object level I suppose managing at the parent level would be the only option?

I wasn’t able to see where the parent PolylineCurve object manages the segments though? Looking through the documentation or the dir() on the curve object didn’t seem to show any ‘Segments’ attribute or anything of that sort? I don’t think I understand how a PolylineCurve manages the sub-object segments and their ID / order ? Do you know where such information gets stored / logged or where that might be documented?


A polyline curve is a curve whose data is an array of 3d points.

– Dale