Accessing COM object

I’m trying to access a com object written in C in python script in dynamo. I have successfully managed to load the com object and the function calls seem to work (no errors or exceptions) but when I use the functions with parameters passed by reference, I only ever get zero returned:

t = System.Type.GetTypeFromProgID("myComObject")
o = System.Activator.CreateInstance(t)
o.Open("afile") <==the com object needs to open a file to be of use

The signature of the GetAValue function is defined as:

short GetAValue(short value1, short* value2)

The return value indicating success (always zero) and the second parameter being the value i’m interested in.

aNumber is always zero. The exact same script (with only changing the functions to load the com object) when ran using spyder using python 3.6 works just fine and I get a non zero value returned as expected.

Is there something I’m doing wrong here?

EDIT: I have asked the developers of the com object to confirm that the functions are being called as expected. They have debugged the code and have proved that the value is being passed in and set to a non-zero value BUT when it the function returns back to the script, it is being set back to a default value. We have both independently tried passing the value by clr reference and this just throws an error.

s= clr.Reference[int]()
o.GetAValue (0,s)

ValueError: Could not convert argument 0 for call to GetAValue

Hello @tim.rutter8KGJD
are you using DynamoStandBox?
if yes, which version Python engine are you using ?

I also posted this on the ironpython site, they solved it. I was passing clr.Reference to int when the function was expecting a short*. Using clr.Reference[System.Int16] fixed the problem.



1 Like