The way I've embedded magnets in prints in the past was to:
- Design a magnet-shaped (plus like 0.2mm of clearance) cavity into the print, but leave it completely "closed off" to where it's "inside" the print.
- But only "closed off" by like 2 or 3 layers (I was printing at 0.2mm layer height for this particular print).
- Use "pause at layer" functionality in my slicer (I used Cura at the time) to pause just before the first layer that would "close off" that cavity.
- Start the print and when it pauses, drop the magnet into the cavity.
Yes, I was a bit nervous about the magnet potentially jumping up and sticking to some ferromagnetic metal that's part of the print head, but that didn't happen in my case. YMMV, I guess.
I guess theoretically it could also be the case that the heat from printing could weaken the magnet, but again, that wasn't an issue in my case.
Just to elaborate on what my project was, I had a freely-spinning part that I wanted to be able to fix in place or unfix. I fashioned a "stop" that when engaged would fix the freely-spinning part in place. The way it works is that the stop can move freely up and down. Putting it in the "down" position fixes the freely-spinning part in place and gravity keeps it engaged. But to disengage it, you slide it straight up. At the top of the "track" in which it slides is where I put the magnet. I used the same technique as described above to embed a little stack of about four staples into the stop itself. So, by sliding the stop to the top of the track, the magnet attracts the staples, keeping the stop disengaged until you pull it back down again to where gravity will keep it engaged until you move it back up.