- Export current “plot” to “PDF” programmatically: Save Plot as Image or Vector Graphics File - MATLAB & Simulink
- Exporting a 3D figure to “PDF”, such that it is rotatable in the “PDF”: Exporting a 3D figure to PDF, such that it is rotatable in the PDF
- Import geometry to from “STL”: Import geometry from STL or STEP file - MATLAB importGeometry
Export STL to 2d PDF at multiple viewpoints
7 views (last 30 days)
Show older comments
Is there a simple function to convert .stl files to 2d .pdf or .jpeg files?
I have a large set of .stl files of 3d objects.
I want to save out these 3D objects as pdfs at different viewpoints (i.e. rotating around x axis).
Thank you.
0 Comments
Accepted Answer
Suvansh Arora
on 4 Nov 2022
In order to import “STL” file (3D image) into MATLAB you can use a customer created function in MathWorks File Exchange which can load “STL” file into MATLAB. The customer created function can be downloaded from the following link:
As you mentioned you have large set of “STL” images to convert, you can use the below mentioned code to save out the 3D objects as “PDFs” at different viewpoints (In order to use it, please download the above package first).
%% 3D Model Demo (stldemo.m)
% This file will help in saving femur.stl (3D image) same view, 7 times in 7 different pdf files.
for idx=1:7
fv = stlread('femur.stl');
%% Render
% The model is rendered with a PATCH graphics object. We also add some dynamic
% lighting, and adjust the material properties to change the specular
% highlighting.
patch(fv,'FaceColor', [0.8 0.8 1.0], ...
'EdgeColor', 'none', ...
'FaceLighting', 'gouraud', ...
'AmbientStrength', 0.15);
% Add a camera light, and tone down the specular highlighting
camlight('headlight');
material('dull');
% Fix the axes scaling, and set a nice view angle
axis('image');
view([135 35]);
exportgraphics(gcf,'test'+string(idx)+'.pdf')
close
end
Please look at the following documentations and related ML answers articles, if you face any issues:
I hope the above information helps you.
3 Comments
Suvansh Arora
on 7 Nov 2022
I had one more followup question, is there a simple argument I could add to make the pdf backgrounds black and the object white?
You can use the “exportgraphics” function to add the background colors to your “PDF”.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!