Grasshopper

algorithmic modeling for Rhino

Hi,

I would like to use a specific API library within a rhino.python component.

It works with a vb.net component by using the Manage Assembly option, and choosing my .dll file (Interop.RobotOM.dll). But I don't know how to do it with a rhino.python component. The question is : where do I have to copy my dll file ? I tried to copy it into  \Plug-ins\IronPython\Lib, but there are only .py files.

Same problem with AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython\settings\lib

Do I have to convert my .dll into a .py file ? And how ?

Views: 5339

Replies are closed for this discussion.

Replies to This Discussion

Perhaps you could experiment with importing .NET assemblies. This is how for the Grasshopper.dll:

import clr
clr.AddReference("Grasshopper")
import Grasshopper

I think that this particular file is located in the Grasshopper root directory.

Edit: here's a link on the subject.

 

that's right

you might need otherwise 

import clr

clr.AddReferenceToFileAndName("C:\...........")

so it gives you the chance to add the whole file path

I tried :

import clr

clr.AddReferenceToFileAndName("C:\Program Files\Version d’évaluation de Rhinoceros 5.0 90 jours\Plug-ins\IronPython\Lib\Interop.RobotOM.dll")

But I got the following message :

Runtime error (MissingMemberException): 'module' object has no attribute 'AddReferenceToFileAndName'
Traceback:
line 7, in script

You can see the clr methods by going like this:

import clr

print dir(clr)

I'm not sure but the one you're looking for might be "AddReferenceToFileAndPath". While troubleshooting you might also want to copy your .dll to the same directory as the Grasshopper.dll and then try to import it like I suggested above. If that works it stands to reason that the other methods should work. Finally there may also be issues with the formatting of the filepath.

sorry for the "tofileandname" thing.

 

nders is right it is tofileandpath actually.

OK,

I am a beginner with Python.

I tried : 

import clr
clr.AddReferenceToFileAndPath("C:\Program Files\Version d’évaluation de Rhinoceros 5.0 90 jours\Plug-ins\IronPython\Lib\Interop.RobotOM.dll")

Seems to work (no error message), but now, I can I have access to my library ?

For rhinoscrit, i write 'import rhinoscriptsyntax as rs', then I can call a class by using toto = rs.AddArc(), for example.

Here, I did not give a name to my new library. I can I do that ? 

You still have to import your .dll after adding the clr reference (see my first reply again with the Grasshopper example). You can use any alias you like using the "as" keyword. So in your case you probably want something like this:

import clr
clr.AddReferenceToFileAndPath("C:\Program Files\Version d’évaluation de Rhinoceros 5.0 90 jours\Plug-ins\IronPython\Lib\Interop.RobotOM.dll")
import Interop.RobotOM as irobot

Adding this line gives this message : 

Runtime error (MissingMemberException): 'LightException' object has no attribute 'RobotOM'

That probably has to with the (rather odd) full stop in the .dll name acting like a dot operator (that is that Python thinks you're trying to access the method RobotOM on the object Interop). Other than that I have no more ideas!

the name that you must import after adding the clr reference may be different than the .dll name

for example, if I added a clr reference to the rhinocommon.dll, I would then import it using

import Rhino

because Rhino is the name defined within the dll.

Basically, you need to check the documentation for your .dll, and perhaps check how it is imported in C# or other languages.

That's correct !

The right name to import is not Interop.RobotOM but RobotOM. Now it works. The final syntax is : 

import clr
clr.AddReferenceToFileAndPath("C:\Program Files\Version d’évaluation de Rhinoceros 5.0 90 jours\Plug-ins\IronPython\Lib\Interop.RobotOM.dll")
import RobotOM as rbt

Thanks a lot !

Benjamin is right.

I don't know whether you wrote the dll or is it from a different software you want to use.

If you wrote it, or somehow you manage to access it in case it is not yours, inside you must find a bunch of classes inside a "namespace".

In the python editor the "file.dll" you can use for addressing the reference, then you use the "namespace" to import the library.
Import "namespace" as...

Hope it is helpful.
In case it is a dll from a different software which is not documented, please i will be very interested if you manage to have access to it.
Thanks

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service