Exchange of data between python and C#

Dear community,

In C#, I can set data using RhinoDoc.Strings.SetString( StringName, StringValue );
which can then be retrieved in a python script using
strValue = rs.GetDocumentUserText( StringName )

Now my questions are:

  1. is this also possible with other data than strings (now I convert in C# StringValue.ToString() and in Python with float(strValue)
  2. is it possible to pass many of these strings in a structured way? Python suggests to work in sections : value = rs.GetDocumentData(“MySection1”, “MyEntry1”) but how to add these sections in C#? In C# on the other hand, something like UserDictionary seems to exist, but how (if at all) can I address them from Python?

Thanks in advance for your leads.

Filip

In Python you have access to RhinoCommon. It seems the most easy way to exchange data between C# and Python.

Rhino, RhinoScript, RhinoCommon, and Rhino.Python can all share user text…

Dear Dale,

I am currently using UserText, but I am passing quite a lot of values string by string, and casting them in python back from strings to whatever I need in Python.

Is there a more structured way to pass larger amounts of values from C# to Python than string by string? It works for now, but maybe I am missing something to pass all these data is a more structured way…

Thanks in advance, and kind regards,

Filip

The next step up from UserText is UserDictionary. It is accessible by C# and by Python using RhinoCommon.

import rhinoscriptsyntax as rs
import scriptcontext as sc

def findUserDict():
    id = rs.GetObject("Select object")
    guid = rs.coerceguid(id)
    obj = sc.doc.Objects.Find(guid)
    for key in obj.Geometry.UserDictionary.Keys:
        print key, obj.Geometry.UserDictionary[key]

if __name__ == "__main__":
    findUserDict()

Thanks for this answer, I am almost where I want now.

Is it also possible to add this dictionary directly to the document and not to an object in the document?

In our C#, we ask the user to define a set of parameters, which is then passed to python to construct the objects. But in C#, there are no geometric objects constructed yet…

Thanks for your patience and replies.

Kind regards,

Filip

Hi,

I am also searching for such a possibility. Filip did you allready find a solutions for that?

Regards,
Philip

Have you tried user text?

Yes, but like filip I am trying to store other types than strings. So an archivable dictionary or something like that attached to the document, rather than to an object would be great. But I could not find a way to do so.

Philip