+ Reply to Thread
Results 1 to 2 of 2

Thread: .NET IronPython interop

  1. #1

    .NET IronPython interop

    Hi Steve

    This might have been asked before but I was unable to search the forum. The search produces no results, also for words that are definitely appearing in posts.

    Regarding my question: I would like to provide some functionality from my .NET plugin for Python scripting. I intended to write a wrapper in IronPython, same as you do with RhinoPython. But I'm unable to load my assembly, clr.AdReference() fails. How are you doing it in the RhinoCommon.dll, so that in Python you just can do "import Rhino". I looked at the RhinoCommon github repo but couldn't find the relevant parts of code. Any tips would be highly appreciated.

    Thanks,
    Silvan

  2. #2
    Senior Member Steve Baer's Avatar
    Join Date
    Apr 2010
    Location
    Seattle
    Posts
    1,472
    Blog Entries
    19
    Hi Silvan,
    I really need to write a full article on this topic, but here's a quick answer.

    There are two ways to export functionality from your .NET plug-in to things like scripts.

    1 - The quick way:
    In your plug-in class, override the GetPlugInObject function and return an instance of a class that you want to be able to call functions on. Then in python do something like
    Python Code:
      import Rhino
      myclass = Rhino.RhinoApp.GetPlugInObject("Silvan's Plug-In")
      if myclass:
          myclass.MyCustomFunction(1,2,3)
    The GetPlugInObject function on RhinoApp will attempt to load your plug-in, call the GetPlugInObject virtual function and return the class that has your custom functions on it.

    2 - The long way:
    Break your plug-in into two pieces; an rhp and a dll that contains functionality but no plug-in or command classes. RhinoCommon uses installed plug-in directories as a search path when looking for assemblies that .NET can't immediately find, so if you want to use your custom dll from python and that dll is in the same directory as your rhp you can then write
    Python Code:
      import clr
      clr.AddReference("SilvanLib")
      import SilvanLib
       
      SilanLib.CustomClass.DoSomething(1,2,3)

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts