MATLAB: How to programmatically access (and edit) bus elements

busdata dictionarysimulinksldduppercase

My project has a restriction that bus elements need to be all lowercase. The architecture has bus objects stored in data dictionaries, and the model uses these in BusCreator objects.
In order to enforce compliance with this restriction, I'd like to programmatically inspect all the buses used in a model, and/or bus objects stored in the data dictionaries. When an offending element is found, I might
  1. just print an error message,
  2. provide a dialog to help the user edit the name, or
  3. do some kind of automatic name change.
But the first issue is to identify the uppercase and camelcase bus elements.
So far, here's what has not worked for me:
1. Inspecting the BusCreator
I've tried selecting a BusCreator block which has elements that need to be corrected, then using the command
get_param(gcb,'DialogParameters')
but the result doesn't contain the bus name, much less the element names.
2. Finding Bus Definitions used by the model
This gets me a little closer; I can use
modelVariables = Simulink.findVars(bdroot,'SourceType','data dictionary')
then check each of the modelVariables.Users to see if that user block is a BusCreator; in which case the variable is probably the name of a bus object. But once I have the bus names, I still need to find the element names, and I'm stumped there.
3. Finding Bus Definitions in the SLDD
I've tried using the Simulink.data.Dictionary class methods to find bus objects' elements names, but haven't found a way to actually find the bus element names, much less edit them.
4. Model Advisor Checks
I took a brief look, but didn't see a way to customize mathworks.maab.jc_0221 Check character usage in signal labels to flag uppercase characters. I don't necessarily want to exclude uppercase on ALL signals, although doing that would probably end up helping achieve all lowercase bus elements.

Best Answer

I wanted to throw a brief update out there about what I ended up with. Thanks to Shivang Menon @ mathworks for some technical support and guidance to use arrayfun & cellfun, I ended up getting there. I won't post all the code I went through because it was scattered across several functions, but here are the key parts to accessing the element names:
sldd_object = Simulink.data.dictionary.open('filename.sldd');
section = getSection(sldd_object, 'Design Data');
entries = find(section, '-value', '-class', 'Simulink.Bus');
% produce cell array of Simulink.Bus objects:
buses = arrayfun(@(x) getValue(x), entries, 'UniformOutput', false);
% produce a cell array of cell arrays of Simulink.BusElement objects:
elements = cellfun(@(x) x.Elements, buses, 'UniformOutput', false);
% produce a cell array of cell arrays of element names:
element_names = getElementNames(elements);
function names = getElementNames(arrayOfElements)
%%getElementNames returns a cell array of element names
function names = busElementNames(busElement)
if (length(busElement)<1)
errordlg('There is a bus with zero elements. Oops.')
elseif (length(busElement)==1)
names{1}{1} = busElement.Name;
else
names = arrayfun(@(x) x.Name, busElement, 'UniformOutput', false);
end
end
names = cellfun(@busElementNames, arrayOfElements, 'UniformOutput', false);
end