Get/Set user text on c#

How I can get/set user text on c#??

Python sample:


Document text is stored in the RhinoDoc.Strings table

Object Attribute Text is located in a RhinoObjects ObjectAttributes

Here’s a link to the original User Text / Doc Text panel project. It should give you plenty of ideas and examples

Hello @Trav ,

Can you write a simple comand to set an get the user text?

Sorry but , I using python and trying use some C# comands with python, so , the c# is just for Dock panel.


We have another sample here.

Sorry , @Trav I can not understand this C # syntax, it must be because I am, very attached to python syntax.

So , I have two C# buttons, and I whant set a user text on doc, and get user text from doc,
How can I do this easily? following this example?

  private void button1_Click(object sender, EventArgs e)

      // equivalent to


  private void button2_Click(object sender, EventArgs e)

      // equivalent to

      String a = rs.GetDocumentUserText(“var1”) 



To use RhinoScript from inside of your button you’ll need to add a reference to the RhinoScript.tbl file located in your Rhino 6 \ Plug-ins directory to your project.

You can then add this code to your button and have access to RhinoScript functionality.

        var rhinoscript_object = RhinoApp.GetPlugInObject("RhinoScript");
        if (rhinoscript_object == null) return;
        var rs = (IRhinoScript)rhinoscript_object;

        rs.SetDocumentUserText("Key", "Value");

@Trav I teste you code:

    private void button1_Click(object sender, EventArgs e)

        var rhinoscript_object = RhinoApp.GetPlugInObject("RhinoScript");
        if (rhinoscript_object == null) return;
        var rs = (IRhinoScript)rhinoscript_object;
        rs.SetDocumentUserText("Key", "Value");


“if (rhinoscript_object” return always null, the script stop on “if” line an return


GetPluginObject wont return an object if the plug-in you specify isnt loaded. You need to open the Plug-in Manager and ensure RhinoScript is checked and restart Rhino.

1 Like

Suite…, this will allow you to move faster.

I gone create a plugin with a installer (visual studio), there is a away to load this plugin (RhinoScript)
on frist installer?? with no user interference?


This plug-in is generally loaded by default unless you’ve unloaded it or you have virus scanner or something blocking it.

There’s no need to use RhinoScript for this. If you are trying to perform the C# equivalent of what one of the rhinoscriptsyntax functions does, I would recommend looking at the rhinoscriptsyntax implementation as that just directly calls RhinoCommon. For GetDocumentUserText you can look here

For C#, you would just call
string a = doc.Strings.GetValue("var1");

Hello @stevebaer, I test you example but there is a error on DOC.

Can be a using lib missing? I already check all this:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using Rhino;
using Rhino.PlugIns;
using Rhino.UI;
using Rhino.Commands;
using Rhino.Input.Custom;
using Rhino.DocObjects;
using Rhino.Input;
using RhinoScript;
using RhinoWindows;


‘doc’ refers to Rhino.RhinoDoc.ActiveDoc, the plugin’s ‘RunCommand’ method provides it as an argument. If your outside that method you’ll need to grab it explicitly like this “var doc = Rhino.RhinoDoc.ActiveDoc;”. Although I’m not sure if this is best practice.


Thank you

@Trav ,

I have this code, I need check is empty or not:

        var rhinoscript_object = RhinoApp.GetPlugInObject("RhinoScript");
        var rs = (IRhinoScript)rhinoscript_object;
        var Selec = rs.GetObjects("selecionar objecto");

        if (Selec.Length == 0)
           MessageBox.Show("nor enpty");

If “Selec” not empty this script work, but if “Selec” is empty ther is a error.

Wy this appen?