VisualTreeHelper

I seem to have gotten away from posting any coding things on this blog.   At first I thought its because I really haven’t done anything exciting; most of the work has been “figure out customer’s need, create something that solves that need”.   Then as I dug deeper, I rediscovered some fun things that I had created along the way:

The Problem

There’s a screen with a list of grids (this is a stock trading app) – when tabbing out of one grid, it needed to get to the next grid.  I also needed to jump left and right from master to detail easily.   (Sorry about all the blurring, but those were real numbers):

image

The screen, in and of itself, was a solution to “how to balance a portfolio to get it back in line with sector totals easily”.   The user could enter a proposed change in a holding, see how the math worked, and then click save positions to generate all the trade(s) necessary to make it happen.

Solution

I needed to write code that would take the grid that was currently focused, figure out what the next grid was, and focus there.    when solved, it looks like this:

image

Oy! What is this?  It’s a helper function that I wrote.   Basically, Starting with a known visual element, I look for “stuff that I’m interested in” (if the lambda returns true, then I’m interested in it):

image

This cuts down the (very) complicated visual control tree (see: http://www.codeproject.com/Articles/21495/Understanding-the-Visual-Tree-and-Logical-Tree-in) down into something much more manageable (this is the output of the Dump() function defined below with some additional comments thrown in)

image

Here’s the source that does it:

        public static VisualTreeInterestingNode GetInterestingNodes(this FrameworkElement topDependencyObject, Func<FrameworkElement, bool> isInteresting)
        {
            var timer = new Stopwatch();
            timer.Start(); 

            var topInterestingNode = new VisualTreeInterestingNode() { FrameworkElement = topDependencyObject, Parent = null };

            var nodesToVisit = new LinkedList<Tuple<DependencyObject, VisualTreeInterestingNode>>();
            nodesToVisit.AddLast(new Tuple<DependencyObject, VisualTreeInterestingNode>(topDependencyObject, topInterestingNode));

            while (nodesToVisit.Any())
            {
                var a = nodesToVisit.First();
                nodesToVisit.RemoveFirst();

                var currentDependencyObject = a.Item1;
                var currentInterestingNode = a.Item2;

                int childCount = VisualTreeHelper.GetChildrenCount(currentDependencyObject);
                for (int i = 0; i < childCount; i++)
                {
                    var childDependencyObject = VisualTreeHelper.GetChild(currentDependencyObject, i);
                    if (childDependencyObject == null) continue;

                    var childFrameworkElement = childDependencyObject as FrameworkElement;

                    if (childFrameworkElement != null)
                    {
                        if (isInteresting(childFrameworkElement))
                        {
                            var b = new VisualTreeInterestingNode() { FrameworkElement = childFrameworkElement, Parent = currentInterestingNode };
                            currentInterestingNode.InterestingChildNodes.Add(b);
                            nodesToVisit.AddLast(new Tuple<DependencyObject, VisualTreeInterestingNode>(childDependencyObject, b));
                        }
                        else
                        {
                            nodesToVisit.AddLast(new Tuple<DependencyObject, VisualTreeInterestingNode>(childDependencyObject, currentInterestingNode));
                        }
                    }
                    else
                    {
                        nodesToVisit.AddLast(new Tuple<DependencyObject, VisualTreeInterestingNode>(childDependencyObject, currentInterestingNode));
                    }
                }
            }

            timer.Stop(); 

            return topInterestingNode;
        }

And the VisualTreeNode class that the result is in:

    public class VisualTreeInterestingNode
    {
        private List<VisualTreeInterestingNode> _all;

        public VisualTreeInterestingNode()
        {
            InterestingChildNodes = new List<VisualTreeInterestingNode>();
        }
        public FrameworkElement FrameworkElement { get; set; }
        public List<VisualTreeInterestingNode> InterestingChildNodes { get; set; }
        public VisualTreeInterestingNode Parent { get; set; }

        public List<VisualTreeInterestingNode> Flatten
        {
            get
            {
                if (_all != null) return _all;

                _all = new List<VisualTreeInterestingNode> { this };
                foreach (var child in InterestingChildNodes)
                    _all.AddRange(child.Flatten);

                return _all;
            }
        }

        public StringBuilder Dump(StringBuilder prefix = null, StringBuilder result = null)
        {
            if (prefix == null) prefix = new StringBuilder();
            if (result == null) result = new StringBuilder();

            result.Append(prefix).Append(FrameworkElement.GetType().Name);
            result.Append(" ").Append(FrameworkElement.Name);
            result.AppendLine();

            var l = prefix.Length;
            prefix.Append("  ");
            foreach (var node in InterestingChildNodes)
            {
                node.Dump(prefix, result);
            }
            prefix.Length = l;
            return result;
        }
    }

Nephew likes Lebron

My nephew loves LeBron James, so I pieced this together for him.

I got the logo and basketball from thingiverse.  The logo was a bit tricky – it was a cellphone cover.  I had to “extract” it by differencing it from a block, and then scaling the block up.   The basketball needed to be squished a bit.

I combined the number six, a cone (base to help it stand), the logo, basketball, and his initials for the final. I printed it in black till about 5 hours in, then switched filaments for white.

Delivered yesterday. He liked it.

20140414-232939.jpg

Cube of Letters

In an effort to post more often, with half baked semi successful projects rather than comprehensive completely solved ones, I give you:

20140414-231547.jpg

The idea was to take each letter and extrude it, cutting it out of the square. Having three letters lead to some juicy geometry on the inside…

The fail part is, I could not dig the supports out. A thin piece snapped off as I struggled with it. I would have to print it in sections and glue it together.

Also note that the interior has shells that are not joined to the exterior.

My next attempt is/will be a coaster. Of my name. I would like to get it such that I can print it without supports.

Tools used for this: Blender.
Workflow: add text, convert to mesh, remove doubles, mesh cube, Boolean, difference, export to STL, net fab, repair, export part.

The Prius X-Dashboard

My car’s dashboard has.. mutated.   It grew .. stripes.    Precision stripes.

2014-04-07 17.19.56

What? Why? 

Well, it’s a 2010 Prius.  They added the “guide” marks to the rear backup camera starting in model year 2012.  I wanted guidelines.  So I lined the car up in our wonderful parking lot somewhat like this:

image

And I used some model stripe tape (Michael’s) to mark it on my rear view monitor:

image

Repeat on the other side, and now I have a much more precise backup camera.  And I didn’t draw on the display. 

BAMF!  (the sound, not the acronym)

3D Printing Adventures

It has been forever since I posted.   Life has been happening – first, my we had a vacation in Florida.  Then, my step father died.  Then, my cat died.   And I’ve been trying to catch up ever since.  I’m not caught up yet.

Just before all of that happened, though, I had started playing with a 3D printer.   I left off with almost getting a successful print of a LEGO block.

Since then, an abbreviated list of what I have learned:

PLA is Awesome

It is much, much easier to print larger parts with PLA.    It works very well on the Solidoodle:

  • Brought the extruder temperature down to 175 or so (hint:  watch for signs of oozing as the extruder warms up, and you’ll know what the safe zones are)
  • Print cold on Blue painters tape.  However, for larger prints, they do peel slightly, so its sucked the tape off the printbed before.
  • Print 85C on heated bed.   Sticks VERY well, to the point of ripping Kapton tape off for big prints.
  • PLA holds more heat in, so it stays soft and droopy for longer than ABS.  Thus, adding an external fan (thank you Step Son for giving me your extra fan) cools it down quicker and prevents drooping and lets the layers continue to look crisp.
  • PLA smells better.

The Best Infill was Rectilinear 20%

I did the same print over and over with different types of infill.    The best, most consistent one was rectilinear – which ends up looking like a bunch of squares.  The other fancy ones.. HilbertCurve, OctaSpiral – cool ideas, but very often ended up with unsupported infill layers, which lead to lots of droop and havok on the inside.  

imageimage

imageimage

This was partially motivated by large ABS prints lifting all the time, I was trying to figure out “least infill possible”, but in the end, PLA solved that problem.

Home Depot did not carry M3 screws

And thus I had to special order those from Amazon.  This is to get a longer Z-stop screw so that I could clip on a glass plate or other such thing to the print bed.. so that I can prep a plate, rather than prepping a print bed, for a print.   I’ve heard that ABS on Slurry on Glass and PLA on heated glass are awesome.  I still need to get some glass – a friend suggested picture frames.   #pendingExperiment

Printing Models and Finish Them Is Fun

So far, I’ve done two Yoda’s, R2-D2, a Dalek, a Weeping Angel, and a TARDIS.

Camera Uploads

I’ve done some painting with Enamels now;  I have more to learn about Acrylic and base coats #pendingExperiment.

image

The best part is giving them away (if I don’t want to paint them myself) to other people who would love them and keep them and call them George.

And that’s all the time I have to write for now.    Later!

Watching TreeHouse Videos Quickly

imageIn November, I signed up to be a mentor for Code Louisville.    It’s a program where people use TeamTreeHouse (as made available to anybody living or working in Jefferson County by Louisville Free Public Library) to study up on stuff, and work on projects, and if they need help, they can ask the mentors during their weekly class/lab.

For the first Two Months, I stayed current on all the videos, and quizzes, at TeamTreeHouse.  You can see that from my profile on the right.

Unfortunately, I do not have the 10 hours per week necessary to do this properly.   (Well, 5 hours for watching videos, and another 5 for working on a personal project). 

I still want to keep up (so that I know what the course is teaching the students, so I can help the students when they have questions), so now my mission is to stay up on videos, while not taking the quizzes that come after each video, in the most efficient way possible.   (Note: possibly Windows specific, YMMV):

Step 1:  Subscribe to the iTunes feed.

Every video lives somewhere like this: image

Go up to the “course” level URL instead: image, and there you will find the magic button:

image

The actual link address is something like this:

itpc://teamtreehouse.com/library/javascript-foundations.rss?feed_token=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Which, if you convert it to http, and get it in a browser, looks like this:

image

I.E. It’s a plain old RSS feed.  However, the itpc:// causes it to open in iTunes as a podcast, where you get this:

image

Note. At first, you don’t get all the episodes – I had to tell it to “show old episodes”, and I had to click the little cloud icon to download each one .. there’s probably a way to do that easier.  I clicked on each one.  I was at work, so it downloaded fairly quickly.

Step 2: Watch them with VLC

Then, instead of watching the episodes with iTunes, I find them on disk, and watch them in VLC.  I go as far as to create a VLC playlist to get them in order:

image

Then, while I’m watching them, I can speed them up:

[ , ] Slower/Faster in 0.10x increments
If the speed gets higher than 4x, it cuts audio out
= Resume normal speed
Shift-Left-Arrow, Shift-Right-Arrow 3 seconds left or right

I find that watching at 8x, I can tell what the subject matter is fairly easily.  If I find something interesting, “=” + a couple of Shift-Left-Arrows, and I watch that at normal speed (or sometimes only double-speed).  

I just watched 3 hours of video in an hour.    And I don’t think I missed any detail.   Nice.

In another half hour, I can catch up to where the class(es) would have me be at.  

Seiki 39” 4k TV as a Monitor

Those are 22" monitors on either side Keep in mind that this is 2014; this is the first generation of this monitor; that being said:   I would not recommend using this as an all-day development monitor.

The exact item:  Seiki Digital SE39UY04 39-inch 4K Ultra HD 120Hz LED TV.   When it dropped to $405 on Amazon, I jumped at the possibility of using it instead of a portrait 1080p as my main coding window.   (Side note: I used CamelCamelCamel to track the price)

It arrived, and it turned out I didn’t have anything that could drive it.  I went out and purchased an NVidia 700-level card which had HDMI 1.4 outputs on it.. hooked it all up.. and..

It is HUGE.

Panoramic View And it is Painful. 

Problem #1: Refresh Rate

I could not tell at first what was “not right” about it.   Eventually, i figured it out – as can be seen from this video:

[youtube=http://www.youtube.com/watch?v=yf4Op9UspbE]
Low Refresh Rate

As I move a window around on a different monitor, the motion on this monitor lags behind.  It might be due to the refresh rate – or it might be due to some kind of latency – but the effect is about the same as using a PC over a somewhat laggy (100ms?) remote desktop connection.   [Edit – actually, its more like remote desktoping into a machine, and then running a VM which does not have client tools, and then trying to use that VM.  The annoying bit is that I try to move the mouse to a certain spot, but I keep over/undershooting]

The problem is due to HDMI 1.4 only being able to handle a 30hz refresh rate at 4K resolution.   HDMI 2.0 would fix this – but this TV does not support it. (yet?) It looks like DisplayPort would handle it, but the TV did not have a DisplayPort input either.

Problem #2: Sheer Size

I am used to snapping a window to full screen, left, or right.

With the right software (Winsplit Revolution), I can snap a window to various parts of a 6×2 quadrant as well.

Either way, snapping windows on this monitor did not work for me.  The only place which felt “right” was snapped to the middle column in the monitor – everything else was too far away, too high, or too big.  I would have to physically move my keyboard to once side of the monitor or the other, to focus on a window that was snapped there.   (Given, I have progressive lenses, and pretty bad astigmatism; perhaps younger eyes would not be troubled as much)  

Floating Windows in a Desktop SeaInstead, the solution was to revert to non-maximized, non-snapped windows – keep each window as small as you can get away with, and they all just “float” in monitor space.  The monitor truly is big enough for it. 

Problem #3: Bifocal Nightmare

I have bifocals.  Actually, no, I have progressive lenses .. the limit as number of focals approaches infinity.    With my bifocals on, I could NOT crane my neck up high enough to actually focus on the top of the monitor, from a 3 foot distance or so. 

So, I switched to my computer glasses.   Single focal length across the entire frame.   It mostly worked, except.. the left and right sides of the monitor – were far enough away – that if the center was in focus, then they were not.  The monitor really is that big.

Watching 4k Video on YouTube

Wildlife in Ultra 4k – The picture was amazing.

Elysium Trailer – Fail (for me)

Once again, the 30hz made it pretty unbearable.  However, I have this same problem at most movie theaters as well – whenever a camera pans, I can see individual frames, it is not “smooth motion” for me.   I might just be defective.

Conclusion

Don’t buy one … yet.  Not till there’s a way to do 4K at 60Hz into it.  Or if you are going to, first spend a day as follows:

  • Bring your refresh rate on your 1080p monitor down to 30hz, and leave it there for the day.
  • Move your monitor away from your normal line of sight – to about 45 degrees away from where your keyboard and mouse “face”.   [Edit: don’t point it at yourself!   Leave it angled away from your line of sight.]
  • Change all your fonts to be really small.  Really really small. 

If you can live with these things.. or if you have a need to work with really large excel spreadsheets, which this was a BOSS at), then go ahead and buy one.  For $400, its pretty awesome.  

I’ll be shipping it back on Wednesday (after the snow storm).  Back to just 3 monitors for now.. with the middle one in portrait mode.   I’ll live.

Solidoodle: Printing a Lego-Like Block: Success

First, what are the actual measurements we must match?   Taking multiple measurements: Mesauring Brick with Caliper

  • A: Diameter of a nubby: 4.92mm, 4.90, 4.89, 4.89
  • B: Width and Length of a 2×2 square: 15.84mm, 15.89mm
  • C: Height of a brick (ie, 3x a thin): 9.57mm, 9.59mm

Then, using NetFabb against the model (click image to for link to ThingiVerse): parametric_lego_2x2_preview_tinycardMeasuring in Netfabb

  • A: 4.8mm
  • B: 15.8 mm
  • C: 9.6 mm

My guess is that they reduced the size of the nubby because it would ooze a bit; the other two dimensions appear to be about right.  

And the printed out ones:

Slice Scale Flowrate A B C Fit?
0.3mm 1.0 0.6 4.67, 4.82
4.69, 4.79
16.07
15.93
9.64 mm Very Loose

Interesting!  The nubbies are coming out a bit smaller, but the part is a bit bigger.   The height is within 1 layer of where it could or should be.

Now, I want the part to print out nice and snug.  Its hard to measure, but it looks like the receptor diameter for tne nubby is about 4.8mm – ie, they’re using a flex of about 0.1mm to keep things snug.  So, I want to print out with a diameter above 4.8mm.

Lets try something at Flowrate 0.65, just to see what happens:

Slice Scale Flowrate A B C Fit?
0.3mm 1.0 0.65 5.02, 4.8, 4.95, 4.86 15.93
15.84
9.73 Pretty good!

And what do you know!  It fits!  Pretty snug-gly!

3 bricks in a row

Although, due to a hole in the original .STL file, the entire bottom of the piece got replaced with a solid face. 

The missing bottom

Mission Accomplished.   0.65 might be the answer, although it disagrees with the single-wall-thickness calibration.

Solidoodle 2 Pro 3D Printing: Frustrated

2014-01-19 11.09.56

I am having difficulty

  • My Lego-like pieces are not sticking to each other, let alone to regular Lego’s.
  • Many many of my prints are curling up from the bed.
  • My 4? 5? attempts at an iPhone case so far have been incorrectly sized
  • My hexagonal infill is not pretty.

Here is What I have Learned

  • When printing really large parts, be aware that ABS filament shrinks.  For example, the XY(Z) thing above was 2” while printing (measured with caliper), but as it cooled from 210C down to 27C, it shrunk to 1.98”. 
  • Enclosures are very important at keeping heat in, which helps a model not-shrink too quickly.  Quick shrinking can lead to bends in the structure.  
  • As the ABS shrinks, in larger parts, the top shrinkage can pull the bottom part off the bed.  There are ways around this.. rafts, permiters, skirts, windex cleaning, hairspray sticking, kapton tape, and the heated bed.. As of yet, i haven’t figured out which combination of things will get me a reliable bigger print.
  • The Doodle was pretty well configured when i got it.  And my tinkering has made it worse.  

Of Flow Rates and Stepper Motors, Oh My

As of right now, I’m refusing to learn how to flash/reprogram the eeprom in the doodle.    Luckily, the number of steps for the X Y and Z axes are almost dead on.    However, the filament stepper is not – its pulling definitely more than  120mm for every 100mm it ought to be pulling.

Luckily, there’s a setting in slic3r that accommodates that – Solidoodle’s config files shipped with a default 0.6 ratio.  The result, I thought, was a bit blobby while doing infill. Also, all the documentation said I should have a 0.4mm nozzle, but the configuration was set at 0.5mm;  likewise, I was using 1.75mm plastic, but the config said 1.68.   

So, i “fixed” them.    And slowly, as I scream in 40-minute-delayed frustration, I’m setting them all back.  

Luckily, that’s all I’ve had to deal with.  Here’s all the things that Solidoodle did RIGHT with the printer, that I have not had to deal with.

  • Correctly configured stepper motor sizes
  • Correct power levels for the X/Y/Z/etc motors.. potentiometers.. something something.
  • Belts are correctly tensioned
  • Bed is Level
  • Bed is appropriate distance away. 
  • Nozzle assembly, no jams.

So, GOOD JOB Solidoodle.  You did good work here.

Dealing with Spooling2014-01-19 11.35.47

The provided spool holder – bit of a nightmare.   It mounts to the back of the printer, but with the XY going all  over the place, and with a brand new spool, the slack allows the cable to “fall over” on itself, and it gets wrapped up on the spool handle.  My initial solution was to hang a bungee cord from the rafters (I’m in the basement) and run the filament through that – so that gravity is applying a tension for me.  

My wife came up with an even better idea: Suspending the Spool from the ceiling with the bungee cord.

Lost My Sense of Direction .. Finding It

I feel like I’ve lost my sense of direction.  Where am I trying to go with this printer, and how do I get there?

Part 1:  An Education

I’m definitely getting that.   Hoo boy.  And I’m glad for it.   At some time.. next week? next month? I’ll be giving a Lunch and Learn at work on some, or all, of this stuff.. and taking the printer in to work so that other folks can use it, possibly to print their own printers.    After what I’ve experienced, if I was to do this again, I’d plunk down the extra money and get an even more pre-built solution – like the Doodle ‘4.   I hate messing with stuff.   Good luck you guys.

Part 2: Specific Goals

To clear my head up .. which way do I need to / want to go?  I need to get this back to being a pleasurable experience, even if I’m failing along the way.  (As my wife would say, stop being a booger!) 

I Want To [Print] Why? To Get there, I need to: Priority
Super Serious (not) Lego Minifig Scale model of our current house, possibly with cute little furniture. Something inside me.. about representing reality.  Its why I do video as well. Figure out how to print large prints without warping. C5
An iPhone case
4s_preview_tinycard
Because then I can print customized cases for my friends and love on them.  Q has already requested a Dragonball Z case. Get better at exact sizes, large model heat shrinkage, and printing large prints without warping. B3
Lego-compatible Blocks
3520480987_710d573c8d_o_preview_tinycard
Because I’d like to incorporate lego nubs on my models, so they are cool. Work on wall widths and flow rates, print some calibration pieces that “ought” to stick together, and work on bed lift B2
Super Action Figure
Jason_Welsh_action-4_preview_tinycard
For my nephew Cam, and for my inner 8-y-o. Just make time to print a LOT of prints.  And precision printing as well. C4
Pendant thingies Because its something my wife can doctor up and make into cool stuff. Already there.  Just need some design work in Sketchup. Which means I need a design from my wife of what the border should look like. Q1
Have things figured out enough so that Brandon and Doug can print their printer parts. I like being of service and enabling people to investigate cool technologies Large print bed lifting and precision. B1.5

So What is Next? (Given unlimited time)

  1. Play with their 0.6 ratio default, +/- for More or Less ooze. Figure out where the parts DONT fit, and where they DON’T stay together, and go halfway.
  2. Double check bed leveling and clearance.
  3. Print in 0.3mm instead of 0.4mm for a bit.
  4. Do some Pendants so that I have a sense of accomplishment.
  5. Print some connector parts, get the connections worked out.
  6. Retry the Lego’s after connectors are connecting.
  7. Retry the iPhone Case – with skirt, with raft?, add hairspray, foam core heat shielding, no scaling – measure – apply scaling and retry
  8. Retry a 2” or 3” print, try to figure out bed lift.  (Skirt, raft?, hairspray, heat shielding)
  9. Take over the world.

Make it so, #1.   

3D Printer: Solidoodle: Day #1

I received my Solidoodle 2 Pro yesterday.    I’ll spare the unboxing video.. suffice it to say, no instructions, but I knew that.  The instructions are online at http://www.solidoodle.com/start-here/ 

I had trouble with the print drivers at first.  I gave up, and switched to a laptop (the laptop that will go with the 3d printer to work when it goes) and it worked fine there.

Here are my first four prints (from left to right)

2014-01-15 09.38.40

  1. I didn’t have the printer homed correctly.   Ie, the printer thought it was at 0,0, but really it was at 100,50 or something.. so as it printed, it would hit the physical limit, and throw the print head off, and each successive layer moved out further.  
  2. I didn’t trim the ooze of plastic from the print head before it started printing, and that little strand of filament bunched up on the build plate.. which made an obstacle for the print head to bump into.. and then the build popped up off the plate.
  3. The build popped up off the plate during printing.
  4. Having borrowed my wife’s $18 Hairspray (she’s getting me cheaper hairspray today), I finally got a good print.   Thank you beautiful wife

The print is a request from my nephew Iman (@PokeIman_Master) .. it’s a Legend of Zelda Tri-Force.  This was done at 0.3mm resolution (the 3rd roughest).. you can see some of the lines don’t quite meet.   Its not 100% solid.. I used a 10%? 20%? honeycomb fill pattern on the inside.  Supposedly took 16cm of filament.. 21 minute print time, probably $0.20 of material.   I think I’ll be doing the same print again at 0.2mm after I do some calibration prints.

The print quality as compared to the Makerbot2 at LVL1 .. not as good, fer sure.  It might be the table I have it on (it shakes while printing), it might be the speed the printheads are travelling at, etc – there’s some tuning to be done.     Its technically the same print nozzle size, I should be able to improve quality.

I’m a wee bit excited.   It’s a good thing I’m not working from home today, I wouldn’t be working.   As it is, I need to stop writing this at get back to being billable.