Meiki is completely correct. The Revit API can only be used within a valid Revit API context, and such a context is provided exclusively by Revit events. 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.
Another approach might be to make use of the DocumentOpened Event. You could use that to trigger the execution flow you desire.
A third but unsupported approach might be to make use of a journal file, as in the IFC Import and Conversion Journal Script.
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!