MATLAB: How to use the ADD_LINE command with SimMechanics blocks

add_lineblockscommandconnectlinemodelportssimmechanicsSimscape Multibody

The ADD_LINE command can be used to connect Simulink blocks from the command line. However, this command basically assumes that there are 'output' ports and 'input' ports. In SimMechanics this is not the case, and specifying connections in the normal way does not work.

Best Answer

SimMechanics models can be created from the MATLAB Command Line, but a special syntax is used to represent the ports. The ports should be described as 'LConn<number>' and 'RConn<number>', where 'number' indicates the position on the block. The following example creates a small sample model with two connected blocks:
 
new_system
open_system(gcs)
add_block('mblibv1/Joints/Revolute',[gcs,'/Revolute'])
add_block('mblibv1/Joints/Revolute',[gcs,'/Revolute1'])
set_param(gcb,'Position',(get_param(gcb,'Position')+[0 60 0 60]))
add_line(gcs,'Revolute/RConn1','Revolute1/LConn1')