Share string with c# plugin and c++ pugin

I use Rhino.RhinoDoc.ActiveDoc.Strings.SetString() in c# to write a string to rhino active document, how can I get this string by c++?

Hi @suc_kiet,

Use CRhinoDoc::GetUserString and CRhinoDoc::SetUserString.

– Dale

Hi@ dale:

Hi @dale,

Do you know some web with explains CRhinoDoc::GetUserString function usage? I have some problem and I don’t know where is the problem.


Hi @aitorerana,
May this sample will help you.

    CRhinoGetObject go;
	go.SetCommandPrompt(L"Select Curve");
	go.GetObjects(1, 1);
	if (go.CommandResult() != CRhinoCommand::success)
		return CRhinoCommand::success;
	ON_wString key = L"test";
	ON_wString text = L"sample text";
	const CRhinoObjRef& ref = go.Object(0);
	const CRhinoObject* objj = ref.Object();

	ON_Object* obj = const_cast<CRhinoObjectAttributes*>(&objj->Attributes());

	// Part 1 start
	obj->SetUserString(key, text);
	// Part 1 end
	// Parte 2 start
	ON_wString textStr;
	obj->GetUserString(key, textStr);

	ON_wString userTextStr;
	userTextStr.Format(L"UserText: %s\n", textStr);

	return CRhinoCommand::success;

Hi @aitorerana,

Here is some text on object user text. Basically, document user text is the same thing.

– Dale

Thank you both!!

@suc_kiet it helps me a lot, now I have other problems but this work good.
@dale I alredy saw that site but didn’t see how to use GetUserString() function.

Thanks again.

Hi Dale, why not Rhino.RhinoDoc.ActiveDoc.Strings.SetString() ?

Hi @gustavo.uzcategui,

The customer above is using C++, not .NET.

– Dale

ahh ok, thanks. I take the opportunity to ask for help, I am using this
but I don’t know why because it returns null

Return Value
Type: String
The previous value if successful and a previous value existed.

– Dale