Rhino.Geometry.Point3d and Rhino.Geometey.Point questions

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:


I get an error:

Message: expected Point3f, got Point

If I use the .Location of the .Point:


I get a point added to the doc, but alas, no userData. I know the userData is in the .Point

So my question is, how can I add a Rhino.Geometry.Point to the document with the userData?


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


1 Like

OK, what am I doing wrong:

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
#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')


checking value is stored:
User string count:
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.