Any command line tool for scaling STLs in X&Y axis 7%?

General discussion topics
swbluto
Posts: 215
Joined: Mon May 25, 2015 7:09 pm

Any command line tool for scaling STLs in X&Y axis 7%?

Post by swbluto » Thu Nov 26, 2015 9:34 am

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

User avatar
ednisley
Posts: 1188
Joined: Fri Apr 11, 2014 5:34 pm
Location: Halfway up the Hudson
Contact:

Re: Any command line tool for scaling STLs in X&Y axis 7%?

Post by ednisley » Thu Nov 26, 2015 1:44 pm

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/

Image

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.

swbluto
Posts: 215
Joined: Mon May 25, 2015 7:09 pm

Re: Any command line tool for scaling STLs in X&Y axis 7%?

Post by swbluto » Thu Nov 26, 2015 5:14 pm

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.

jsc
Posts: 1864
Joined: Thu Apr 10, 2014 4:00 am

Re: Any command line tool for scaling STLs in X&Y axis 7%?

Post by jsc » Thu Nov 26, 2015 5:43 pm

Slic3r and Simplify3D can scale your models in any axis independently.

swbluto
Posts: 215
Joined: Mon May 25, 2015 7:09 pm

Re: Any command line tool for scaling STLs in X&Y axis 7%?

Post by swbluto » Thu Nov 26, 2015 7:10 pm

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.

swbluto
Posts: 215
Joined: Mon May 25, 2015 7:09 pm

Re: Any command line tool for scaling STLs in X&Y axis 7%?

Post by swbluto » Thu Nov 26, 2015 7:32 pm

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

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.

User avatar
insta
Posts: 2007
Joined: Tue Sep 16, 2014 3:59 am

Re: Any command line tool for scaling STLs in X&Y axis 7%?

Post by insta » Thu Nov 26, 2015 11:55 pm

You'd have written that code in 14.7 minutes if you used 'var' for everything like you're supposed to 8-)
Custom 3D printing for you or your business -- quote [at] pingring.org

swbluto
Posts: 215
Joined: Mon May 25, 2015 7:09 pm

Re: Any command line tool for scaling STLs in X&Y axis 7%?

Post by swbluto » Fri Nov 27, 2015 4:43 am

insta wrote:You'd have written that code in 14.7 minutes if you used 'var' for everything like you're supposed to 8-)
Lol. I don't like using 'var' because it makes it harder to read the code during maintenance/improvement/changes later on.

User avatar
insta
Posts: 2007
Joined: Tue Sep 16, 2014 3:59 am

Re: Any command line tool for scaling STLs in X&Y axis 7%?

Post by insta » Fri Nov 27, 2015 4:54 am

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);
;)
Custom 3D printing for you or your business -- quote [at] pingring.org

swbluto
Posts: 215
Joined: Mon May 25, 2015 7:09 pm

Re: Any command line tool for scaling STLs in X&Y axis 7%?

Post by swbluto » Fri Nov 27, 2015 5:01 am

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.

Post Reply