Finding and accessing nested objects for export in System Composer Toolbox

2 views (last 30 days)
Hello all,
I am currently working with the System Composer toolbox and am trying to implement an export of the data. The internal export is not sufficient for me and I would like to adjust the export according to the project characteristics.
System Composer provides me with a Architecture model or its object. This can then consist of components, which in turn can contain new architectures or components. In short, these are nested objects.
Normally, I would use for example
model.Architecture.Components(1, 1).Name
to query the name of this specific component, for example. I could then repeat this for other Components(1, n...) components inside of a loop. But how do I manage to process all components of all architectures?
My idea was based on https://www.mathworks.com/matlabcentral/fileexchange/57957-set-and-get-nested-structure-object-filed-data to find all components and output them as a list of strings. This appoach follows a recursive algorithm. Of course I would have to adapt this function. Then I would know at least the path of the objects.
How can I then call these objects in a loop based on my string vector/list?
Because MATLAB does not accept
model.Architecture.('Components(1, 3).Architecture.Components(1, 2).Name')
To make matters more complicated, some objects refer back to previous objects and thus form a loop. I.e. there is no lowest level. These must therefore be systematically excluded in the above approach.
Are there any other ideas I'm overlooking or other approaches that would make exporting the properties of the objects, for example, easier?
Thanks a lot for your help.

Answers (1)

Josh Kahn
Josh Kahn on 21 Mar 2022
Edited: Josh Kahn on 21 Mar 2022
Hi there,
Hope you were able to figure out a solution that worked for you but if not, I think the find API with the AnyComponent query and the lookup API may get you the list for which you are looking.
System Composer Find with AnyComponent query constraint:
System Composer Lookup (use the paths returned from the query above):
I'd also be interested to hear what issues you ran into when using the systemcomposer.exportModel API.
Hope that helps!
Josh
  2 Comments
Benedikt Kniebel
Benedikt Kniebel on 21 Mar 2022
Hey Josh,
what I did at the end is tho write a function that queries threw all the objects in my system composer modell...
methods (Static)
function myObjList = getFromArch(model, querry)
if strcmp('Architectures', querry)
whiteList ={'Architecture'; 'Components'};
evalString = {'systemcomposer.arch.Architecture';'systemcomposer.arch.ComponentPort'; 'systemcomposer.arch.Component'};
elseif strcmp('Components', querry)
whiteList ={'Architecture';'Components'};
evalString= {'systemcomposer.arch.Component'; 'systemcomposer.arch.Architecture'};
elseif strcmp('Ports', querry)
whiteList ={'Ports'; 'Architecture'; 'Components'};
evalString = {'systemcomposer.arch.ComponentPort'; 'systemcomposer.arch.Architecture'; 'systemcomposer.arch.Component'};
elseif strcmp('Connections', querry)
whiteList ={'Connectors'; 'Architecture'; 'Components'};
evalString = {'systemcomposer.arch.Connector'; 'systemcomposer.arch.Architecture'; 'systemcomposer.arch.Component'};
else
warning('Input must be a query input.')
end
querObjList = {};
myObjList = interfaceClass.getDataFromObjects(model, querObjList, whiteList, evalString);
end
function querObjList = getDataFromObjects(obj, querObjList, whiteList, evalString)
% recursive field search
%
% pram:
% obj [in ] object to querry
% whiteList [in ] fieldnames hat need to be searched in
% evalString [in ] corresponing obj types that need to be searched in; First one always represents the type that is the actual querry
% querObjList [in; out] querried data objects that fit querry
fields = fieldnames(obj);
%find idx of fieldnames matching whiteList
idxMatch = CStrAinBP(fields, whiteList);
for posFields = idxMatch
%Get all the field names matching
field = fields{posFields};
currentField = obj.(field);
%determine if component and NOT empty
if ( any( strcmp( class(currentField), evalString)) && isempty(currentField) == 0)
numArrayComponents = numel(currentField);
for k = 1:numArrayComponents
%determine if querry: Component/Port/Connection
if strcmp(class(currentField(k)), evalString{1})
querObjList{end + 1} = currentField(k);
end
%could there be more inside of the object?
querObjList =interfaceClass.getDataFromObjects(currentField(k), querObjList, whiteList, evalString);
end
end
end
end
end % end methods (Static)
You just specify the type you like (what kind of objects: connections, ports...) and it searches for the nested objects inside your model.
So you can have:
querry = 'Components'
myCompList = getFromArch(myImportedModel, querry);
Hope that helps you or other people. If you have any questions, please don't hesitate to ask...
Josh Kahn
Josh Kahn on 22 Mar 2022
Thanks for the update! Glad that you were able to work out a solution. By the way, was there any information missing from systemcomposer.exportModel or were you just looking for a custom format?
Josh

Sign in to comment.

Categories

Find more on System Composer in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!