# Set Multi-UserString on the same CRhinoObjRef

**URL:** <https://discourse.mcneel.com/t/set-multi-userstring-on-the-same-crhinoobjref/15474>\
**Category:** Rhino Developer\
**Created:** [January 8, 2015, 11:25am UTC](https://discourse.mcneel.com/t/set-multi-userstring-on-the-same-crhinoobjref/15474 "2015-01-08T11:25:11Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vaker](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/vaker/32/646982_2.png) [@Vaker](https://discourse.mcneel.com/u/Vaker)\
**Post date:** [January 8, 2015, 11:25am UTC](https://discourse.mcneel.com/t/set-multi-userstring-on-the-same-crhinoobjref/15474/1 "2015-01-08T11:25:11Z")

</div>

Command1:

```
CRhinoMeshObject* obj=m_Doc->AddMeshObject(mesh);
CRhinoObjRef ObjRef(obj);

ON_UserString us[2];
us[0].m_key = _T("test1");
us[0].m_string_value = _T("1");
us[1].m_key = _T("test2");
us[1].m_string_value = _T("2");
CRhinoObject* pObj = (CRhinoObject*)ObjRef.Object();
CRhinoObjectAttributes Attrib( pObj->Attributes() );
Attrib.SetUserStrings( 2, us, true );
pObj->ModifyAttributes(Attrib);

```

Command2: modify same CRhinoObjRef ObjRef

```
ON_UserString us[2];
us[0].m_key = _T("test1");
us[0].m_string_value = _T("1");
us[1].m_key = _T("test2");
us[1].m_string_value = _T("4");
CRhinoObject* pObj = (CRhinoObject*)ObjRef.Object();
CRhinoObjectAttributes Attrib( pObj->Attributes() );
Attrib.SetUserStrings( 2, us, true );
pObj->ModifyAttributes(Attrib);

```

go through all UserString:

```
ON_ClassArray<ON_UserString> NewUserStringArray;
int iTCount = pObj->Attributes().GetUserStrings( NewUserStringArray );
for ( int iKeys=0; iKeys<iTCount; iKeys++ )
{
	ON_UserString* us = NewUserStringArray.At(iKeys);
	ON_wString key = us->m_key;
	ON_wString value = us->m_string_value;
};// iKeys loop

```

The value of UserString key"test2" still “2”.  
The value do not update.  
Please help me.

Best Regard,  
Vaker

---

<div class="post-metadata">

**Author:** ![dale](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dale/32/685184_2.png) [@dale](https://discourse.mcneel.com/u/dale)\
**Post date:** [January 8, 2015, 6:45pm UTC](https://discourse.mcneel.com/t/set-multi-userstring-on-the-same-crhinoobjref/15474/2 "2015-01-08T18:45:59Z")

</div>

Hi Vaker,

There is a know issue with attribute user strings and ModifyAttributes.

[http://mcneel.myjetbrains.com/youtrack/issue/RH-29393](http://mcneel.myjetbrains.com/youtrack/issue/RH-29393)

Here is a method that works.

[https://github.com/mcneel/Rhino5Samples\_CPP/blob/master/SampleCommands/cmdSampleUserStrings.cpp](https://github.com/mcneel/Rhino5Samples_CPP/blob/master/SampleCommands/cmdSampleUserStrings.cpp)

---

<div class="post-metadata">

**Author:** ![Vaker](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/vaker/32/646982_2.png) [@Vaker](https://discourse.mcneel.com/u/Vaker)\
**Post date:** [January 9, 2015, 6:22am UTC](https://discourse.mcneel.com/t/set-multi-userstring-on-the-same-crhinoobjref/15474/3 "2015-01-09T06:22:15Z")

</div>

Hi Dale,

It works.  
Thank for your help.

Best Regard,  
Vaker

---

<div class="post-metadata">

**Author:** ![Vaker](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/vaker/32/646982_2.png) [@Vaker](https://discourse.mcneel.com/u/Vaker)\
**Post date:** [January 9, 2015, 9:57am UTC](https://discourse.mcneel.com/t/set-multi-userstring-on-the-same-crhinoobjref/15474/4 "2015-01-09T09:57:20Z")

</div>

I have another question:  
I created one Rhino object with UserString data.  
I save the object to 3dm file.  
I open the file again, then UserString data of object is missing.  
If I want to save the UserString data, how can I do?  
coding write UserString data on CRhinoUtilityPlugIn::WriteDocument()?

Best regards,  
Vaker

---

<div class="post-metadata">

**Author:** ![dale](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dale/32/685184_2.png) [@dale](https://discourse.mcneel.com/u/dale)\
**Post date:** [January 9, 2015, 9:53pm UTC](https://discourse.mcneel.com/t/set-multi-userstring-on-the-same-crhinoobjref/15474/5 "2015-01-09T21:53:43Z")

</div>

The GitHub code sample seems to work (serialize). How does your code differ?

---

<div class="post-metadata">

**Author:** ![Vaker](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/vaker/32/646982_2.png) [@Vaker](https://discourse.mcneel.com/u/Vaker)\
**Post date:** [January 12, 2015, 6:47am UTC](https://discourse.mcneel.com/t/set-multi-userstring-on-the-same-crhinoobjref/15474/6 "2015-01-12T06:47:48Z")

</div>

Sorry, my mistake.  
It works fine.  
Thank you.

---

<div class="post-metadata">

**Author:** ![jonm](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/jonm/32/502039_2.png) [@jonm](https://discourse.mcneel.com/u/jonm)\
**Post date:** [August 9, 2015, 12:37pm UTC](https://discourse.mcneel.com/t/set-multi-userstring-on-the-same-crhinoobjref/15474/7 "2015-08-09T12:37:27Z")

</div>

Hi Dale,

I don’t seem to be able to access the issue on myjetbrains, and I can’t seem to spot what the solution is in your sample c++ code.

Can you please advise further on how to address this issue using c# and rhinocommon?  
I’ve seen also that user strings aren’t being set when using modify user attributes method.

Thanks,

Jon

---

<div class="post-metadata">

**Author:** ![jonm](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/jonm/32/502039_2.png) [@jonm](https://discourse.mcneel.com/u/jonm)\
**Post date:** [August 9, 2015, 12:52pm UTC](https://discourse.mcneel.com/t/set-multi-userstring-on-the-same-crhinoobjref/15474/8 "2015-08-09T12:52:36Z")

</div>

I searched harder through my emails (as I did recall encountering this in the past).  
Adding a line such as atts.LayerIndex = atts.LayerIndex; ensures Rhino recognizes that the attributes have been modified.

---

<div class="post-metadata">

**Author:** ![dale](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dale/32/685184_2.png) [@dale](https://discourse.mcneel.com/u/dale)\
**Post date:** [August 10, 2015, 4:45pm UTC](https://discourse.mcneel.com/t/set-multi-userstring-on-the-same-crhinoobjref/15474/9 "2015-08-10T16:45:14Z")

</div>

> [@jonm](#):
>
> I don’t seem to be able to access the issue on myjetbrains

You should now be able to view the issue.
