필터 지우기
필터 지우기

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 CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by