I’m creating objects through a command I made and I’m wondering if it’s possible to add a plane to that object, such that I can access that plane from a different command without having to do lots of analysations. Is this something suitable for User Data? Or what do you use User data for?
Yes, absolutely.
– Dale
Hi Siemen,
Below is an example how to add geometry to another geometry userdictionary.
Do note that if you transform the base geometry, the geometry that is stored on it is not transformed
-Willem
import Rhino
import scriptcontext as sc
import rhinoscriptsyntax as rs
def add_plane(plane, size = 200):
xid = rs.AddLine(plane.Origin, plane.Origin + plane.XAxis*size)
yid = rs.AddLine(plane.Origin, plane.Origin + plane.YAxis*size)
zid = rs.AddLine(plane.Origin, plane.Origin + plane.ZAxis*size)
rs.ObjectColor(xid, [255,0,0])
rs.ObjectColor(yid, [0,255,0])
rs.ObjectColor(zid, [0,0,255])
rs.AddObjectsToGroup([xid,yid,zid],rs.AddGroup())
def get_geometry_dict_key(geom,key):
for KV in geom.UserDictionary:
if KV.Key == key:
return KV.Value
def set_geometry_dict(geom,key,geom_to_store):
udict = geom.UserDictionary
udict.Set(key,geom_to_store)
#creae geometry for example
line_curve = Rhino.Geometry.LineCurve(Rhino.Geometry.Point3d(0,0,0), Rhino.Geometry.Point3d(300,600,800))
plane = Rhino.Geometry.Plane(Rhino.Geometry.Point3d(0,0,0), line_curve.TangentAtStart)
#add line to doc to get id
line_id = sc.doc.Objects.AddCurve(line_curve)
#store the plane on the line
line_geom = rs.coercegeometry(line_id)
set_geometry_dict(line_geom,'my_plane',plane)
#retrieve the plane from the userdict
my_plane = get_geometry_dict_key(line_geom,'my_plane')
#helper to visualize the plane
add_plane(my_plane, size = 200)
Hi,
Maybe this Dale’s Rhinocommon example is useful as well (demonstrating how to attach a plane to object via UserData):
Thanks a lot @dale, @jeffoulet & @Willem!
Does that mean if I store a plane to an object that gets moved, the plane stays in the same position, but the plane is still stored in the object?
Also another question, does this increase file size a lot or is it not that bad or not at all?
Hi Siemen,
yes, however any change to the geometry of the object will make you loose the plane.
I’m not sure what changes do and do not loose is, for I’m using this on ‘static’ objects only.
Best would be to do some tests to find out yourself.
-Willem
Thanks a lot Willem. OnePush looks amazing by the way!