Programmatic Device Swap

Simeon Stoykov's icon

I am looking for a way to replace devices in existing tracks, with ones from the user library, similar to the "hot-swap" functionality.

Is there a way to achieve that "programmatically", i.e. via a M4L patch, or any API interface?

Any learning resources and references are appreciated, thanks!