smbCopyConnections

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - SimMechanics
Introduced first in SolidGeometry 3.2, Creation date: 2016-12-26, Last change: 2025-09-14

smb copies all existing conntections of a block to another

Description

This function does only work if both blocks B1 and B2 are in the same open subsystem!
Both blocks need to have exactly the same order of connection ports:
LConn1, LConn2, ..., RConn1, RConn2, ...


See Also: smbCreateConnection , smbCreateSG , smbCreateSGJoint , smbCreateSGNode , smbCreateStopJointC , smbCreateStopJointR , smbCreateDrive , smbCreateSineWave

Example Illustration

 missing image of smbCopyConnections (B1,B2,opt)

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

Algorithm Steps

  1. 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'.
  2. Find Local Names: The function retrieves the local names of the blocks B1 and B2 using the helper function gcsb.
  3. Remove Unconnected Lines: The function calls smbDeleteUnconnectedLines to clean up any unconnected lines in the model.
  4. Get Connected Blocks: The function retrieves the connected blocks of B1 using smbGetConnectedBlocks and stores them in variable a.
  5. Remove Duplicated Connections: The function uses unique to filter out duplicate connections from the list.
  6. Duplicate Connections: For each unique connection, the function adds a new line from B2 to the connected block using add_line with autorouting enabled.
  7. 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:

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