Run twinmotion/datasmith from pyrevit

Hi there,
I’m investigating the possibility of running datasmith exports headlessly and/or via pyrevit button.

I’m finding it difficult to figure out how to access the datasmith export command and how to execute it.

I’m able to find the assembly with
tm=__revit__.LoadedApplications[24]

This returns a <TwinmotionForRevit.TwinmotionApplication object at 0x00000000000000A6 [TwinmotionForRevit.TwinmotionApplication]> object.

Alternatively I can run
[a.Location for a in System.AppDomain.CurrentDomain.GetAssemblies() if "smith" in a.GetName().Name]

Which returns a list of dlls.

[‘C:\Program Files\Autodesk\Revit 2024\AddIns\TwinmotionForRevit\Autodesk.DatasmithRevitExporter.dll’, ‘C:\Program Files\Autodesk\Revit 2024\AddIns\TwinmotionForRevit\Autodesk.DatasmithFacadeWrapper.dll’, ‘C:\Program Files\Autodesk\Revit 2024\AddIns\TwinmotionForRevit\Autodesk.DatasmithRevitExporterResources.dll’, ‘C:\Program Files\Autodesk\Revit 2024\AddIns\TwinmotionForRevit\en-US\Autodesk.DatasmithRevitExporterResources.resources.dll’]`

How would I go about getting the commands available from the Autodesk.DatasmithRevitExporter.dll and then execute the command; ideally without any dialogs popping up?

Are there any other methods which would work here? I’ve seen this example which seems to do what I need, but it involves using win forms to send keystrokes to automatically handle the dialogs. It’s also not python, so I’ve no idea if the same approach could work from pyrevit.

Solved: Re: TwinMotion Dynamic Link Export Fbx Automatically - Autodesk Community

I’ve made some progress, I’m now stuck at instantiating ExternalCommandData().

ass=Assembly.LoadFrom(“C:\Program Files\Autodesk\Revit 2024\AddIns\TwinmotionForRevit\Autodesk.DatasmithRevitExporter.dll”)
cmd=ass.DatasmithRevitExporter.DatasmithExportRevitCommand()
elements = ElementSet()

cmd.Execute()

The execute method has the following signature:-

Execute(self: DatasmithExportRevitCommand, InCommandData: ExternalCommandData, OutCommandMessage: str, OutElements: ElementSet) -> (Result, str)

ExternalCommandData() returns an error

Alternatively, cmd.ExecuteFunc(__revit__, "", elements) successfully calls the command, but I have to manually set the path and hit a button to close the dialog.

Are there any examples on how to handle the file browser pop-up programatically?