Updating line connection in Simulink

7 views (last 30 days)
Iliya Valchev
Iliya Valchev on 17 Apr 2020
Commented: Iliya Valchev on 21 Apr 2020
Hi,
I am trying to update the connection of a line/signal in Simulink programatically. So fat I was able to retrieve the line information using
h = get_param('some_system/some_block','PortHandles');
ln = get_param(h.LConn, 'Line');
After that I want to change the source or destination port of the line ln, but I did not find a way to do that.
What I want to achieve in the end is to put a block before/after another Simscape block and make sure that all connections from the chosen port pass through the new block which in also connected to all previously connected blocks. If I have Block_A connected to Block_B and Block_C, I want to inject Block_X between them, so Block_A is only connected to Block_X, while Block_X is connected to Block_A on LConn and to Block_B and Block_C on RConn

Answers (1)

Jyotsna Talluri
Jyotsna Talluri on 21 Apr 2020
You can do that by deleting the lines connected from Block_A to Block_B and Block_A to Block_C.Add a new block Block_X.Then add lines connecting from Block_A to Block_X,Block_X to Block_B and Block_X to Block_C.You can make use of delete_line,add_block and add_line functions respectively for the above operations
Refer to the below documentation links to know more about the functions:
  1 Comment
Iliya Valchev
Iliya Valchev on 21 Apr 2020
Yes, this sounds simple enough. With the Simscape blocks I want to connect there are branches in the lines, so I want to keep their logic. Normally it works to just delete the line from A and connect it to X, but connecting X to B,C...,Z can produce errors since there are already lines to these ports. Additionally I might want to put X "before" A, so the lines from B,C, ..., Z reach X and then X is connected to A.
So far trying to done this has been hard. Even if I use the points of the connection line, sometimes Simulink connects to the nearby port instead

Sign in to comment.

Categories

Find more on Programmatic Model Editing in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!