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

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.

댓글을 달려면 로그인하십시오.

 채택된 답변

Javier Gazzarri
Javier Gazzarri 2025년 6월 30일
편집: Javier Gazzarri 2025년 6월 30일

0 개 추천

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

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개)

카테고리

도움말 센터File Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

제품

릴리스

R2022b

질문:

季
2025년 6월 4일

댓글:

季
2025년 7월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by