Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
-
Deepak Singh
- Posts: 6
- Joined: Wed Feb 14, 2024 2:48 pm
Post
by Deepak Singh » Tue Feb 20, 2024 4:05 pm
The following is the code i wrote in matlab and it updates and saves the file and i can see the script change as well when i open the new .osim file in Notepad however the file doesn't open in OpenSim.
Code: Select all
clear
clc
import org.opensim.modeling.*
% Constructing Filepaths of osim Model and CAD stl file:
Filepath = "J:\temp\Deepak\OpenSim\Models\ImportGeomertyTrial\Gait2354_Simbody";
Modelfilename = "gait2354_simbody.osim";
CADfilename = "afoPlate.stl";
Modelfilepath = fullfile(Filepath, Modelfilename)
CADfilepath = fullfile(Filepath, CADfilename)
% Opening osim Model as a Model Class:
HumanBodyModel = Model(Modelfilepath)
% Opening CAD stl file as a Body Class:
CADpart = Body()
%CADpart.RenameType(extractBefore(CADfilepath, "."))
CADpart.attachGeometry(Mesh(CADfilepath))
CADpart.scaleAttachedGeometry(Vec3(2))
% Adding CAD stl Body class into osim Model Class:
HumanBodyModel.addBody(CADpart)
% Saving combined Model:
combinedModelFilename = strcat(extractBefore(Modelfilename, "."), "_with_", extractBefore(CADfilename, "."), ".osim")
HumanBodyModel.print(fullfile(Filepath, combinedModelFilename))
Tags:
-
Deepak Singh
- Posts: 6
- Joined: Wed Feb 14, 2024 2:48 pm
Post
by Deepak Singh » Fri Feb 23, 2024 7:35 am
Thank you so much for your response! After considering your reply and making changes to the code this is what i have:
Code: Select all
%References:
% https://simtk.org/plugins/phpBB/viewtopicPhpbb.php?f=91&t=11924&p=37599&start=0&view=
% https://simtk.org/plugins/phpBB/viewtopicPhpbb.php?f=91&t=17581&p=0&start=0&view=&sid=213c74f2deb6d15e507c592c14b4bb4d
% https://github.com/opensim-org/opensim-core/blob/main/Bindings/Java/Matlab/Dynamic_Walking_Tutorials/Dynamic_Walker_Builder/buildWalker_Complete.m
clear
clc
import org.opensim.modeling.*
%% Constructing Filepaths of osim Model and CAD stl file:
Filepath = "J:\temp\Deepak\OpenSim\Models\ImportGeomertyTrial\Gait2354_Simbody"
Modelfilename = "gait2354_simbody.osim"
CADfilename = "afoPlate.stl"
Modelfilepath = fullfile(Filepath, Modelfilename);
CADfilepath = fullfile(Filepath, CADfilename);
%% Opening osim Model as a Model Class:
HumanBodyModel = Model(Modelfilepath);
%% Get a reference to the ground object
ground = HumanBodyModel.getGround();
%% Opening CAD stl file as a Body Class:
CADpart = Body();
CADpart.setName(extractBefore(CADfilename, "."));
CADpart.setMass(20);
CADpart.setInertia(Inertia(1,1,1,0,0,0));
CADpart.attachGeometry(Mesh(CADfilepath));
%CADpart.scaleAttachedGeometry(Vec3(2))
%% Adding CAD stl Body class into osim Model Class:
HumanBodyModel.addBody(CADpart)
%% Finalizing everything:
HumanBodyModel.finalizeConnections();
%% Initialize the System (checks model consistency).
HumanBodyModel.initSystem();
%% Saving combined Model:
CombinedModelFilename = strcat(extractBefore(Modelfilename, "."), "_with_", extractBefore(CADfilename, "."), ".osim")
HumanBodyModel.print(fullfile(Filepath, CombinedModelFilename));
if ans==1
display(['Combined File Saved Successfully!']);
else
display(['There is an error. File didn''t save']);
end
Now the file gets saved and the model opens in OpenSim as well, however, i can't see the model even though i can see everything in Navigator and Topology View.
-
Deepak Singh
- Posts: 6
- Joined: Wed Feb 14, 2024 2:48 pm
Post
by Deepak Singh » Fri Feb 23, 2024 3:48 pm
Thank you, Dr. Uchida! I am facing some interesting issues still:
1. When i import a simpler CAD file "afoPlate.stl" (73 KB), the model opens and i can visualize everything.
2. When i open a more compelx CAD file "Fuselage_Tail_D311_1.stl" in my case (877,525 KB), I can't see anything.
3. I am using OpenSim 4.3 in Windows.
4. I can send you a zip file with everything over your email if you would like to help troubleshoot since i can't attach large files here.