Psim_GetUndefinedParameters
Usage
psim.Psim_GetUndefinedParameters();
MATLAB function
function params = psim_get_undefined_params(schFilePath)
psim = psim_get_instance();
% --- Call Python ---
out = psim.Psim_GetUndefinedParameters(schFilePath);
if ~isa(out, 'py.tuple')
error("PSIM:APIError", "Unexpected return type.");
end
% --- Extract tuple safely ---
result = double(out{1});
namesStr = string(out{2});
count = double(out{3});
err = string(out{4});
% --- Check result ---
if result == 0
error("PSIM:GetUndefinedFailed", err);
end
% --- Convert to MATLAB ---
if strlength(namesStr) == 0
params = strings(0,1);
return;
end
params = splitlines(namesStr);
params = params(params ~= "");
Python def
PSIM 2025 and above:
def Psim_GetUndefinedParameters(self, schFilePath_or_Obj):
result = 0
ErrorMessage = ""
szParameters = ""
nParamCount = 0
try:
if not self.IsValid():
ErrorMessage = "PSIM object was not loaded."
Result = 0;
return result , szParameters, nParamCount, ErrorMessage;
sch_closeFile = False
schHandle = 0
#is schFilePath a filePath or schematicID?
if isinstance(schFilePath_or_Obj, PSIM_schematic):
schHandle = schFilePath_or_Obj.value
elif isinstance(schFilePath_or_Obj, str):
schFilePath = schFilePath_or_Obj
SimOpenSchematicFileW = getattr(self.psimHandle, "SimOpenSchematicFileW")
if not SimOpenSchematicFileW:
raise AttributeError(self.VersionErrorMessage)
SimOpenSchematicFileW.restype = ctypes.c_int
# int SimOpenSchematicFileW(const wchar_t * szFileName, UINT nFlag)
schHandle = SimOpenSchematicFileW(ctypes.c_wchar_p(schFilePath), ctypes.c_int (1)); #returns 0 on error
if schHandle == 0 :
ErrorMessage = "Unable to open schematic file " + schFilePath
Result = 0;
return result , szParameters, nParamCount, ErrorMessage;
sch_closeFile =True
elif schFilePath_or_Obj is None:
ErrorMessage = "in Psim_GetUndefinedParameters function, schFilePath_or_Obj is None"
Result = 0;
return result , szParameters, nParamCount, ErrorMessage;
else:
ErrorMessage = "in Psim_GetUndefinedParameters function, schFilePath_or_Obj is of an unknown type"
Result = 0;
return result , szParameters, nParamCount, ErrorMessage;
# BOOL EXPORT SimGetUndefinedVariables3A(int nID, int* pnVariableCount, char* szVarNames, int* pnMaxBufferSize)
# get the function pointer
GetUndefinedVariables = getattr(self.psimHandle, "SimGetUndefinedVariables3A")
if not GetUndefinedVariables:
raise AttributeError(self.VersionErrorMessage)
GetUndefinedVariables.argtypes = [
ctypes.c_int, # nID
ctypes.POINTER(ctypes.c_int), # int* pnVariableCount
ctypes.c_char_p, # char* szVarNames
ctypes.POINTER(ctypes.c_int) # int* pnMaxBufferSize
]
GetUndefinedVariables.restype = ctypes.c_int # Return type
# call GetUndefinedVariables
pParameterCount = ctypes.c_int(0) # Initial value for pnVariableCount
initial_buffer_size = 1000
buffer_size = initial_buffer_size
pBufferSize = ctypes.c_int(buffer_size) # Set initial pBufferSize to buffer size
# Allocate buffer
szParameters_szValues = ctypes.create_string_buffer(buffer_size)
# Call the function
result = GetUndefinedVariables(
schHandle,
ctypes.byref(pParameterCount),
szParameters_szValues,
ctypes.byref(pBufferSize)
)
if result == 0:
if pBufferSize.value > initial_buffer_size:
initial_buffer_size = pBufferSize.value
szParameters_szValues2 = ctypes.create_string_buffer(initial_buffer_size) # Allocate memory
result = GetUndefinedVariables(
schHandle,
ctypes.byref(pParameterCount),
szParameters_szValues2,
ctypes.byref(pBufferSize)
)
if result == 0:
ErrorMessage = "in Psim_GetUndefinedParameters function: Failed to retrieve parameters."
result = 0
else:
# Retrieve the output values
nParamCount = pParameterCount.value
updated_pBufferSize = pBufferSize.value
szParameters = szParameters_szValues2.value.decode('utf-8')
result = 1
else:
ErrorMessage = "in Psim_GetUndefinedParameters function: Failed to retrieve parameters. "
result = 0
else:
# Retrieve the output values
szParameters = szParameters_szValues.value.decode('utf-8')
updated_pBufferSize = pBufferSize.value
nParamCount = pParameterCount.value
result = 1
if sch_closeFile:
CloseSchematicFile = getattr(self.psimHandle, "SimCloseSchematicFile")
if not CloseSchematicFile:
raise AttributeError(self.VersionErrorMessage)
CloseSchematicFile.restype = ctypes.c_int
# int SimCloseSchematicFile(int nSchematicID)
res = CloseSchematicFile(schHandle); #returns 0 on error
except Exception as e:
Result = 0
ErrorMessage += f"Error: {e}"
return result , szParameters, nParamCount, ErrorMessage;