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( prompt='test', acceptNothing=True, filter=fitler_type ) 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!