Title: Problem in passing an array in win32COM object in python
Tags: python;vba;windows;win32com
Question: I am using win32com.client in Python to mimic a vba method of OpenStaad Api of StaadPro.
Method of vba is:
Dim memb As Long
Dim Lcase As Long
Dim endDis As Long
Dim LoctoGlb As Long
Dim eForce(0 To 5) As Double
objOpenSTAAD.Output.GetMemberEndForces(memb, endDis, Lcase, eForce, LoctoGlb)
Variable eForce is the output from this method, which is an array. Results are:
result1 = eForce(0), result2 = eForce(1), result3 = eForce(2), etc.
Code I have written in Python is:
import win32com.client
os = win32com.client.GetActiveObject(&quot;StaadPro.OpenSTAAD&quot;)
output = os.Output
output._FlagAsMethod(&quot;GetMemberEndForces&quot;)
memb = 1
endDis = 0
lcase = 1
eforce =[]
loctoglb = 0
output.GetMemberEndForces(memb, endDis, lcase, eforce, loctoglb)
This basically does not execute. Please tell me how an array declaration (which will be an output) is passed to a COM object in Python and how to extract its values.
Comment: Maybe take a look here: https://stackoverflow.com/questions/1062129/python-win32-com-how-to-handle-out-parameter. Basically you set a variable to the result of the function. I think it requires early binding (makepy) to work.



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2021:00:12/17/21', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<python><vba><windows><win32com>', 'Title': 'Problem in passing an array in win32COM object in python', 'ViewCount': 154, 'id': 70392633, 'user_AboutMe': None, 'user_AccountId': 19758506.0, 'user_DisplayName': 'Jukti Pratim Saikia', 'user_Reputation': 13.0, 'user_Views': 1.0, 'user_id': 14468237.0}}