Programmatically comment blocks residing in a subsystem
17 views (last 30 days)
Show older comments
Haroon Zafar
on 20 Nov 2023
Commented: Gordon
ongeveer 15 uur ago
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
1 Comment
Gordon
ongeveer 4 uur ago
This comment was flagged by Paul
@cowboy safari You might want to build the full path dynamically instead of relying on gcb. For example, use find_system with filters to locate all blocks matching your naming pattern, then loop through those paths and set the Commented parameter. That way it works no matter which subsystem they’re in.
Accepted Answer
More Answers (1)
Fangjun Jiang
on 20 Nov 2023
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.
See Also
Categories
Find more on Programmatic Model Editing 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!