pruning promotions in GMail

I finally got around to writing some code – turns out its super easy, there’s something called script.google.com, and you Resources|Advanced Google Resources and add the Gmail resource, and then you can write functions to prune your inbox arbitrarily:

function prunePromotions() { 
  var response = Gmail.Users.Messages.list('me',{'q':'label:promotions', 'includeSpamTrash':false});
  if (response && response.messages && response.messages.length > 0) { 
    // messages seem to come in from most recent to least recent
    Logger.log('inspecting '+response.messages.length+' messages'); 
    var collected = {};
    for (var i=0; i < response.messages.length; i++) { 
      var message = response.messages[i]; 
      if (message.id) { 
        var message = Gmail.Users.Messages.get('me',message.id);           
        if (message && message.payload && message.payload.headers && message.payload.headers.length > 0) { 
          for (var j=0; j < message.payload.headers.length; j++) { 
            var header = message.payload.headers[j]; 
            if (header.name=='From') { 
              var from = header.value; 
              if (!collected[from]) collected[from] = []; 
              collected[from].push(message); 
              break; 
            } // if header is from
          } // for each header
        } // if message.payload.headers
      } // if message.id
    } // every message
    for(var from in collected) {
      if (collected[from].length > 1) { 
        for (var i=1; i < collected[from].length; i++) { 
          var message = collected[from][i];
          Logger.log('trashing '+message.snippet); 
          Gmail.Users.Messages.trash('me',message.id);
        }
      }
    }
  } 
}

Unfortunately, I get a lot of promotions, and this only works on the most recent 100 messages or so, so it might be of limited use in this state.   But its a start.

House Print 4/N: “Second Beta”

image

I have 3.5 floors printed!  And they go together!  With Stairs!

image image
image image

There are some problems:

image I forgot to cut a section out of the “concrete” that the family room sits on to make room for the stairs from the basement up to the family room.

I also had a hard time getting the steps on the left to fit – I had to resort to my wife’s Dremel to cut some of it down to size.   (Incidentally, a Dremel doesn’t cut it, it selectively melts it via friction)

image I did not make the basement 7ft high like it really is.   Thus, the kitchen is than in reality – and the stairs are the wrong height.

In this same picture, you can also see the problem I have with trying to get the stairs to fit.   
The kitchen wall does not line up with the bedroom wall.

image I ran out of filament with 3 pieces of the bedroom to go.   If I had not made mistakes, I could have gotten the whole thing in a 1kg spool.   (In the pictures above, notice the bedroom has no upper section)

I have ordered a 2kg (5.5 lb) spool of white (“Studio Line White” from JustPLA.com);  With it I’m going to start over.  This time:

  • Correct the basement height
  • Put the stairs in from the start so they get “cut” correctly.  
  • I want to reflect where the ground level is better.

~~~~~~~

For this blog post, I snapped this tag:

https://github.com/sunnywiz/housejscad/tree/Post4

image

When I get time, I plan on making a how-to video – for my own benefit, since a year from now I won’t remember the details:

  • How to create the blueprint
  • How to size the blueprint to create the text overlap
  • How to use the code to generate the STL’s
  • How to use the Join libraries to make the pieces possibly fit each other
  • How to use the Cut libraries to make things printable on my print bed and Plate them
  • How to use the Microsoft / NetFabb Cloud service to fix the model
  • How to use Blender to section the shells off into separate prints
  • How I glued things together (as best as I have found so far)

Pewee, we have a problem (House Print 3/N)

(I live in Pewee Valley, KY, not Houston, TX)

image

This is the 1:48 scale print of the fourth floor.   The source is here:  https://github.com/sunnywiz/housejscad/tree/Post3  and the STL files you are seeing here are bedroom0.stl, bedroom1.stl, and bedroom2.stl.

Problem: The top half doesn’t quite fit the bottom half.   This is because the top half isn’t large enough to hold the shape together – when the roof prints, its warm, and as it cools, it wants to shrink, and so it wants to curve.  The bottom print wants to do the same, but the walls are large enough to prevent this from happening.

Solution: no-roof.  Which, my wife points it, is the way to go:  then you can easily play with the furniture inside.   The side effect of that is, in the current iteration, I won’t be doing top/bottom alignment tabs (similar to the “cross” thing on the left side of the picture). 

Otherwise, the 1:48 scale is working well.  Here is the same bottom half, but with Victorian doll furniture inside it:

image

The checkerboard at the bottom of the picture is also working well as a place to glue things.  Here it is glued to the next piece:

image

Pretty proud of it so far! 

Using OpenJSCAD to print a house (2/N): Small Print!

I advanced the code significantly:

https://github.com/sunnywiz/housejscad/releases/tag/Post2

  • I introduced a “TwoD” class to take the pain out of working in the 2-D character space.
  • I traced out my house’s 4th floor plan to a text file, so I’m dealing with the real thing now rather than test data.
  • I got my 3D printer back up and running – didn’t need any re-calibration after 6 months of no-use.  I had to go read the powerpoint of the presentation I gave a while back to re-remember what to do.
  • The result is this print, which is 1:72 scale, and took about 4 hours (1 failed print included):  

image

Its in two pieces so that:

  • I don’t have to print support structures for the doorways and windows
  • We see things at eye-level, or about 5.5 feet; the model is 8 feet; this makes the model feel overly tall.  With a removable section a little lower, this becomes more “playable”. (I need to move the cut line up though to be at about 5 feet.  Or, move the windows down a bit)

I’ll do a full “How To” video at some point in the future – I’m not quite done yet.  There’s some bleeding edge stuff in the “cuts” branch at the moment:

  • I’ve learned how to do real drag-and-drop libraries, in a separate file, which will work with OpenJSCAD
  • I’m working on a cutting algorithm that will let me cut with tabs.  Its workable now, but needs some fine tuning on gap distances.
  • We’ve (wife and I) decided to do the final print in 1:48 scale – there’s a lot of toy furniture out there available at that scale.  And it will be printed in white.

More to follow at some point.

Using OpenJSCAD to Print a House (1/N)

Since before I got my 3D printer, I’ve wanted to make a scale replica of my house.   I tried doing it with Legos once – it was cost prohibitive.

I came up with a workflow where I drew out the entire house in SweetHome3D, and then exported that, but I ran into manifold problems and stuff like that.

So I did one of the floors in Sketchup.  However, that was a painfully task – and the resulting model was still too big (I want 1:24 or 1:36 scale).  I’d have to slice up the model to print out individual pieces, which means I wanted to cut them in such a way that they joined together with some kind of self-aligning joint.

I was about to try it again, but the sheer amount of detail that I had to go through kept holding me back.  I wanted a formula.

A recent blog post brought my attention to OpenJSCAD. and an Idea formed in my head:

Convert THIS: image
Into THIS: image

I had tried to do something similar in OpenSCAD before, however, because that language doesn’t have procedural elements, I ran into all kinds of problems.   Fresh new start!

So I set about to do it.

As you can see by this screenshot, I succeeded.

The code is here: https://github.com/sunnywiz/housejscad.  It took me about 2 hours.   You can see the commit log, I committed every time I figured even a small piece of the puzzle out.

UPDATE 2/1/2015:  the code as of this blog post is tagged with “Post1”, ie https://github.com/sunnywiz/housejscad/releases/tag/Post1  — the code has since evolved. Another blog post is in the works.  I guess I could “release to main” every time I do a blog post.  Heh.

The Code

  • Provide a translation of map character to 1x1x10 primitive anchored at 0,0,0
  • convert the template into a 2D Array, so that I can look for chunks of repeated stuff.
  • Walk the pattern, looking for chunks.  Rather than get fancy, I made a list of all chunk sizes from 6×6 down to 2×1, and check for each one at a time.
    • There are more efficient ways to do this, but IAGNI.
  • If a chunk is found, generate the primitive for that chunk, scale it up, and add it to the list.  “Consume” the characters which we just generated.
  • When all done, union everything together.

Notes about the Code

  • The resulting file is not manifold, however, NetFabb fixes that pretty easily and reliably.
  • The chunking is necessary if I want to represent steps in an area.    Otherwise, I didn’t need it.
  • You can define any mapping you want .. from a character to a function that returns a CSG.
  • Could probably use this to generate dungeon levels pretty easily.  Or, maybe take a game of NetHack and generate out the level?  Coolness!

Where would it go from here

  • Lay out an actual template of (part of) the house, and fine tune it from there.
    • Probably involve adding “and I want the result to be exactly 150 by 145mm” type scaling.
    • The functions will probably start taking arguments like (dx,dy) => so that the function can draw something intelligent for an area that is dx by dy in size.
    • I just noticed, the output is mirrored due to axes being different between R,C and Y,X
  • Preferably, I’d like to create a object / class that does this work, rather than the current style of coding.  IAGNI at the moment.  Then, maybe running in node, I could take the different floors and convert then into objects, and then do further manipulation on them..
    • Like slice them into top and bottom pieces.  Windows and doors print a lot better upside down – no support material necessary.
    • Would also need to slice them into horizontal pieces.  My build platform is limited to 6” square.
  • I live in a very 90-degree-angle house.   Thus, this kind of solution would work for me.  Sorry if you live in a circular, or slightly angled, house, this solution is not for you.    Buy me a house, and I’ll build you a solutiion. 😛
    • Seriously thinking about this.  I’d probably have a template of “points”, and then a language of “Draw a wall from A to D to E”;  and then “place a door on wall from A to D at the intersection of F”  or something like that.

A fun night of short and sweet coding.  I had to look up a lot of javascript primitives, mostly around arrays of arrays, and checking for undefined.

Some day I’ll get that “doll” house printed.  Then I can make scale sizes of all my furniture from Lego’s!  Fun fun.