Attach a config set from a data dictionary to a model programmatically

I have a configuration set in a simulink data dictionary.
How can I use this config in a model?
I can check it out using
dd = Simulink.data.dictionary.open('mydict.sldd')
ds = dd.getSection('Configurations')
cf = ds.find('-class','Simulink.data.dictionary.Entry')
which is of type Simulink.data.dictionary.Entry
What do I need to do to set this as the reference configuration of a model?
There is
configRef = Simulink.ConfigSetRef;
but I cannot find any reasonable documentation on how to use in that use case.
Or is there a way to convert the entry object of the dictionary to a Simulink.ConfigSetRef object?

Respuestas (1)

9 comentarios

Marcus
Marcus el 4 de Abr. de 2025
Editada: Marcus el 4 de Abr. de 2025
No.
Please provide an example for the above scenario.
@Marcus In the following you can find an example code, which gets the Configuration object stored in a Data Dictionary and this configuratin then gets set in a configuration reference linked to a model. Please let me know what else is missing, so I can provide you any further information. I believe your code above missed the getValue method to actually get the configuration object.
% get referenced configuration from "myNewDictionary.sldd"
dictionaryObj = Simulink.data.dictionary.open('myNewDictionary.sldd');
configsSectObj = getSection(dictionaryObj,'Configurations');
entryObj = getEntry(configsSectObj,'myConfig1');
myConfig1 = getValue(entryObj);
% open the model
open_system('testcase');
% create a configuration reference
Reference = Simulink.ConfigSetRef;
% set the source name of this configuration reference as the configuration
% set in data dictionary
set_param(Reference,'SourceName','myConfig1');
% attach the referenced configuration (myConfig1) to the model
attachConfigSet('testcase',Reference)
setActiveConfigSet('testcase','Reference')
Thanks for the example. In deed the getValue was missing to get the actual configuration object.
However if I follow your example above I create a configuration object in the base workspace which ist what afterwards is being referenced in the model, i.e. in the Model Explorer Configurations View it shows "Location: base" where I want it to be "Location: myNewDictionary.sldd". How to fix that?
The following code will create a new configuration reference in a Data Dictionary which references the configuration located in the Data Dictionary. If you have questions on how to get the configuration reference located in a model, please let me know.
dictionaryObj = Simulink.data.dictionary.open('myDD.sldd');
configsSectObj = getSection(dictionaryObj,'Configurations');
allEntries = configsSectObj.find('-class','Simulink.data.dictionary.Entry');
assert(isa(allEntries.getValue,'Simulink.ConfigSet'))
nameOfConfig = allEntries.Name;
configRef = Simulink.ConfigSetRef;
set_param(configRef,'SourceName',nameOfConfig);
set_param(configRef,'Name','myConfigRef');
configsSectObj.addEntry('myConfigRef',configRef)
Marcus
Marcus el 8 de Abr. de 2025
Editada: Marcus el 8 de Abr. de 2025
Why would one want to locate a reference in the dictionary itself? What is a potential use case for that?
However, yes, I'd rather want to how to get the configuration reference located in the model instead, in such a way that it references the configuration in the data dictionary, not one in the base workspace.
I can only imagine that one could store the reference in the dictionary itself to make it easier to share this reference and directly attach it to a model in a programmatic workflow. But in my case it was just an example on how to create such objects and link them, I had no clear use case in mind.
In the following you can find the code for that, the only change was to link the model to the Data Dictionary (if this is already the case it is not needed) and then attach the configuration reference to the model:
dictName = 'myDD.sldd';
mdl = 'myExpMdl';
nameOfConfigRef = 'myConfigRef';
% dictionaryObj = Simulink.data.dictionary.open(dictName);
% configsSectObj = getSection(dictionaryObj,'Configurations');
% allEntries = configsSectObj.find('-class','Simulink.data.dictionary.Entry');
% assert(isa(allEntries.getValue,'Simulink.ConfigSet'))
%if you know the name of the Configuration you can use it directly
nameOfConfig = 'myNewDDConfig';
configRef = Simulink.ConfigSetRef;
set_param(configRef,'SourceName',nameOfConfig);
set_param(configRef,'Name',nameOfConfigRef);
set_param(mdl,'DataDictionary',dictName);
attachConfigSet(mdl,configRef);
setActiveConfigSet(mdl,nameOfConfigRef);
Marcus
Marcus el 8 de Abr. de 2025
Editada: Marcus el 8 de Abr. de 2025
So for my understanding: The only thing that links the configuration and the model ist the name of the configuration and there is no dedicated link to this particular dictionary? I.e. it is searched by its name at the common locations, if one wants it to be found in the dictionary the dictionary needs to be added to the model. Is that correct?
Yes, that is correct.
Do you have any further questions?

Iniciar sesión para comentar.

Categorías

Más información sobre Manage Design Data en Centro de ayuda y File Exchange.

Productos

Versión

R2022b

Preguntada:

el 3 de Abr. de 2025

Comentada:

el 9 de Abr. de 2025

Community Treasure Hunt

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

Start Hunting!

Translated by