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 件のコメント
A
A 2024 年 7 月 24 日
Have you solved the issue, I too got the same error.
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 Center および File ExchangeModeling についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by