Programmically re-order model reference inports in Simulink

3 views (last 30 days)
When you use the model reference block in Simulink you can reorder the inputs (and outputs) of the block dynamically via dragging the input ports in a new order. This action does not change the numbering of the inports inside the referenced model.
Left: The referenced model; Right: The model reference block
Left: The referenced model (still with the same ordering of inputs); Right: The model reference with the ordering changed (via drag-drop)
Now, I want to change the ordering of the model reference block programmically. How can I do this?
I have not found anything in get_param() or get() that could be used to achieve this.
(Although, in PortConnectivity, the Position of the Port is updated when they are moved. However, the PortConnectivity is read-only access only)

Answers (1)

Fangjun Jiang
Fangjun Jiang on 17 Aug 2023
This is interesting. A user could drag and drop the ports, to a different order or even to the top, bottom or right side of the block. The port "Position" value got changed but you can't set it programmingly because it is read-only.
I don't know what is the practical benefit of moving the ports around, especially in the case that you want to do it programmingly. I knew this feature and it provides some convenience or graphical beauty when connecting blocks manually. But it could also confuse uses regarding the connection. If after all the blocks are connected correctly, a user could move (or by accidental drag and drop) the ports on the left side to a different order. It looks like that the connection has bee changed but it does not.
  1 Comment
Michael Zauner
Michael Zauner on 18 Aug 2023
My use-case is a bit exotic for it. We have a block with ~300 inputs and outputs where the port-ordering can't be changed due to backwards-compatibility. However, we do not require all inputs und outputs for every use-case. So my goal was to move the ports that are used to the top and the ones that aren't to the bottom. This way, we can connect auxilary systems easily with the "Ctrl+click" functionality (automatically creates lines between two blocks) without having to hand-wire everything.

Sign in to comment.

Categories

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

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!