Invalid Simulink object name even after the object respective to the name was created

6 Ansichten (letzte 30 Tage)
Hello,
I have an issue where first I created a "From" block with a name by using add_block() function. At this step, I could see the "From" block was successfully created with the name that was provided initially. Then, when I tried to connect this "From" block to an inport by using add_line(), unfortunately, an error prompted mentioning that there is Invalid Simulink object name of the "From" block.
add_block('simulink/Signal Routing/From', [harnessName, '/', new_outs{cnt}, 'From'], 'Name', [new_outs{cnt}, 'From'], 'GotoTag', new_outs{cnt});
add_block('simulink/Sources/In1', [TestCases_path, '/', new_outs{cnt}], 'Name', new_outs{cnt});
port = get_param([TestCases_path '/', new_outs{cnt}], 'Port');
add_line(harnessName, [new_outs{cnt}, '_From', '/', num2str{cnt}], ['TestCases/', port], 'autorouting', 'on');
These lines were executed for some number of iterations denoted by 'cnt'. For the first iteration, it worked fine. However, once it came on the second iterations, the error appeared. Anyone has any idea what's going on?

Antworten (1)

Riya
Riya am 17 Jun. 2025
Hi mohd fuad sarman,
I understand that you are dynamically creating a "From" block using “add_block” function and then trying to connect it to an In1 block using add_line” function which throws the error "Invalid Simulink object name" from the second iteration onward.
The issue arises due to inconsistent or invalid block names when you're dynamically creating and connecting Simulink blocks using add_block” function and add_line” function.
You are attempting to connect a From block (which has an output port) to an In1 block (which also has an output port) — this will lead to an invalid port connection and the error you are encountering.
Another likely issue is a naming mismatch. The block name used in add_line” function doesn't match the name used when the block was created. You used “From”(no underscore) while adding the block but “_From”(with underscore) while connecting the line.
To fix this, you may consider connecting the From block to a block that receives input, like a Scope block.
Also, ensure that the block names used in add_line” function exactly match those created in add_block” function.
For further reference, here is the link to the “add_block” and “add_line” functions documentation:

Kategorien

Mehr zu Programmatic Model Editing finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by