Replaces a component in the circuit with another component from the database.

Syntax


ReplaceComponent ( _
       ByVal componentName As String, _
       ByVal sectionName As String, _
       ByVal sourceDatabase As MultisimDB, _
       ByVal sourceGroup As String, _
       ByVal sourceFamily As String, _
       ByVal sourceName As String, _
       ByVal modelName As String) _
       As String

Parameters

componentName—The RefDes of the component to be replaced. If the component does not exist, then an error occurs. Use EnumComponents to get a complete list of available components.

sectionName—The name of the section, for multi-section components, otherwise an empty string (""). Use EnumSections to get a complete list of available sections.

sourceDatabase—The database from which to retrieve the new component, as defined by the enumeration enum MultisimDB.

sourceGroup—The database group for the new component, for example, Sources, Basic, Diodes.

sourceFamily—The database family for the new component, for example, DIODE, ZENER, SCR.

sourceName—The component name of the replacement, for example, 1N3064, 1N4002.

modelName—If the new/replacement component has multiple models, modelName is used to specify which one to use. An empty string, "", uses the default model. This is the first model listed in the Select a Component dialog box if you are running Multisim interactively. Include the model name(id) only, not the manufacturer. For example, use "1N5712", not "Motorola/1N5712".

Remarks

The string returned contains the new RefDes of the replacement component. It may or may not be the same as the original RefDes.

Component replacements may not always have the expected result - they should be tested in an interactive session of Multisim to make sure that the behavior is as expected. Also, it is recommended that a component be replaced with another of the same type.

The combination of componentName and sectionName specifies which component to replace. Leave sectionName blank for single-section components. If a matching component cannot be found, an error occurs.

The combination of sourceGroup, sourceFamily and sourceName is a "path" to the desired target component in the database. If a matching component cannot be found corresponding to these parameters, an error occurs.

Attempting to replace a component while a simulation is running causes an error. The simulator must be in the stopped state.

Inputs and outputs should be enumerated again after making replacements to ensure an accurate list.

Notes

  • Not every component in the database is a valid source or target for ReplaceComponent. This includes special components, such as power sources and grounds.
  • This function cannot be used to replace RLC components. Instead, change the value of an RLC component with the RLCValue property.
  • The sectionName parameter must be specified if the component to be replaced is multi-section.
  • When replacing a multi-section component with another multi-section component, ReplaceComponent attempts to keep the section name the same. For example, if the original component was section C , it will be replaced by another section C if possible. If section C does not exist in the new component, the default section, typically A, will be used.
  • If the pin names in the current and new components do not match, the nets will be lost, which also happens in an interactive session of Multisim. This may be desirable if a 5-terminal opamp is being replaced with a 3-terminal opamp. The power supply connections will be lost, but they are not being modeled in the 3-terminal opamp, so there is no effect on simulation. However if the current diode has pins named A and K, and the new one has pins named 1 and 2, the resulting circuit may not provide meaningful results.

Example


' Replace all available sections of opamp U1 with another opamp from the master database


On Error GoTo ErrorHandler


sections = Circuit.EnumSections("U1")
Dim section As Variant


For Each section In sections
       Dim newRefDes As String
              newRefDes = Circuit.ReplaceComponent("U1", _
                     section, _
                     MultisimInterface.MultisimDB.MultisimMasterDB, _
                     "Analog", _
                     "OPAMP", _
                     "MC1458SU", _
                     "MC1458S" )
Next


' Replace a diode with a different one, using the default model


Dim newRefDes As String
newRefDes = Circuit.ReplaceComponent("D1", _
                     "", _
                     MultisimInterface.MultisimDB.MultisimMasterDB, _
                     "Diodes", _
                     "DIODE", _
                     "1N5712", _
                     "" )


ErrorHandler:
       MsgBox Circuit.LastError