Sunday, December 06, 2009

STL to IGS (IGES) Conversion

I've been trying to get my models from Sketchup into a decent file format for use with different analysis engines and for producing drawings for machining.

After a week of playing about with different options I have managed to get from Sketchup files to IGES files.
I used BRL-CAD to convert from .stl to its native format and then exported as an .igs from there.
Below is a copy of the script i used to convert a whole directory of files.

# Convert an STL file to IGES format using BRL CAD

for file in *.stl
# Add the -b option or binary format stl files (aoi,solid edge etc)
# stl-g -b ${file} ${file}.g

# Use ascii format for exports from sketchup
stl-g ${file} ${file}.g

for file in *.g
mkdir ${file}.d
g-iges -m -o ${file}.d ${file} all
cp ${file}.d/*.igs ${file}.igs
rm -rf ${file}.d

I did run into an issue or two along the way. When initially export as iges with the command g-iges -o file.igs file.g all the file produced caused every program I tried to load it with to crash with the exception of BRL-CAD which loaded it just fine. I found that when I used the -m option and export all regions to a directory of iges files the files worked. The STL files produced by the STL output plug-in for sketchup produces STL files in the ASCII format some programs may produce files in binary format, in which case you will need to add the -b option to the stl-g command. I had to use this when converting the STL files from the reprap project to iges files.

Why IGES files? Because I couldnt get STEP files. While STL files are widely supported they are mesh files that describe surfaces only. Most professional mechanical CAD packages use constructive solid geometry (CSG) techniques and don't like mesh files so much. That's not to say I couldn't load STL files into these packages but the loaded part was less useful when imported from STL as compared to IGES. An IGES file allows me to measure and convert to a solid object or more easily produce drawings for a machinist to work with.