File Exchange

image thumbnail

CAD2MATDEMO.M

version 1.0 (120 KB) by

3D CAD data to MATLAB Converter, CAD STL to MATLAB Patch.

4.58333
48 Ratings

62 Downloads

Updated

View License

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.

Comments and Ratings (57)

thanks!

iwan gunawan

Yiwu Fang

nice

saleh

saleh (view profile)

nice.

behdad

behdad (view profile)

hurd cheng

very good

Was very helpful. Thank you.

Carlos Macedo

Looks fantastic! very useful

Malikireddy

do we need any toolbox so that rndread() is understood by MATLAB?

Yong Da

Yong Da (view profile)

Fantastic code for me, thanks

He Li

He Li (view profile)

Great job!! It is very help for us to import 3d model into matlab.

Ali Jafari

Roopam Dey

I am having error while the matrix multiplication:

for ang = 0:1:90
    nv = rx(ang)*V;
    set(p,'Vertices',nv(1:3,:)')
    drawnow

please help

Chen

Chen (view profile)

Nice job! Should I replace "AXIS" (Line 52)with "axis"?

Vibhute

Thanks
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.

Junjie

Junjie (view profile)

great work!

Aurelio

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

liguo

liguo (view profile)

nice

Thanks, I use it for reading STL files.

Scott

Scott (view profile)

THANK YOU.

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

Ali

Ali (view profile)

Hi, it is a nice job, please could you tell me how can I machining an stl file? Regards

shiva

shiva (view profile)

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)];

example:

function cad2mat(filename)
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)];
save('Link0.mat','s0');
end

Carlos

Carlos (view profile)

Soner Ulun

Hi,

 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
'AXIS'

The closest match is: axis
in C:\Program
Files\MATLAB\R2012a\toolbox\matlab\graph2d\axis.m

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.

erikmarte

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

Joachim

YT

YT (view profile)

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.

badr Higab

Alex Frid

Hi,
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.

Husam Aldahiyat

Greg C

Any suggestions on the memory pre-allocation? I made several attempts unsuccesfully.

Sharina S

Great work indeed.This helped me in my project.

igor scardanzan

what one needs to start exporting matlab patch in CDF pre processing tools
just slow in writing the STL file

Scott Burnside

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.

M Genest

Great tool

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

Raphael Beckers

Exactly what I was searching for. A little bit slow, yes, but I have no Idea how to make it faster.

Roland Lehmann

Great program that saved me a lot of time. Thank you for sharing!

abelmi ab

Look great

Matt Donath

Good demo for small models. However, it took 20 minutes to load a model of a transport vehicle.

Ha Seungwon

it's very good.

Sebastian Held

great demo; easy to use. Thanks.

SIVA PRASAD

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..

N Q

Works first time. Very useful, but slow for big models.

H O

S G

Very nicely done

abelmi ab

I had tried it.It's work good.Nice job

Tom Mansfield

This has helped me so munch. Thanks.

Chris Barnhart

Works great!

Fadi Glor

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?

Rajeev Jain

Duane Nightingale

Very nice utility that seems to be working for us right out of the box. Thanks for sharing.

MATLAB Release
MATLAB 6.5 (R13)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video