Import Pyhton Libary in Dynamo

python
importinstance

#1

Hello,

In the end I would like to modify Images with dynamo and import those into Revit.
Basically print text (Revit inofs) on images. So my approach was to import the Pillow llibrary form Pyhton and go from there.

So my first step was to import a simple python script and acces its function, but I faild. IronPython.Runtime.PythonFunction

Could you guys help me why?

I suppose it has to do with Iron python not being python but just an .net VBA hidden behind a python mask, hahaha


#2

Hi
Try adding your IronPython path to your script: (Default:)
sys.path.append(“C:\Program Files (x86)\IronPython 2.7\Lib”)

Though you should be aware that Dynamo currently only can use libraries that are supported by IronPython.


#3

You’ve forgetten to add () after your function, everything’s fine


#4

On another note, Pillow uses C python modules so it can’t be used in ironpython.

You might be able to use the .NET System.Drawing class to achieve what you’re after. This can be found here:

C:\Windows\Microsoft.NET\Framework\v…

If you still want to use Pillow see here:


#5

Wow thanks for the fast reply i will check those out next week and come back to you


#6

OK, So importing the .NET libary works, just need to know how to use it…

import clr
import sys
sys.path.append(r'C:\Windows\Microsoft.NET\Framework\v4.0.30319')
clr.AddReference('ProtoGeometry')
clr.AddReferenceToFile('System.Drawing.dll')

I’ll keep you posted


#7

There are lots of C# tutorials on stackoverflow for using this class, you’ll be able to translate it to python fairly easily. Remember to dispose the image once you’ve finished


#8

Thanks Tom, I’m crawlling my way through the .NET world and find it not very… accessible
Thanks for your support though


#9

It’s fun! Check out msdn for more info on the system.drawing namespace, any other questions are probably best directed at stackoverflow for this kind of thing