I just finished writing this thing. Its soo awesome. i can't even believe it my self. There is still one more thing that I want to do with it because it repeats lines at the moment. But I'm still going to release it just for coolness. I'll clean it up later and fix up the duplicated lines.
For now, get an STl file from PRo/e or some other ASCII STL producing program. I wonder if Blender has that. If not I'm going to have to import the binary STl files too..darn.
here it goes.... have fun...
#!/usr/local/bin/perl -w
##############################################################################
# STL to GEO exporter
# This is a product of Alfonso Medina
# I'm releasing this under the copyleft, free as in free beer
# Follow whatever rules you want to follow and copy what ever you want to copy
# All I ask is that you keep it free and keep my name some where on the title
# Just you know Glory.
##############################################################################
#some of these lines and their descriptions are completly off because I rewrote the whole thing today.
#it works, i just tried an 80,000 vertex stlfile
#it will spit out a geo file containing, points, lines, line loops and planes
#all you got to do is make a virtual surface for the walls and the inlets and outlets.
#have perl installed and save this as "STL_GEO.pl"
#have your stl file in the same folder and call it "infile.stl"
###############################################################################
use strict;
use warnings;
#######
#global vars go here
our $stlin = "infile.stl";# file to be exported, replace with *.stl later
our $geoout = "outfile.geo";# output file, replace with *.geo later
our $sorter = "sort.txt";# Lines, lines loops and planes are written here first
our @lines = ();# where the initial file goes
our @lin= (); # this is used to keep the current number for points inside lines
our $i=1;#point counting. number given to points
our $j=1;#line step counter count 3 points per plane
our $k=1;#line counter. number given to lines
our $m=1;#line loop and plane counter. number shared betwix line loops and planes since they are sequencial and non overlapping.
our @linps = ();#array of points to make lines from at every 3 counts
our %seen = ();#stores points that have been seen before and in the order read
our %points = ();#stores all points in the order read
our %data = ();
our %ldata = ();
#######
open(INFILE,"$stlin") or die "Cannot open '$stlin': $!";
@lines = <INFILE>;
close(INFILE);
open(PTFILE,">$geoout") or die "Cannot open '$geoout': $!";#so we open the output file for initial output
print PTFILE "lc=0.1;\n";
####################################################################################
foreach my $line (@lines) { #read three points and place them in a file
if ($line =~ /vertex\s(\S*)/ ) { #if it looks like a point containing line
$line =~ /vertex\s(\S*)\s(\S*)\s(\S*)/; #grab point coordinates
# print $1;
%data = (
"point$i" => {
"x" => "$1",
"y" => "$2",
"z" => "$3",
}
);
next if $seen{"$1$2$3"}++;
print PTFILE "Point($i) = {", $data{"point$i"}{"x"},",", $data{"point$i"}{"y"},",", $data{"point$i"}{"z"},", lc};\n";
my $done = "$1$2$3";
$ldata{$done} = "$i";
#print $ldata{$done},"\n";
$i++;
}
}
#######################
#open(PTFILE,">$geoout") or die "Cannot open '$geoout': $!";#so we open the output file for final print
########################
foreach my $line (@lines) {
if ($line =~ /vertex\s(\S*)/ ) { #if it looks like a point containing line
$line =~ /vertex\s(\S*)\s(\S*)\s(\S*)/; #grab point coordinates
my $done = "$1$2$3";
#print $ldata{$done},"\n";
$lin[$j] = $ldata{$done};
#print "$done\n";
if ($k >= 3) { #if three points have been tested
# Point(2) = {0.754907,0.505602,0,0.05};
# Line(6) = {6,7};
# Plane Surface(26) = {25};
# Line Loop(27) = {13,10,11};
print PTFILE "Line(",$j-2,") = {",$lin[($j-2)],",",$lin[($j-1)],"}\;\n";
print PTFILE "Line(",$j-1,") = {",$lin[($j-1)],",",$lin[($j)],"}\;\n";
print PTFILE "Line(",$j,") = {",$lin[($j)],",",$lin[($j-2)],"}\;\n";
print PTFILE "Line Loop(",$m,") = {",$j-2,",",$j-1,",",$j,"};\n";
print PTFILE "Plane Surface(",$m+1,") = {",$m,"};\n";
$k=0;
$m++;
}
$j++;
$k++;
}
}
#######################
print "size of array: " . @lines . ".\n";
close(PTFILE);