Share string with c# plugin and c++ pugin

Hi;
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:
Thanks.

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.

https://discourse.mcneel.com/t/rhino-c-getuserstring/100276

Thanks.

Hi @aitorerana,
May this sample will help you.
https://github.com/mcneel/rhino-developer-samples/blob/6/cpp/SampleCommands/cmdSampleUserStrings.cpp

    CRhinoGetObject go;
	go.SetCommandPrompt(L"Select Curve");
	go.SetGeometryFilter(CRhinoGetObject::curve_object);
	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);
	RhinoApp().Print(userTextStr);

	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
RhinoDoc.ActiveDoc.Strings.SetString(“IsLoadedOnCheckIo”,“false”);
but I don’t know why because it returns null

https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_DocObjects_Tables_StringTable_SetString.htm

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

– Dale