I can assign a project to a task in the inbox
tell application "OmniFocus"
set oproject to (first flattened project of default document whose name is "MyProject")
tell content of first document window of front document
set theSel to value of (selected trees where class of its value is not item and class of its value is not folder)
repeat with theTask in theSel
set assigned container of theTask to oproject
end repeat
end tell
end tell
But how do I assign an existing project to a task which is not in the inbox?