This is exactly what I wanted! I wish I knew about this mod 235 hours ago.
Does this work when upgrading or downgrading the quality of a building? And does it work both when replacing a building manually, by the player, and when a bot does it?
Yes, quality works, and player, bot and platform construction work as well.
Also this mod may have not existed 235 playtime hours ago ;)
(surprisingly)