I answered an almost identical question this very morning:
The Revit API can only be used within a valid Revit API context, and such a context is provided exclusively by Revit events:
http://thebuildingcoder.typepad.com/blog/2015/08/revit-api-context-and-form-creation-errors.html#2
http://thebuildingcoder.typepad.com/blog/2015/12/external-event-and-10-year-forum-anniversary.html#2
You can however implement an external event and trigger that from outside to obtain access to a valid Revit API context. This is discussed in detail with many solutions provided by The Building Coder in the topic group on Idling and External Events for Modeless Access and Driving Revit from Outside:
http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.28
Another approach might be to make use of the DocumentOpened Event:
https://apidocs.co/apps/revit/2019/7e5bc7a1-0475-b2ec-0aec-c410015737fe.htm
You could use that to trigger the execution flow you desire.
I would start out reading the numerous solutions listed in the topic group, and probably end up making use of an external event.
Good luck and have fun!
Cheers,
Jeremy