How to Use command to remove lines between physical models?

4 ビュー (過去 30 日間)
季
2025 年 6 月 4 日
コメント済み: 2025 年 7 月 7 日
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 件のコメント
季
2025 年 6 月 9 日
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!
季
2025 年 6 月 9 日
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.

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

採用された回答

Javier Gazzarri
Javier Gazzarri 2025 年 6 月 30 日
編集済み: Javier Gazzarri 2025 年 6 月 30 日
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 件のコメント
季
2025 年 7 月 7 日
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

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

その他の回答 (0 件)

カテゴリ

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