It should work from a DS script. I use it in XGM to do some AI balancing at campaign start. There are some limitations. You can't upgrade buildings (it has to be a type that doesn't exist in the settlement yet) and you can't add things that would be visible on the strat map like walls, roads, or ports.