Hi Thibaud,
To help further, I would need more code.
If you don't show what your objects are initialised as, or what your personal functions do, the code you posted actually makes little sense. (Certainly not to an English speaker like me!)
If you're passing a document to a function, that has to be the modifiable document. You also need to pass elementIds from that document to that function. You can't mix and match, if that's what you're trying to do. And you can't modify a linked document.
To be clear though, if you cannot do what you're trying in the Revit UI, I doubt you would be able to do it using the API
Cheers,
-Matt