create a view based on a .mldatx file.

3 views (last 30 days)
Remi
Remi on 20 Jun 2025
Answered: Deepak on 23 Jun 2025
I have 3 files :
1- Architecture view
2-Logical view
3-Allocation file .mldatx.
I would like to display a view based on the .mldatx file.
The component in the architecture view are linked to several element in the logical view.
SO far i'm able to identify which block are connected, but impossible to display those.
Or is there a better way than a script to do it ?
At first I thought using the stereotype but we can't have several value for one enum, and having the string type doesn't help because there are too much possibility.
Am i missing something ?
here is the code I did so far for the first part.
% Fichier FunctionalBlock.m
% Loading allocation file
allocationSetFile = 'FunctionToDetail.mldatx';
allocationSet = systemcomposer.allocation.load(allocationSetFile);
scenarios = allocationSet.Scenarios;
% Scenario selection
scenarioName = 'Scenario 1';
scenario = [];
for i = 1:numel(scenarios)
if strcmp(scenarios(i).Name, scenarioName)
scenario = scenarios(i);
break;
end
end
if isempty(scenario)
error('Scénario "%s" non trouvé.', scenarioName);
end
fprintf('Scénario d’allocation utilisé : %s\n', scenario.Name);
% Allocations
allocations = scenario.Allocations;
% Functional components extraction
composantsFonctionnels = systemcomposer.arch.Component.empty;
for i = 1:numel(allocations)
src = allocations(i).Source;
if isempty(composantsFonctionnels) || ~any(src == composantsFonctionnels)
composantsFonctionnels(end+1) = src; %#ok<AGROW>
end
end
% Find functional target component
nomComposantFonctionnel = 'sfa_dcl_overvoltage_trip';
composantFonctionnel = [];
for i = 1:numel(composantsFonctionnels)
if strcmp(composantsFonctionnels(i).Name, nomComposantFonctionnel)
composantFonctionnel = composantsFonctionnels(i);
break;
end
end
if isempty(composantFonctionnel)
error('Composant fonctionnel "%s" non trouvé.', nomComposantFonctionnel);
end
fprintf('Composant fonctionnel trouvé : %s\n', composantFonctionnel.Name);
% Allocated logical blocks
blocsLogiquesAlloues = systemcomposer.arch.Component.empty;
for i = 1:numel(allocations)
if allocations(i).Source == composantFonctionnel
blocsLogiquesAlloues(end+1) = allocations(i).Target; %#ok<AGROW>
end
end
fprintf('Composants logiques alloués :\n');
for i = 1:numel(blocsLogiquesAlloues)
fprintf(' - %s\n', blocsLogiquesAlloues(i).Name);
end

Answers (1)

Deepak
Deepak on 23 Jun 2025
Hi @Remi,
I understand that you are trying to display logical components allocated to an architectural component using a ".mldatx" allocation file in System Composer. The most effective way to visualize these allocations is through the Allocation Editor, which you can open via the System Composer toolbar or using the command
systemcomposer.allocation.open('filename.mldatx')
Within the Allocation Editor, selecting a component and clicking Show Allocations will visually highlight the corresponding linked components across the source and target models, enabling interactive navigation and inspection.
While your script correctly identifies allocations programmatically, for visualization purposes, you can also create a custom architecture view using "createView" and "addElement" to display just the allocated components. It is generally better to use the built-in allocation mechanism rather than stereotypes for linking, since allocations natively support many-to-many relationships. If needed, you can attach metadata to the allocations themselves using allocation stereotypes, which is more scalable than managing multi-value enums or strings on components.
Please find attached the documentation of "Allocation Editor" for reference:
I hope this helps.

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!