Why does "subsystem2ssc" generate code that cannot be built using "ssc_build" if the subsystem contains further subsystems?

5 views (last 30 days)
I wanted to generate a Simscape library block for a subsystem in a model, where the subsystem contained further subsystems. Therefore I wanted to use "subsystem2ssc" to generate the SSC files for my component, place all the SSC files in a package directory, and then use "ssc_build" to make the single Simscape component for my top-level subsystem.
However, when trying to do "ssc_build" it errors with the following:
Error using ssc_build
Failed to generate 'mySSCFiles_lib'
Caused by:
Simscape file with package path 'myNestedSubsystem1' is not on MATLAB path and not in import context declared by import statements. Ensure the Simscape file is on MATLAB path or in import context. If the Simscape file is
moved or renamed, use its new package path.
In mySSCFiles.mySubsystem (line 17)
I then tried expanding every subsystem that is inside the top-level subsystem that I wanted to use "subsystem2ssc" on, and then it generated the single SSC file that I could use "ssc_build" on to build my component.
Is this a limitation of "subsystem2ssc" with nested subsystems?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 29 Feb 2024
Edited: MathWorks Support Team on 29 Feb 2024
The behaviour you are experiencing is expected as "subsystem2ssc" does not really know anything about the package hierarchy the user eventually wants to put the files in (it may not necessarily be the folder you generate the files into). So we generate the files in a flat hierarchy, which works when using a Simscape component block.
Therefore in order to run "ssc_build" or "ssc_mirror" you would have to edit paths in the files to match your intended package structure. An example of this is provided below:
If we have a subsystem called "mySubsystem" that contains two further subsystems inside, named "A" and "B", and we execute "subsystem2ssc" on "mySubsystem" we generate 3 SSC files, "mySubsystem.ssc", "A.ssc", and "B.ssc". We place these inside a package directory named "+mySSCFiles" and then want to execute "ssc_build" to generate the Simscape component for "mySubsystem". However, currently, the Components section of the "mySubsystem.ssc" file looks like the following:
components(ExternalAccess = observe)
A = A;
B = B;
So you will need to append the location of the components to the package directory they are in (even if it is the same package directory). So the following change needs to be made:
components(ExternalAccess = observe)
A = mySubsystem.A;
B = mySubsystem.B;
This limitation is mentioned on the following documentation page in the final paragraph of the "Suggested Workflows" section:
As mentioned in the above documentation "you have to edit the subcomponent paths in the generated files manually to match your intended package structure".  However, a potential alternative is to write a short script that uses "pwd" to identify the current folder name and then do a find-and-replace script that parses the generated SSC files to append the package name before the components.

More Answers (0)


Find more on Composite Components in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!