Code covered by the BSD License  

Highlights from
CAD2MATDEMO.M

4.69697

4.7 | 33 ratings Rate this file 105 Downloads (last 30 days) File Size: 120 KB File ID: #3642
image thumbnail

CAD2MATDEMO.M

by

 

23 Jun 2003 (Updated )

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

| Watch this File

File Information
Description

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.

Acknowledgements

This file inspired 3 D Puma Robot Demo and X Mas Tree.

MATLAB release MATLAB 6.5 (R13)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (39)
10 Jul 2014 Junjie

great work!

10 Feb 2014 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

02 Dec 2013 liguo

nice

28 Aug 2013 Emmanuel Farhi

Thanks, I use it for reading STL files.

04 Jun 2013 Scott

THANK YOU.

02 Jun 2013 Rooha Siddiqui

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

23 Apr 2013 Ali

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

24 Nov 2012 shiva

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

03 Sep 2012 Carlos  
30 Jun 2012 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.

04 May 2012 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

05 May 2011 Joachim  
08 Apr 2011 YT

very good tools!thank you

10 Mar 2011 Jeroen Vandersteen  
02 Mar 2011 William LaCava

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.

22 Jun 2009 badr Higab  
04 Apr 2009 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.

12 Mar 2009 Husam Aldahiyat  
22 Aug 2008 Greg C

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

24 Jul 2008 Sharina S

Great work indeed.This helped me in my project.

27 Mar 2008 igor scardanzan

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

09 Mar 2008 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.

12 Oct 2007 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

09 Oct 2007 Raphael Beckers

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

05 Jun 2007 Roland Lehmann

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

27 Jan 2007 abelmi ab

Look great

23 Jan 2007 Matt Donath

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

15 Jan 2007 Ha Seungwon

it's very good.

13 Dec 2006 Sebastian Held

great demo; easy to use. Thanks.

26 Aug 2006 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..

11 Jul 2006 N Q

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

06 May 2006 H O  
30 Mar 2006 S G

Very nicely done

16 Mar 2006 abelmi ab

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

17 Feb 2005 Tom Mansfield

This has helped me so munch. Thanks.

19 Dec 2004 Chris Barnhart

Works great!

10 Nov 2004 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?

12 Feb 2004 Rajeev Jain  
20 Oct 2003 Duane Nightingale

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

Contact us