Is it possible to programmatically check if a model has stale block information before saving?

조회 수: 5 (최근 30일)
I have a situation where a large number of Simulink models are processed and saved programmatically. The first attempt at this loop is structured like so:
for i=1:numel(allModels)
modelName = allModels{i};
if strcmp(get_param(modelName,'Dirty'),'on')
set_param(modelName, 'SimulationCommand','Update');
save_system(modelName);
end
end
This works, but has the negative impact of requiring a large number of sometimes costly and repetive model updates. The allModels variable is a large list of models, and the models are related by all being in a single large hierarchy (i.e., in this list there is the very top most model, and then many many layers of models below the top model, with many model reference blocks creating this entire hierarchy for the software). By updating each one, it results in the higher level models updating the lower level models many times.
I have tried several things to try to prevent these unnecessary updates. The first was to process the top model first, updating the entire hierarchy, and then saving with the optional flag like shown:
set_param(modelName, 'SimulationCommand','Update');
save_system(modelName, modelName, 'SaveDirtyReferencedModels', true);
This helped significantly,because now all of the models in the hierarchy are no longer dirty and are skipped since they were updated/saved when the top model was updated and saved.
However, there is still a situation when two models within the hierarchy reference the same utility model (i.e., a model with Total number of instances allower per top model: setting set to Multiple). In this situation, the first model referencing the utility saves the utility model, and then when the second model tries to be saved, it forces a popup like shown. I need to avoid this popup, as there could be 10s or 100s of these, and the script needs to continue without user interaction.
Is it possible to programmatically check if a model has stale block information and needs to be updated prior to trying to save?
  댓글 수: 2
Joshua Kephart
Joshua Kephart 2024년 8월 30일
I have not. It's been so long since I asked this it will take me a bit to remember what this was even a part of :D
I am pretty sure Vidip's recommendation below for the refreshBlocks function will do it, but I'll have to go back to the tool that had this problem and try it out sometime.

댓글을 달려면 로그인하십시오.

답변 (1개)

Vidip
Vidip 2024년 8월 28일
To programmatically check if a model has stale block information and if a model needs an update before saving, you can use 'Simulink.BlockDiagram.getChecksum', this function helps to determine if a model has changed since the last save, by comparing checksums. Also, you can programmatically refresh all variants, linked blocks, and Model blocks in the specified model by using 'Simulink.BlockDiagram.refreshBlocks' function.
Please refer to the below documentation links for more information:

카테고리

Help CenterFile Exchange에서 Modeling에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by