フィルターのクリア

Programmatically comment blocks residing in a subsystem

1 回表示 (過去 30 日間)
Haroon Zafar
Haroon Zafar 2023 年 11 月 20 日
回答済み: Haroon Zafar 2023 年 11 月 24 日
Hi,
I am trying to programmatically comment some subsystem blocks in my model. Here I have shown a simplified version of in the attached model file. ( actual number of subsystem block is in 100s)
Subsytem1 has: E7kW_Medium Range1, E7kW_Long Range1
Subsytem2 has: E7kW_Medium Range2 , E7kW_Long Range2
clc
clear all
open_system('Commenting_Programmatic')
Num_7L=2
Num_7M= 2
Status_7L= 'on'; % Comment status
Status_7M= 'on';
for kk= 1: Num_7L
set_param([gcb,'/E7kW_Long Range',num2str(kk),''],'Commented',Status_7L)
end
for ll= 1: Num_7M
set_param([gcb,'/E7kW_Medium Range',num2str(ll),''],'Commented',Status_7M)
end
E7kW_Medium Range1 gets commented out, but E7kW_ Medium Range2 ( residing in Subsystem2) gives error , as the gcb still reads the previous location w.rt Subsystem1.
If I put the EV subsystem in model root, then commenting works fine. But how can I get address of the block when it is residing in separate subsystems?
Thanks,
Haroon

採用された回答

Haroon Zafar
Haroon Zafar 2023 年 11 月 24 日
Corrected code with asociated simulink file is here:
clc
clear all
load_system('Commenting_Programmatic')
Num_7L=2
Num_7M= 2
Status_7L= 'on'; % Comment status
Status_7M= 'off';
for kk= 1: Num_7L
EV_7L_names= strcat('E7kW_Long Range',num2str(kk));
fullnames= getfullname(Simulink.findBlocks('Commenting_Programmatic','Name',EV_7L_names));
path= string(fullnames);
set_param(path,'Commented',Status_7L)
end
for ll= 1: Num_7M
EV_7M_names= strcat('E7kW_Medium Range',num2str(ll));
fullnames= getfullname(Simulink.findBlocks('Commenting_Programmatic','Name',EV_7M_names));
path= string(fullnames);
set_param(path,'Commented',Status_7M)
end

その他の回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2023 年 11 月 20 日
If doing it programmingly, never use "gcb" or "gcs". Instead, use the full block path like "RootModelName/SubSystemName/BlockName". If the "SubSystemName" is varying, then use find_system() to find the SubSystem block and get its name.
  1 件のコメント
Haroon Zafar
Haroon Zafar 2023 年 11 月 24 日
Thanks for the comment. But I was not able to find the specific varying subsystem name using find_system.
Though Simulink.findBlocks did the job.
Corrected code with asociated simulink file is here:
clc
clear all
load_system('Commenting_Programmatic')
Num_7L=2
Num_7M= 2
Status_7L= 'on'; % Comment status
Status_7M= 'off';
for kk= 1: Num_7L
EV_7L_names= strcat('E7kW_Long Range',num2str(kk));
fullnames= getfullname(Simulink.findBlocks('Commenting_Programmatic','Name',EV_7L_names));
path= string(fullnames);
set_param(path,'Commented',Status_7L)
end
for ll= 1: Num_7M
EV_7M_names= strcat('E7kW_Medium Range',num2str(ll));
fullnames= getfullname(Simulink.findBlocks('Commenting_Programmatic','Name',EV_7M_names));
path= string(fullnames);
set_param(path,'Commented',Status_7M)
end

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgrammatic Model Editing についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by