55 lines
1.8 KiB
Matlab
55 lines
1.8 KiB
Matlab
function apply_pmlsm_ansys_integration
|
|
% Persist the validated PMLSM-to-AEDT link and automatic interface setup.
|
|
|
|
projectDir = fileparts(mfilename('fullpath'));
|
|
modelFile = fullfile(projectDir, 'LEM_slx', 'PMLSM.slx');
|
|
projectFile = fullfile(projectDir, 'LinearSimulink.aedt');
|
|
backupDir = fullfile(projectDir, 'analysis_artifacts', 'backups');
|
|
backupFile = fullfile(backupDir, 'PMLSM_before_ansys_relink.slx');
|
|
|
|
assert(isfile(modelFile), 'PMLSM model not found: %s', modelFile);
|
|
assert(isfile(projectFile), 'AEDT project not found: %s', projectFile);
|
|
if ~isfolder(backupDir)
|
|
mkdir(backupDir);
|
|
end
|
|
|
|
load_system(modelFile);
|
|
closeOriginal = onCleanup(@() close_system('PMLSM', 0));
|
|
|
|
if ~isfile(backupFile)
|
|
save_system('PMLSM', backupFile);
|
|
close_system('PMLSM', 0);
|
|
load_system(modelFile);
|
|
end
|
|
|
|
blockPath = 'PMLSM/S-Function';
|
|
userData = get_param(blockPath, 'UserData');
|
|
fields = strsplit(userData, ',');
|
|
assert(numel(fields) >= 6 && strcmp(fields{1}, 'DataVer:2'), ...
|
|
'Unexpected Ansoft S-Function UserData format.');
|
|
fields{2} = projectFile;
|
|
fields{3} = 'LinearSimulink';
|
|
fields{4} = 'Simplorer2';
|
|
fields{5} = 'TR';
|
|
fields{6} = 'MDL1';
|
|
updatedUserData = strjoin(fields, ',');
|
|
|
|
set_param(blockPath, ...
|
|
'FunctionName', 'AnsoftSFunction', ...
|
|
'Parameters', '-1', ...
|
|
'UserData', updatedUserData, ...
|
|
'UserDataPersistent', 'on', ...
|
|
'OpenFcn', 'AnsoftLinkDialog();');
|
|
|
|
initCallback = [ ...
|
|
'run(fullfile(fileparts(get_param(bdroot,''FileName'')),' ...
|
|
'''setup_lem_ansys_link.m''));'];
|
|
set_param('PMLSM', 'InitFcn', initCallback);
|
|
save_system('PMLSM', modelFile);
|
|
|
|
fprintf('UPDATED_MODEL\t%s\n', modelFile);
|
|
fprintf('BACKUP_MODEL\t%s\n', backupFile);
|
|
fprintf('PROJECT_LINK\t%s\n', fields{2});
|
|
fprintf('INIT_FCN\t%s\n', get_param('PMLSM', 'InitFcn'));
|
|
end
|