Page 1 of 1

DLL vensim_get_vecvals

Posted: Thu Sep 05, 2024 4:19 pm
by valen0205
Hello,

I’m currently working on a Vensim model from Python using the DLL.

I’m trying to get the values of a vector, and while the code is running, it’s not returning the correct result (it’s returning -1.2980742e+33 when the value should be 10).

Any ideas on what might be happening?

Here is a sample of the code I’m using:
import numpy as np
from ctypes import c_float, POINTER

Variable = ['A', 'B', 'C', 'D', 'E', 'F']

def GetData(Variable):
vec = np.zeros(len(Variable), dtype=np.float32)
fp = (c_float * len(Variable))(*vec)

# Retrieving the values of the variable
var = ['Offer [' + t + ']' for t in Variable]
for t in range(len(Variable)):
vec[t] = vensim_dll.vensim_get_varoff(var[t].encode('utf-8'))

vensim_dll.vensim_get_vecvals(vec.ctypes.data_as(POINTER(c_float)), fp, len(Variable))
dOffer = np.ctypeslib.as_array(fp)

return dOffer

dOffer = GetData(Variable)
print(dOffer)
Thanks in advance

Re: DLL vensim_get_vecvals

Posted: Thu Sep 05, 2024 4:28 pm
by Administrator
Always check the return value when calling into the DLL, if it returns zero, something has not worked correctly. For example, you are not checking the result of the call
vensim_dll.vensim_get_vecvals(vec.ctypes.data_as(POINTER(c_float)), fp, len(Variable))