MATLAB: How to add Simulink Library Block programmatically

add_blockblock pathsimulinksimulink add block programmatically

Hi,
I try to generate a Simulink model with using add_block() function programmatically. I have an issue with a block path. When I use following example everything is ok.
sys = 'testModel';
new_system(sys) % Create the model

open_system(sys) % Open the model

pos = [30 37 60 50 ];
add_block('simulink/Sinks/Scope',[sys '/In1'],'Position',pos);
But if I try to insert another blocks I get an error : There is no block named 'NI VeriStand Blocks/NIVeriStand In1'
sys = 'testModel';
new_system(sys) % Create the model
open_system(sys) % Open the model
pos = [30 37 60 50 ];
add_block('NI VeriStand Blocks/NIVeriStand In1',[sys '/In1'],'Position',pos);
I thought that the path is same like in Simulink Library Browser, but it’s wrong probably
Is there any way how to found the path to the Simulink blocks?
Thanks Jan

Best Answer

The name of the model is not the same as what shows up on the Library Browser. It just happens to be so for "Simulink", whose library file name is simulink.slx.
If you right-click the "NI VeriStand Blocks" library and select "Open NI VeriStand Blocks library", it will bring up the model file, which will tell you the actual name of the model. I can't tell you what that is since NI VeriStand is a third-party library and I don't have it.
Take this other one as an example. If you right-click your DSP System Toolbox library and open it in the above fashion, the model name (in R2015b) will be dsplibv4. Furthermore, when you click "Sources", it will open a new model called dspsrcsv4.
Bottom line: You can't tell the path of the block by looking at its user-visible name. Best thing to do is to
  1. Right-click the library and open it outside the Library Browser
  2. Navigate to, and select, the block you're interested in adding
  3. Enter gcb in MATLAB to get the exact block path you should use
- Sebastian