Skip to main content

PsimWriteGraphFile

Usage

psim.PsimWriteGraphFile();

Python Help

py.help(psim.PsimWriteGraphFile)

Python def

def PsimWriteGraphFile(self, graphFilePath, ColCount, RowCount, Names, Curves):
if not self.IsValid():
print("PSIM object was not loaded.")
return 0
grf = 0
result = 0
try:
SaveGraph = getattr(self.psimHandle, "GraphSaveToFile_AllFormats_Ref")
if not SaveGraph:
raise AttributeError(self.VersionErrorMessage)

ReleaseSimulationGraphRef = getattr(self.psimHandle, "ReleaseSimulationGraphRef")
if not ReleaseSimulationGraphRef:
raise AttributeError(self.VersionErrorMessage)


grf = PSIM.__private_MakeGraph(self, ColCount, RowCount, Names, Curves)
if(grf > 0):
#int EXPORT GraphSaveToFile_AllFormats_Ref(const wchar_t* szGraphFile, int nGraphRef, wchar_t * szError)
# // char * szError must allocate 1000 bytes in calling function

SaveGraph.restype = ctypes.c_int
# Argument types
SaveGraph.argtypes = [
ctypes.c_wchar_p,
ctypes.c_int,
ctypes.c_wchar_p
]

# Prepare the buffer for szError
szError = ctypes.create_unicode_buffer(1000)

# Call the function
result = SaveGraph(graphFilePath, grf, szError)
if(result == 0):
print(szError.value)

ReleaseSimulationGraphRef(ctypes.c_int(grf))

except Exception as e:
print(f"Error: {e}")
return result

def __private_MakeGraph(self, nColCount, nRowCount, Names, Curves):
GraphMake = getattr(self.psimHandle, "GraphMakeRef")
if not GraphMake:
raise AttributeError(self.VersionErrorMessage)
GraphMake.restype = ctypes.c_int

# Argument types
GraphMake.argtypes = [
ctypes.c_int,
ctypes.c_int,
ctypes.POINTER(ctypes.c_wchar_p),
ctypes.POINTER(ctypes.POINTER(ctypes.c_double)),
ctypes.POINTER(ctypes.POINTER(ctypes.c_byte))
]

temp_val_bufs = []

ppNames = (ctypes.c_wchar_p * nColCount)()
ppValues = (ctypes.POINTER(ctypes.c_double) * nColCount)()
for i in range(0, nColCount):
ppNames[i] = Names[i]
curve = Curves[i]
if isinstance(Curves[i], ctypes.POINTER(ctypes.c_double)):
nRowCount_1 = nRowCount
ppValues[i] = curve
elif isinstance(curve, PSIM_curve):
nRowCount_1 = curve.Rows
ppValues[i] = curve.Values
else:
nRowCount_1 = len(curve)
arr_type = ctypes.c_double * nRowCount_1
arr = arr_type(*curve)
temp_val_bufs.append(arr)
ppValues[i] = arr
ppValidState = None;

# Call the function
grf = GraphMake(nColCount, nRowCount, ppNames, ppValues, ppValidState)

return grf