Replacing all sub assemblies in the entire structure of a large assembly can be a complicated task to fully automate properly, because it often involves a lot of references and dependencies being changed. We don't really replace documents, but instead either component occurrences or file descriptors. You can review the following two methods online help documentations for more information.
ComponentOccurrence.Replace2
FileDescriptor.ReplaceReference
To replace component occurrences, you need to be iterating them, instead of referenced documents. And similarly, in order to replace file descriptors, you need to be iterating them, instead of referenced documents. You can get to file descriptors several different ways, depending on the situation.
Every Inventor.Document type object (or its sub-types) has a property named File, which is supposed to return an Inventor.File type object, if one exists. The Document object represents an active set of organized data being held in Inventor's memory. The File object represents organized data that has already been written to a longer term storage medium. A Document can exist without a File, such as when we use the 'New' tool to create a new Document, and we have not saved it yet. And even when both the Document & File both exist, the data in the Document can be different than the data in the File, if changes have been made to the Document since it was last saved.
The File object has the File.ReferencedFileDescriptors property, which returns a FileDescriptorsEnumerator collection object that we can iterate through to work with each FileDescriptor in it. There are also the following properties of other types of objects which can lead us to a FileDescriptor:
BOMRow.ReferencedFileDescriptor (property of the BOMRow object)
DocumentDescriptor.ReferencedFileDescriptor (property of the DocumentDescriptor object)
There are tons of other object's properties that can lead to a DocumentDescriptor type object, including the ComponentOccurrence.ReferencedDocumentDescriptor property of the ComponentOccurrence object type.
Wesley Crihfield

(Not an Autodesk Employee)