Error while using smimport

20 views (last 30 days)
Sam Hayward
Sam Hayward on 18 Nov 2020
Commented: Sam Hayward on 21 Jan 2021
I am receiving an error: 'Error using smimport_implementation' when using the 'smimport' function to import a CAD model into Simscape Multibody. I have copied the command window readout below.
Error using smimport_implementation
Workspace for block diagram 'sm_robot' was not loaded because an error occurred while loading the MATLAB-file 'C:\Program
Files\MATLAB\R2018b\bin\win64\sm_robot_DataFile.m'.
Error in smimport (line 167)
[varargout{1:nargout}] = smimport_implementation(multibodyDescriptionFile, varargin{:});
Caused by:
Error using smimport_implementation
Undefined function or variable 'sm_robot_DataFile'.
I have seen the previous answer to a similar question in 2017, but the issue that caused the error has been fixed in the release I am using: R2018b. The line in the function smimport is also line 167 not 132 as in the older question. This error is even happening with the demo XML file: sm_robot. I have checked that the data file has been generated and I can open it and view it.
How can I rectify this error so that the multibody block diagram builds without errors?

Accepted Answer

Priysha LNU
Priysha LNU on 24 Nov 2020
Hi,
Try moving to a directory whose path does not have a 'space' character.
It is best practice to avoid using spaces or any special characters in folder names used by MATLAB and Simulink. A space is present in your current path:
C:\Program Files\MATLAB\R2018b\bin\win64\sm_robot_DataFile.m'.
You may also try renaming the sm_robot_DataFile.m to smrobotDataFile.m to eliminate the occurence of underscore character "_" in the MAT file name.
Having changed the directory, make sure to run this command:
>> addpath <new path (before the .m file)>
Another approach you may try is to navigate to the model's Model Workspace in the Model Explorer in the generated model. Change the Workspace Data Source from MATLAB File to MATLAB Code. Copy the contents of the generated "sm_robot_DataFile.m" and paste it into the text area. Click Apply.
DISCLAIMER: These are my own views and in no way depict those of MathWorks.

More Answers (1)

Yatish Chandra Chitluri
Yatish Chandra Chitluri on 20 Jan 2021
Hello,
This error also occured when I'm running the code. If your problem is not resolved try the following
  1. Remove apostrophes or spaces in the file directory.
  2. Add file directory to Matlab path.
If your are having problems with Simscpae Multibody Link plugin, try replacing the .ipt or any other cad format to .step or .stl in the Datafile.m. Simply use search and replace option.
I hope this helps! Good luck!
Regards,
Yatish.
  1 Comment
Sam Hayward
Sam Hayward on 21 Jan 2021
Hi Yatish
Thanks so much for your response. I managed to solve the problem by opening the .m datafile and then opening the model workspace in the model explorer of my model file. I then changed the workspace data source from matlab file to matlab code and I copied the contents of the datafile into the block and clicked apply. This worked really well and solved my problem!
Thanks again
Sam

Sign in to comment.

Categories

Find more on Model Import in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!