Hi! I have a question about Ctypes on python.
I’m attempting to build a small object to pass around between fortran code and Python. But I find an error, which I show below.
Thank you in advance.
Grasshopper Python Script Editor
from ctypes import *
#call fortran code below.
mylib = CDLL('C:\\Users\\Owner\\sub.array.fortran.dll')
mylib.mySub.argtypes = [ POINTER(c_double), c_int, POINTER(c_double) ]
mylib.mySub.restype = c_void_p
ArrayType = c_double*5
IntType = c_int
input1 = ArrayType(1.1,2.2,3.3,4.4,5.5)
input2 = 5
inputoutput = ArrayType()
**mylib.mySub( input1, input2, inputoutput )**
print 'output within Python'
a = [0,1,2,3,4]
for ii in a: print inputoutput[ii]
While not having the setup ready to test this, I am not sure if CTypes is 100% compatible with IronPython, which the Python implementation used in Rhino. At first sight, I’d say yes, with some caveats.
If I read the error message, it says that it was expecting a single c_double, but you provided the c_double_Array_5 type instead. I take that is the last argument. Try putting a single value and see how it goes?
This does not seem a “walk in the park” kind of development. Are you following some tutorial?
Thank you for the information. I’m sorry I didn’t make it clear enough.
Now I am using IronPython. This is a little different from Python. I have heard that in IronPython we can not use Numpy.
I’m working through a uni project in which I’m trying to use Fortran code cause I already have a tons of sources. For GUI ,Graphical User Interface, I need to use IronPython and Ctypes.
Unfortunately, I can not show you all sources cause it is really long.
What I know now is that "mylib.mySub( input1, input2, inputoutput )"is wrong. But I do not know what I need to do next.
This is link.
I checked that my code run in Python. But I can not compile thin in IronPython.
Thanks in advance for any advice!
If you cannot make it work in IronPython, an alternative could be to invoke a CPython script from Rhino and collecting its results.