CAD2MATDEMO is a demonstration of importing 3D CAD data into MATLAB.
The demo includes:
1) the general program,
2) 4 CAD data file samples, and
3) a simple script that executes the program to show the 4 samples.
To get CAD data into MATLAB, the process is:
1) Export the 3D CAD data as an ASCII STL (or Pro/E render SLP) file.
2) This MATLAB routine reads the CAD data, and
3) Once read, the CAD data is rotated around a bit for viewing.
The program has been tested with: AutoCAD, Cadkey, and Pro/Engineer.
It should work with most any CAD programs that can export STL files.
Format Details: STL is supported, and the color version of STL that Pro/E exports, called 'render' is also supported. The render (SLP) is just like STL but includes color.
Only that data associated with STL or SLP files are translated, e.g., geometry and the geometry color. No textures, transparencies, or other such things are exported with the STL (or SLP) file.
Note: This routine has both the import function and some basic manipulation for testing. The actual reading mechanism is located at the end of the demo file.
Don Riley (2020). CAD2MATDEMO.M (https://www.mathworks.com/matlabcentral/fileexchange/3642-cad2matdemo-m), MATLAB Central File Exchange. Retrieved .
I really like the way he visualizes the result.
Is there any toolbox for MATLAB to autocad For 3d
Thanks a lot. It works well.
Was very helpful. Thank you.
Looks fantastic! very useful
do we need any toolbox so that rndread() is understood by MATLAB?
Fantastic code for me, thanks
Great job!! It is very help for us to import 3d model into matlab.
I am having error while the matrix multiplication:
for ang = 0:1:90
nv = rx(ang)*V;
Nice job! Should I replace "AXIS" (Line 52)with "axis"?
finaly I imported STL file with your work
Work great but....why are you moving the object at the end of the script? For huge file on computer with High CPU / Low GPU it make the script x10 time longer.
Hello I am using MATLAB R2012b and run the script the image appears in 3D, but it does not set the variables of structure (S1, S2 ...), or the variables (V1, C1, N1) ... the workspace is blank, and no files. m is created. Please can someone help me? thank you
Thanks, I use it for reading STL files.
can you please help me with my problem ? I have a catia figure saved in . stl format and i want it to read in matlab . I m finding it difficult to find the function that does that
Hi, it is a nice job, please could you tell me how can I machining an stl file? Regards
A tip to automatically add a column of 1s to vertices matrix
add this line in the cad2mat function
s0.V0 = [V(:,1), V(:,2), V(:,3), ones(length(V),1)];
filename = 'Link0.stl'; % part
% Read the CAD data file:
[F, V, C] = rndread(filename);
s0=struct('F0', F,'V0', V,'C0', C);
s0.V0 = [V(:,1), V(:,2), V(:,3), ones(length(V),1)];
I have tried export a solid drawing, successfully I can see the drawing in matlab but I could not save it as mat-file. When I run the cat2matdemo It gives an error ;
Cannot find an exact (case-sensitive) match for
The closest match is: axis
Error in cad2matdemo (line 53)
AXIS([-vsize vsize -vsize vsize -vsize vsize]);
Can you please help me with the subject. I have tried R2011B and R2012a versions.
nice and awesome jobe man i just can say that you are great but, im stuck, i think i have a problem with this, because when i try to load a stl file it apears on the command windows ??? indefined function or variable "v" Error in cad2matdemo>rndread at 223 vout = v';.
i will be glad if you can give me a hand on it
very good tools!thank you
A note to SolidWorks users: be sure to export your STL files as ASCII, not binary. To do this for a solid part, hit 'saveas', choose *.stl, and go into Options. In my case, solidworks defaulted to export in binary.
i have tried to load a different 6DOF arm in to the code and bumped on problem of the initial location. How do you set what the initial location of each part before you performing the InitHome function call.
Any suggestions on the memory pre-allocation? I made several attempts unsuccesfully.
Great work indeed.This helped me in my project.
what one needs to start exporting matlab patch in CDF pre processing tools
just slow in writing the STL file
After adding some preallocation I found this code to be very simple, straightforward and robust. This example is particularly useful to me as I am writing a 3D track display and was able to write a process based on your example so that we could develop our track symbols in autocad and bring the vertices and faces into Matlab as a patch object. An amazing combination of tools. Thank you for sharing.
I strongly recommend you modify the file opening function to pre-allocate the memmory. This allow to open large model a lot faster.
This can easily be done
Exactly what I was searching for. A little bit slow, yes, but I have no Idea how to make it faster.
Great program that saved me a lot of time. Thank you for sharing!
Good demo for small models. However, it took 20 minutes to load a model of a transport vehicle.
it's very good.
great demo; easy to use. Thanks.
I WANT A MATLAB CODE FOR STL OFFSETTING(VERTEX OFFSETTING)
IN MY PROJECT I NEED TO GENERATE A 3D OBJECT WITH GIVEN OFFSET..SO PLEASE UPDATE THIS..
Works first time. Very useful, but slow for big models.
Very nicely done
I had tried it.It's work good.Nice job
This has helped me so munch. Thanks.
works great - do you have anything for performing boolean operations on stl-files? Like merging two stl-files into one? Looking for the intersection of two stl-files?
Very nice utility that seems to be working for us right out of the box. Thanks for sharing.
I have just updated the file (R2), due to a capitalization issue on some internal functions that kept the rotations from working. The demo should be working correctly now.