I am working on a project in which I am storing string data in the geometry objects. Everything is working for curves. I also would like to store things in points. However, Point3d does not have a SetUserString method, which is what I am using on the curves. After looking around I find that Rhino.Geometey.Point seems to be what I want, as the .Location is the point3d, and it also has the geometry base that holds the user data. However, when I try to add the .Point to the document:
Point derives from GeometryBase so you’ll want to use the function on the ObjectTable that takes GeometryBase as input. This is the Add function
location = Rhino.Geometry.Point3d(1,2,3)
point = Rhino.Geometry.Point(location)
# add user data to the point geometry
scriptcontext.doc.Objects.Add(point)
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
#get set of coords
pointLocation = rs.GetPoint('select point location', in_plane=True)
#make the 'Point' object
rgPoint = Rhino.Geometry.Point(location=pointLocation)
#set user string
rgPoint.SetUserString(key='key', value='value')
#check user string is stored in 'Point'
print 'checking value is stored:'
print rgPoint.GetUserString(key='key')
#add the point to the object with the 'add' function
sc.doc.Objects.Add(rgPoint)
#select the just added 'Point'
pointObject = rs.GetObject('select point for user data print')
#get to the geometry
rgPointObject = rs.coercegeometry(pointObject)
#should be 1 user string
print 'User string count:'
print rgPointObject.UserStringCount
print 'User string value:'
print rgPointObject.GetUserString(key='key')
output:
checking value is stored:
value
User string count:
0
User string value:
Little more investigation shows that if I add the Point, then edit user strings, it seems to hold.
2/24 - Ok I have worked around it for now by adding the data immediately after I add the point to the doc. Still not sure what I am doing incorrectly or why the sc.doc.Objects.Add() looses the user strings, but have a working solution now.