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


#1

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:

scriptcontext.doc.Objects.AddPoint(Rhino.Geometry.Point)

I get an error:

Message: expected Point3f, got Point

If I use the .Location of the .Point:

scriptcontext.doc.Objects.AddPoint(Rhino.Geometry.Point.Location)

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?

Thanks!


(Steve Baer) #2

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)

http://4.rhino3d.com/5/rhinocommon/html/M_Rhino_DocObjects_Tables_ObjectTable_Add.htm


#3

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
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.