# Get user string doubs

**URL:** <https://discourse.mcneel.com/t/get-user-string-doubs/83333>\
**Category:** Scripting\
**Tags:** rhino\
**Created:** [May 15, 2019, 6:29pm UTC](https://discourse.mcneel.com/t/get-user-string-doubs/83333 "2019-05-15T18:29:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cristian.donaire.roj](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/cristian.donaire.roj/32/148108_2.png) [@cristian.donaire.roj](https://discourse.mcneel.com/u/cristian.donaire.roj)\
**Post date:** [May 15, 2019, 6:29pm UTC](https://discourse.mcneel.com/t/get-user-string-doubs/83333/1 "2019-05-15T18:29:58Z")

</div>

Hello,  
I have a question with scripting when assigning a userString to a mesh. I leave two scripts but only one works.

```
#This Works
import Rhino
import scriptcontext as sc
go = Rhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select Mesh")
go.GeometryFilter = Rhino.DocObjects.ObjectType.Mesh
go.GetMultiple(1, 0)
objRefs = []
if go.CommandResult()==Rhino.Commands.Result.Success:
    objRefs = go.Objects()
go.Dispose()

for objRef in objRefs:
mesh = objRef.Mesh()

textString = "This is a Mesh"
meshCopy = mesh.Duplicate()
meshCopy.SetUserString("key",textString)
sc.doc.Objects.AddMesh(meshCopy)
userText = meshCopy.GetUserString("key")
print userText

```

With this other form I can not do the same

```
import Rhino
import scriptcontext as sc
go = Rhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select Mesh")
go.GeometryFilter = Rhino.DocObjects.ObjectType.Mesh
go.GetMultiple(1, 0)
objRefs = []
if go.CommandResult()==Rhino.Commands.Result.Success:
    objRefs = go.Objects()
go.Dispose()

for objRef in objRefs:
mesh = objRef.Mesh()

textString = "This is a Mesh"
meshCopy2 = mesh.Duplicate()
#This part don´t Works
atributtes = Rhino.DocObjects.ObjectAttributes()
atributtes.SetUserString("key2",textString)
sc.doc.Objects.AddMesh(meshCopy2,atributtes)
userText = meshCopy2.GetUserString("key2")
print userText

```

Any suggestions? Please help me.

[SetGetUserString.3dm](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/c/6/c628f33facd839d981471c95c1515d75f1da14e9.3dm) (2.5 MB)

---

<div class="post-metadata">

**Author:** ![lando.schumpich](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/lando.schumpich/32/636282_2.png) [@lando.schumpich](https://discourse.mcneel.com/u/lando.schumpich)\
**Post date:** [May 16, 2019, 6:33am UTC](https://discourse.mcneel.com/t/get-user-string-doubs/83333/2 "2019-05-16T06:33:47Z")

</div>

Hello @cristian.donaire.roj,

In Rhinocommon there are conceptually two main elements that make up every object in the Rhinodoc

- Geometry (inheriting from [GeometryBase](https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_Geometry_GeometryBase.htm), like your mesh is)
- [ObjectAttributes](https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_DocObjects_ObjectAttributes.htm)

You can assign your UserString to either one of those, like you do in your two examples.  
If you want to get back the UserString in your second example, you have to get it from the attributes like this:

```python
atributtes = Rhino.DocObjects.ObjectAttributes()
atributtes.SetUserString("key2",textString)
sc.doc.Objects.AddMesh(meshCopy2,atributtes)
userText = atributtes.GetUserString("key2")

```

Also a little side note:  
Your get function lets you select multiple meshes, but then you just take one f those and assign it to your `mesh` variable. Also, if your get function is escaped by pressing `ESC` or not selecting anything, your script will crash, try to set up your get function like so:

```python
def myGetOneMeshFunction():
    go = Rhino.Input.Custom.GetObject()
    go.SetCommandPrompt("Select Mesh")
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Mesh
    go.Get()
    if go.CommandResult() != Rhino.Commands.Result.Success:
        return go.CommandResult()
    
    mesh = go.Objects()[0].Mesh()
    go.Dispose()

    # Do the rest of your logic here...

if __name__ == " __main__":
    myGetOneMeshFunction()
```
