Well I have found a solution. It's not very nice, but it works.
All the files can be downloded here from dropbox
Sorry, I would have liked to post an image, but I don't have 10 reputations. So you have to donwload it from the link above.
Here ist the main skript and further down is a recursif function.
The skript should also work for all other Simulin models with a bus. But just now it just works, if there ist only one busselector. But it is not much to program for several bus systems and bus selectors.
% Name_Signals_after_Blocknames
format compact, clear all, clc
cd(''); % Directory where the simulink model is safed
Simulink_Model = ('linearGuide_model.slx');
Simulink_Model = ('Verbindung.slx');
Simulink_Model = ('bus_system.slx');
% Simulink_Model = ('singlebus.slx');
[path, Model_name, ext] = fileparts(Simulink_Model);
BlockPaths = find_system(Model_name,'LookUnderMasks', 'all' ,'Type','Block');
length_Model_name = length(Model_name);
Cellofbusselector = [];
jj = 0;
for ii = 1:length(BlockPaths)
disp(BlockPaths{ii})
porthandles = get_param(BlockPaths{ii}, 'PortHandles');
outporthandles = get_param(porthandles.Outport, 'Line');
Block_Name = BlockPaths{ii};
% if length(outporthandles) > 1 % only give names to outputs of a subsystem, they are also listed in the BlockPaths cell
% warning ('more than one signal wants to get the same name, might be a Subsystem')
% else
if strcmp(BlockPaths{ii}(end-7:end), 'Selector') % you can not change the name of a line connecting a Bus Selector
disp('Here we have a Bus selector')
jj = 1+jj;
Cellofbusselector(jj) = ii;
else
if isempty(outporthandles)
warning(['Block ', Block_Name, ' has no Output'] )
elseif length(outporthandles) == 1
if outporthandles == -1 % outporthanldes == 1, when there is no signal attachet to the outport of the block
warning(['Block ', Block_Name, ' has no Output-Signal attached'] )
else
Signal_name = BlockPaths{ii}((length_Model_name+2):end);
set_param(outporthandles, 'Name', Signal_name);
end
elseif length(outporthandles) > 1
for jj = 1:length(outporthandles)
if outporthandles{jj} == -1 % outporthanldes == 1, when there is no signal attachet to the outport of the block
Block_Name = BlockPaths{ii};
warning(['Block ', Block_Name, ' has no Output-Signal attached'] )
else
Signal_name = [BlockPaths{ii}((length_Model_name+2):end), '_out', num2str(jj)];
set_param(outporthandles{jj}, 'Name', Signal_name);
end
end
end
end
% end
end % for ii = 1:length(BlockPaths)
buscell = get_param(BlockPaths{Cellofbusselector}, 'InputSignals');
[signalname, buslevel, numofsig, busname] = f_get_complete_signalnames(buscell)
%%
signalnamesize = size(signalname);
for ii = 1:signalnamesize(1)
for kk = 1:signalnamesize(2)
if isempty(signalname{ii,kk})
else
nrofbusnames = kk-1;
fullbusname = '';
for i = 1:nrofbusnames
fullbusname = [fullbusname '.' busname{i}];
end
fullsignames{ii,1} = [fullbusname(2:end) '.' signalname{ii,kk}]
end
end
end
Here is the code from the recursiv function
function [signalname, buslevel, numofsig, busname] = f_get_complete_signalnames(buscell, buslevel, numofsig, signalname, busname)
%% Description
% This function returns the complete signal names which are stored in a
% bus. The name looks something like bus1.bus2.signal1.
if nargin < 2; buslevel = 1; end
if nargin < 3; numofsig = 0; end
if nargin < 4; signalname = {}; end
if nargin < 5; busname = {}; end
buscellsize = size(buscell);
buscellsize(1); % busvert is the vertical dimension of buscell
for kk = 1:buscellsize(1)
if ischar(buscell{kk,1}) && buscellsize(2) == 1
numofsig = numofsig + 1;
signalname{numofsig, buslevel} = buscell{kk,1};
elseif ischar(buscell{kk,1}) && buscellsize(2) == 2
busname{buslevel-1} = buscell{kk,1};
[signalname, buslevel, numofsig, busname] = f_get_complete_signalnames(buscell{kk,2}, buslevel, numofsig, signalname, busname);
elseif iscell(buscell{kk,1}) && buscellsize(2) == 1
buslevel = buslevel+1;
[signalname, buslevel, numofsig, busname] = f_get_complete_signalnames(buscell{kk,1}, buslevel, numofsig, signalname, busname);
buslevel = buslevel-1;
end
end
end
I hope I made this right. And this helps somebody.