Attach a config set from a data dictionary to a model programmatically
Mostrar comentarios más antiguos
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)
Oliver Jaehrig
el 4 de Abr. de 2025
0 votos
Is this documentation section resolving your question?
9 comentarios
Oliver Jaehrig
el 7 de Abr. de 2025
@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')
Marcus
el 7 de Abr. de 2025
Oliver Jaehrig
el 8 de Abr. de 2025
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)
Oliver Jaehrig
el 8 de Abr. de 2025
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);
Oliver Jaehrig
el 9 de Abr. de 2025
Yes, that is correct.
Do you have any further questions?
Marcus
el 9 de Abr. de 2025
Categorías
Más información sobre Manage Design Data en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!