enter code hereIs there a way to create (multidimensional) arrays in Python, without pre-populating these arrays with data?
Specifically I'm looking for something equivalent to the Ironpython solution I found here :
import clr
from System import Array,Boolean,Double
from System.Activator import CreateInstance
a=clr.Reference[Array[str]](Array[str](('')))
b=clr.Reference[Array[float]](Array.CreateInstance(Double,0))
I tryed with ctypes (e.g. a=(c_double*2*3)() ) but this way arrays are prepopulated with zeros. Any idea?
The problem is that I have a COM object with an API which functions are something like:
ret=function(var1,var2,var3,...)
where var1,var2,var3 are multidimensional arrays to be filled by values. If I use Ironpython I can communicate with the COM object via the System module like:
from System.Type import GetTypeFromProgID
from System.Activator import CreateInstance
# Create Sap2000 object
sap = CreateInstance(GetTypeFromProgID("Sap2000.SapObject"))
and then I solve my problem by building var1, var2, var3 with clr.Reference...
With CPython I used the win32com.client module to communicate with the COM object but now I don't know how to build the var1, var2, var3 so that they work in the function.
Thanks,
HERE'S THE CODE:
import win32com.client
from ctypes import*
def Sap2000():
sap,SapModel=OpenSap2000(Visible = True)
NewModel(SapModel)
#define material property
ret = SapModel.PropMaterial.SetMaterial("CONC", 2) #MATERIAL_CONCRETE)
#assign isotropic mechanical properties to material
ret = SapModel.PropMaterial.SetMPIsotropic("CONC", 3600, 0.2, 0.0000055)
#create model from template
ret = SapModel.File.New2DFrame(0, 3, 124, 3, 200) # 0=PortalFrame
#run analysis
ret = SapModel.File.Save("C:\SapAPI\xy.sdb")
ret = SapModel.Analyze.RunAnalysis
#clear all case and combo output selections
ret = SapModel.Results.Setup.DeselectAllCasesAndCombosForOutput
#set case and combo output selections
ret = SapModel.Results.Setup.SetCaseSelectedForOutput("DEAD")
#get point displacements
# Arrays passed by ref
#Obj=clr.Reference[Array[str]](Array[str](('')))
Obj=[[""]]
#Elm=clr.Reference[Array[str]](Array[str](('')))
Elm=[[""]]
#LoadCase=clr.Reference[Array[str]](Array[str](('')))
LoadCase=[[""]]
#StepType=clr.Reference[Array[str]](Array[str](('')))
StepType=[[""]]
#StepNum=clr.Reference[Array[float]](Array.CreateInstance(Double,0))
StepNum=(c_double*3*2)()
#U1=clr.Reference[Array[float]](Array.CreateInstance(Double,0))
U1=(c_double*3*2)()
#U2=clr.Reference[Array[float]](Array.CreateInstance(Double,0))
U2=(c_double*3*2)()
#U3=clr.Reference[Array[float]](Array.CreateInstance(Double,0))
U3=(c_double*3*2)()
#R1=clr.Reference[Array[float]](Array.CreateInstance(Double,0))
R1=(c_double*3*2)()
#R2=clr.Reference[Array[float]](Array.CreateInstance(Double,0))
R2=(c_double*3*2)()
#R3=clr.Reference[Array[float]](Array.CreateInstance(Double,0))
R3=(c_double*3*2)()
ret = SapModel.Results.JointDispl("ALL", GroupElm, NumberResults, Obj, Elm, LoadCase, StepType, StepNum, U1, U2, U3, R1, R2, R3)
print ret
def OpenSap2000(Units='kN_m_C',Visible = False,FileName=''):
# Create Sap2000 object
sap = win32com.client.Dispatch("Sap2000.SapObject")
# Start application
ret=sap.ApplicationStart(6,Visible,FileName)
print ret
SapModel=sap.SapModel
return sap,SapModel
def NewModel(SapModel,Units='kN_m_C'):
# Initialize new model
#SapModel=sap.SapModel
u=SetUnits(Units)
ret = SapModel.InitializeNewModel(u)
# New blank model
ret = SapModel.File.NewBlank()
return
if __name__=="__main__":
Sap2000()
It fails calling the SapModel.Results.JointDispl(..) function.
File "C:\Python26\Lib\site-packages\win32com\client__init__.py", line 456, in ApplyTypes self.oleobj.InvokeTypes(dispid, 0, wFlags, retType, argTypes, *args), TypeError: Objects for SAFEARRAYS must be sequences (of sequences), or a buffer object.