The challenge is "how exactly to make this work?"
First, throw away everything not needed on the train engine to reduce the weight. I 3d printed a cover shell and magnet holders. These will be very specific to whatever engine you use. My engine weighs about two pounds, so it has to not only keep from falling, but push against the track enough to pickup electricity.
Each bar magnet that I have chosen holds over ten pounds. That's over ten pounds if directly in contact with smooth steel. My magnet configuration allows 85% of the "contact area" to be air. Remove 85% of my attraction.
I stacked the magnets, four in front and four in the back. Stacking magnets is kind of linear for a while. Two magnets are almost twice as powerful as one. Four stacked are more powerful than three singles--but not equal to four singles.
When you introduce an air gap, the attraction drops fast. My magnets are placed about 1.5 mm above the track. This involved a lot of trial and error building of brackets.
The magnets cannot be allowed to touch the rail because: a) they will create a short circuit (they conduct)
b) they stick so well that the train can't move.
Eight Neodymium bar magnets (eight magnets out of this pack of 15)
An O gauge train engine
Some 3d printed parts to fit the train engine selected.
Files for 3d parts can be found at: