Main Content

smartConnect

Auto-connect select components in model using port names or custom policy

Since R2025a

    Description

    [connectors,diag] = smartConnect(arch) auto-connects selected components in an architecture model using port names.

    example

    [connectors,diag] = smartConnect(arch,Policy=policy) auto-connects selected components in an architecture model using a custom policy.

    Examples

    collapse all

    This example shows how to connect components in the mSmartConnect.slx architecture model with default port name matching using the smartConnect function.

    model = systemcomposer.loadModel("mSmartConnect");
    conns = smartConnect(model.Architecture)
    conns=1×6 Connector array with properties:
        SourcePort
        DestinationPort
        Name
        Parent
        Ports
        Model
        SimulinkHandle
        SimulinkModelHandle
        UUID
        ExternalUID
    
    

    This example shows how to connect components in the mPortNameAmbiguous.slx architecture model that lead to diagnostic warnings.

    model = systemcomposer.loadModel('mPortNameAmbiguous');
    [conns,diag] = smartConnect(model.Architecture);
    diag
    diag = 
      MSLException with properties:
    
           handles: {[0×1 double]}
        identifier: 'systemcomposer_operations:EditorOperationsImpl:ConnectorCreationFailed'
           message: 'Unable to create connector.'
             cause: {3×1 cell}
             stack: [10×1 struct]
        Correction: []
    
    
    diag.cause{1}
    ans = 
      MSLException with properties:
    
           handles: {[0×1 double]}
        identifier: 'systemcomposer_operations:EditorOperationsImpl:CreateConnectorPortInterfaceMismatch'
           message: 'Unable to connect input port 'mPortNameAmbiguous/Y/p5'. Multiple output ports with same name are available, but their interfaces do not match.'
             cause: {}
             stack: [10×1 struct]
        Correction: []
    
    
    diag.cause{2}
    ans = 
      MSLException with properties:
    
           handles: {[0×1 double]}
        identifier: 'systemcomposer_operations:EditorOperationsImpl:CreateConnectorPortInterfaceMismatch'
           message: 'Unable to connect input port 'mPortNameAmbiguous/Z/p2'. Multiple output ports with same name are available, but their interfaces do not match.'
             cause: {}
             stack: [10×1 struct]
        Correction: []
    
    
    diag.cause{3}
    ans = 
      MSLException with properties:
    
           handles: {[0×1 double]}
        identifier: 'systemcomposer_operations:EditorOperationsImpl:CreateConnectorPortInterfaceMismatch'
           message: 'Unable to connect input port 'mPortNameAmbiguous/Y/p1'. Multiple output ports with same name are available, but their interfaces do not match.'
             cause: {}
             stack: [10×1 struct]
        Correction: []
    
    

    Input Arguments

    collapse all

    Architecture, specified as a systemcomposer.arch.Architecture object.

    Custom connection policy, specified as a systemcomposer.arch.SmartConnectPolicy object. For more information on creating custom policies, see Smart Connect Ports by Custom Policy.

    Output Arguments

    collapse all

    Created connections, returned as an array of systemcomposer.arch.Connector or systemcomposer.arch.PhysicalConnector objects.

    Diagnostics, returned as an MException object. For more information, see Error Handling in Simulink Using MSLException Objects.

    More About

    collapse all

    Version History

    Introduced in R2025a