How to Use command to remove lines between physical models?

Hi,
I want to use commands to delete this line, but 'delete_line' always results err, saying "Invalid Simulink object name: 'Battery_Cell6/1'."
Could anyone help me, pls?

3 Comments

Hi Ji, which line is "this line" that you want to delete? Your syntax like this?
delete_line('modelName', 'Battery_Cell6/1', 'Bat+/1');
Have you identified the source and destination ports of the Battey_Cell6 block?
Hi Sam,
yes, I want to delete the horizontal line from Battey_Cell6 to Bat+.
I suspend cursor on the ports and identified the source port of Battery_Cell6 block as LConn1 and destination port of Bat+ as RConn1. I tried to use this syntax:
add_line(gcs, 'Battery_Cell6/1', 'Bat+/1');
delete_line(gcs, 'Battery_Cell6/1', 'Bat+/1');
but get error info: Invalid Simulink object name: 'Battery_Cell6/1'.
I can only add or delete physical model line by clicking and dragging. But I want to use command in script to do it.
Many thanks!
New discovery:
If LConn1 of Battery_Cell6 and RConn1 of Bat+ is not connected to anything, I can use this syntax to add line:
add_line(gcs, 'Battery_Cell6/LConn1', 'Bat+/RConn1');
if I connect LConn1 of Battery_Cell6 with RConn1 of Battery_Cell7 manually at first, I still can use that command above to add line, but cannot use this syntax below to delete the connected line:
delete_line(gcs, 'Battery_Cell6/LConn1', 'Bat+/RConn1');
and get this error info: Invalid line specifier.

Sign in to comment.

 Accepted Answer

Hello 季,
I am investigating the proper way to get a proper handle to the connection line you want to delete and I'll get back to you as soon as possible. In the meantime, would you kindly try this workaround and let me know if it works for you?
Best regards,
Javier
pos = get_param(gcs+"/Bat+","Position");
ori = get_param(gcs+"/Bat+","Orientation");
delete_block(gcs+"/Bat+")
delete_line(find_system(gcs, 'FindAll', 'on', 'Type', 'line', 'Connected', 'off'))
add_block("nesl_utility/Connection Port",gcs+"/Bat+", "Position", pos, "Orientation", ori)

1 Comment

Hi Gazzarri,
Thank you for the workaround proposed. I've tried it and it works!
Meanwhile I found another method to do it.
h = get_param(gcs+"/Bat+",'lineHandles');
delete_line(h.RConn);
To add line again with autorouting:
h2 = get_param(gcs+"/Bat+",'portHandles');
h1 = get_param(gcs+"/Battery_Cell6",'portHandles');
add_line(gcs, h1.LConn, h2.RConn, "autorouting",'on');
Best regards,
J

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2022b

Asked:

季
on 4 Jun 2025

Commented:

季
on 7 Jul 2025

Community Treasure Hunt

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

Start Hunting!