Rhino3dm.py - Can't read object user strings from existing file

test.3dm (31.2 KB)

I hope I’m not doing something obviously wrong here, I’m new to rhino3dm.

Running this code here with the attached model file:

import rhino3dm as r
model = r.File3dm.Read('test.3dm')
objTable = model.Objects  
for obj in objTable:      	
	geom = obj.Geometry      	
	print("<<< All user strings: ", geom.GetUserStrings() , "   Type string: ", geom.GetUserString( "type" ), "   User string count: ", geom.UserStringCount, " >>>" ) 

The output is this, despite the fact that the single surface in the model does in fact have several pieces of user text attached:

<<< All user strings: () Type string: User string count: 0 >>>

If I set user text in the code before printing it works fine.
Added line:
geom.SetUserString( "type", "Frame web" )

Result is then:

<<< All user strings: ((‘type’, ‘Frame web’),) Type string: Frame web User string count: 1 >>>

Hi Freg,

Usertext can be set to the object Geometry or or on the object Attributes. I think it is policy that within Rhino usertext is stored on the attributes.

Does that help?
-Willem

1 Like

Oh, thanks Willem!

Using obj.Attributes instead of obj.Geometry is the answer.

I’m using a combination of documentation here: https://mcneel.github.io/rhino3dm/python/api/index.html
and here: https://developer.rhino3d.com/api/RhinoCommon/html/R_Project_RhinoCommon.htm
I’m not sure either is correct and complete for rhino3dm.py…