Equivalent code in IronPython from C# code

Hi @stevebaer @brian @piac

I am developing a .NET application that requires the use of Iron Python to read an HDF5 file format and I have found a piece of code written in C# that solve my problem.
I am using the HDF5-CSharp library HDF5-CSharp Repo but I struggling to translate the code for Iron Python.


public class Coordinate
       [Hdf5EntryName("COORDINATES")] public double[,] COORDINATES { get; set; }

string filename = @"recorder.hdf5"; \\full path
long fileId = -1;
        fileId = Hdf5.OpenFile(filename, true);
        var result = Hdf5.ReadObject<Coordinate>(fileId, "/MODEL_STAGE[1]/MODEL/NODES");
        if (fileId > 0)

IronPython CODE (it doesn’t work)

  1. Solution exception:Property set method not found.
import clr

from System.Collections import ArrayList
from HDF5CSharp import Hdf5

filename = r"C:\Users\FORMAT\Desktop\hdf5Test\recorder.hdf5"

fileId = Hdf5.OpenFile(filename, True)

print("Group exist: {}".format( Hdf5.GroupExists(fileId, "//MODEL_STAGE[1]//MODEL//NODES")))

result = Hdf5.ReadObject[ArrayList](fileId, "//MODEL_STAGE[1]//MODEL//NODES//COORDINATES")

I attached a “recorder.hdf5” and .dll in case you want to try to help.

Download: hdf5 and dll

Do you get a line number on where the error occurs?

It seems the library relies on the reflection structure of customized classes. I don’t believe it’s possible with IronPython.

ArrayList isn’t bound to a HDF type and you’ll need a customized type.

I have done some research around and I have (almost) made it working.
The actual problem is that I can not run the script twice and I am struggling to find a solution.
I have notice that I can just change the Class Name to run it one more time.


  line 537, in __clrtype__, "C:\Program Files\Rhino 6\Plug-ins\IronPython\Lib\clrtype.py"
  line 15, in script

A possible work around is to create a different class name everytime that the script run but there should be a better way :frowning:

IronPython Code that I have tried

import System

import clr
import clrtype


from HDF5CSharp import Hdf5

type_2d = type(System.Array.CreateInstance(float, 1, 1))

class Coord(object):
    __metaclass__ = clrtype.ClrClass

    def COORDINATES(self): return self.__coords
    def COORDINATES(self, value): self.__coords = value    

a = []
b= []
c = []

fileId = 0

fileId = Hdf5.OpenFile(r"C:\Users\FORMAT\Desktop\hdf5Test\recorder.hdf5", True)

result = Hdf5.ReadObject[Coord](fileId, "/MODEL_STAGE[1]/MODEL/NODES")
    for i in range(1000):
        a.append( result.COORDINATES[i,0])
        b.append( result.COORDINATES[i,1])
        c.append( result.COORDINATES[i,2])

Gif showing the process and error

1 Like