Page 1 of 2
Any command line tool for scaling STLs in X&Y axis 7%?
Posted: Thu Nov 26, 2015 9:34 am
by swbluto
I need to increase the size of my STLs by 7% in the x-axis and y-axis to compensate for the 7% shrinkage my replicator 3d printers exhibit. Is there an app that will do this? Doesn't necessarily need to have batch processing abilities (Would be nice), just needs to be able to call some kind of STL scaling app from the command line (I can implement batch processing through a GUI frontend if there's a command line utility I can use on the backend.).
Kind of looking for anything like ImageMagick (A swiss army knife command line tool for modifying images), except for STLs instead of images.

Re: Any command line tool for scaling STLs in X&Y axis 7%?
Posted: Thu Nov 26, 2015 1:44 pm
by ednisley
swbluto wrote:Is there an app that will do this?
Something like:
openscad -D "fudge=[1.07,1.07,1.00]" -D filename="whatever.stl" -o "whatever-scaled.stl" rescale.scad
With rescaled.scad containing:
Code: Select all
filename = "dummy.stl";
fudge = [1.00,1.00,1.00];
scale(fudge) import(filename);
That's not quite correct (and, if you're using Windows, isn't the right batch format and lacks the right quoting), but it should get you started. I used OpenSCAD in batch mode to rework STL files into chocolate mold plates, so that writeup should help:
http://softsolder.com/2014/02/17/chocol ... are-stack/
If you have really intricate STL files, OpenSCAD will take quite a while to chew through them and may fall over dead after eating all available RAM, but if it works, you're done.
Plus, because it's Free Software, you can improve it as much as you like.
Re: Any command line tool for scaling STLs in X&Y axis 7%?
Posted: Thu Nov 26, 2015 5:14 pm
by swbluto
Hmmm... luckily for me, I have all the original SCADs so rescaling them would be a cinch. The downside is that I have 2000+ scads to rerender, took a good 2 days the last time I tried. (And, yes, I paralleled that shizniz on 7 different threads on my 8 core processor. Had to leave at least one core for me, lol.)
So, I'm looking at the STL files and the format seems simple enough.
facet normal 0 -1 -0
outer loop
vertex -18.8263 -2.59997 9
vertex -19.8987 -2.59997 0
vertex -18.8263 -2.59997 0
endloop
endfacet
facet normal -0.0410955 -0.999155 0
outer loop
vertex -18.8263 -2.59997 0
vertex -18.2473 -2.62378 9
vertex -18.8263 -2.59997 9
endloop
endfacet
facet normal -0.0410955 -0.999155 -0
outer loop
vertex -18.2473 -2.62378 9
vertex -18.8263 -2.59997 0
vertex -18.2473 -2.62378 0
endloop
endfacet
Probably should look at the STL documentation, but I'd surmise the facet is defining the normal vector (The fact its length is always equal to 1 suggests this.), and the numbers next to the vertex line are the x,y and z positions of the point. So to scale by 7% in the X and Y, all I'd really have to do is multiply all those vertex X & Y numbers by 1.07, right? Should be a piece of cake, just wondering if there's any gotchas I'll encounter in the wooly world of STL files.
Re: Any command line tool for scaling STLs in X&Y axis 7%?
Posted: Thu Nov 26, 2015 5:43 pm
by jsc
Slic3r and Simplify3D can scale your models in any axis independently.
Re: Any command line tool for scaling STLs in X&Y axis 7%?
Posted: Thu Nov 26, 2015 7:10 pm
by swbluto
jsc wrote:Slic3r and Simplify3D can scale your models in any axis independently.
You can scale it in S3D, but you must use the GUI as it offers no command line functionality. Not useful when I have to rescale 2000+ models.
Slic3r offers command line functionality, but doesn't scale each axis independently. It scales all the axes using the same factor.
Re: Any command line tool for scaling STLs in X&Y axis 7%?
Posted: Thu Nov 26, 2015 7:32 pm
by swbluto
Okay, took about 15 minutes to write this c# code. Haven't tested it yet, but looks like it should work. Might have to string format the doubles to comply with STL specs, but let's see if I can get away with it.
Code: Select all
DirectoryInfo d = new DirectoryInfo(p);
dl("Got directory info:" + d.FullName);
string newln = "";
StringBuilder outlns = new StringBuilder();
foreach (var file in d.GetFiles("*.stl"))
{
string[] con = File.ReadAllLines(file.FullName);
foreach (String ln in con)
{
newln = "";
if (ln.Contains("vertex"))
{
string[] prts = ln.Trim().Split(' ');
if (prts[0].Contains("vertex"))
{
double x, y, z;
Double.TryParse(prts[1], out x);
Double.TryParse(prts[2], out y);
Double.TryParse(prts[3], out z);
double newx = x * STL_SCALEFACTOR;
double newy = y * STL_SCALEFACTOR;
newln = " vertex " + newx + " " + newy + " " + z;
}
}
if (newln.Length > 0)
outlns.AppendLine(newln);
else
outlns.AppendLine(ln);
}
File.WriteAllText(file.FullName, outlns.ToString());
}
EDIT: Just tested it out and IT WORKS! HOORAH! Took about 30 minutes to process for my 2000+ models, nice.
Re: Any command line tool for scaling STLs in X&Y axis 7%?
Posted: Thu Nov 26, 2015 11:55 pm
by insta
You'd have written that code in 14.7 minutes if you used 'var' for everything like you're supposed to

Re: Any command line tool for scaling STLs in X&Y axis 7%?
Posted: Fri Nov 27, 2015 4:43 am
by swbluto
insta wrote:You'd have written that code in 14.7 minutes if you used 'var' for everything like you're supposed to

Lol. I don't like using 'var' because it makes it harder to read the code during maintenance/improvement/changes later on.
Re: Any command line tool for scaling STLs in X&Y axis 7%?
Posted: Fri Nov 27, 2015 4:54 am
by insta
It also makes upgrades to your own APIs harder because you can't change the signature of a method to something comparable (like GetAllFiles returning IEnumerable<string> instead of string[]) without breaking everything
You're right though, I clearly have no idea what type "d" is here:
Code: Select all
DirectoryInfo d = new DirectoryInfo(p);
Way more readable than:
Code: Select all
var directoryInfo = new DirectoryInfo(p);

Re: Any command line tool for scaling STLs in X&Y axis 7%?
Posted: Fri Nov 27, 2015 5:01 am
by swbluto
insta wrote:
Code: Select all
DirectoryInfo d = new DirectoryInfo(p);
Way more readable than:
Code: Select all
var directoryInfo = new DirectoryInfo(p);

If it makes you feel any better, I'm pretty sure I just copied and pasted that from a stack overflow thread, lol. Regardless, I would've done it much the same.
I totally love it when the 'var' code reads like...
'var val = getValue(tbox)';
It's like... what the hell is val? A double, a string, an int?! I agree, var used wisely can be beneficial, but used carelessly in situations like that makes for a coding maintenance nightmare. And way too many people just use it everywhere where they can.