Syntax
smbCopyConnections(B1,B2,[opt])
Input Parameter
B1 : | | Block string top copy connections from |
B2 : | | Block string to copy connections to |
opt : | | 'replace' deletes the Block B1 afterwards; default is '' |
Copyright 2016-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
This algorithm is designed to copy connections from one block (B1) to another block (B2) within the same open subsystem in a SimMechanics model. The blocks must have the same order of connection ports. The function can optionally delete the original block after copying connections.
Input Parameters
- B1: The block string from which connections are copied.
- B2: The block string to which connections are copied.
- opt: An optional parameter. If set to 'replace', the original block B1 is deleted after copying. The default value is an empty string, which means the block is not deleted.
Algorithm Steps
- Parameter Handling: The function checks if a third argument is provided. If so, it sets the option to the provided value; otherwise, it defaults to 'copy'.
- Find Local Names: The function retrieves the local names of the blocks B1 and B2 using the helper function
gcsb
.
- Remove Unconnected Lines: The function calls
smbDeleteUnconnectedLines
to clean up any unconnected lines in the model.
- Get Connected Blocks: The function retrieves the connected blocks of B1 using
smbGetConnectedBlocks
and stores them in variable a
.
- Remove Duplicated Connections: The function uses
unique
to filter out duplicate connections from the list.
- Duplicate Connections: For each unique connection, the function adds a new line from B2 to the connected block using
add_line
with autorouting enabled.
- Remove Original Block (Optional): If the option is set to 'replace', the function deletes the original block B1 and sets the position of B2 to the position of B1.
Switch Conditions
The function includes a switch statement to handle the optional 'replace' parameter:
- Case 'replace': If the option is 'replace', the function retrieves the position of B1, deletes B1, removes any unconnected lines, and sets the position of B2 to the original position of B1.
Algorithm explaination created using ChatGPT on 2025-08-19 07:13. (Please note: No guarantee for the correctness of this explanation)
Last html export of this page out of FM database by TL: 2025-09-21