You can use the command-line tools:
http://manual.calibre-ebook.com/cli/cli-index.html
calibredb -- communicate with the database, includes the set_metadata command to feed in a metadata.opf
fetch-ebook-metadata -- download metadata from sources, with a switch to output in OPF format.
Or you could use Bulk Metadata Edit, by selecting multiple books and editing all of them at once.