Exporting to pdf and dwg in a script run from Rhino.Inside

We have two custom GH components written in C#, one that exports selected layers to DWG and another that exports selected layouts to PDF. The former calls RhinoApp.RunScript("-_Export \n"" + filePath + “”\n _Enter", false), while the latter uses the class Rhino.FileIO.FilePdf.

We’re using these two components in GH scripts that are called from Rhino.Inside, where there are two ways of invoking the GH script: either via GH_RhinoScriptInterface.OpenDocument, or Rhino.RhinoApp.RunScript($"_-Grasshopper _Document _Open {filePath} _Enter", true).

Interestingly, we notice that the pdf export doesn’t work if using OpenDocument, and the dwg export doesn’t work if using RunScript. But the pdf export works if using RunScript and the dwg export works if using OpenDocument. Is there a script run method where both export operations could work?

We’ve noticed as well that doing a drag-n-drop of a GH script containing the dwg export plugin into a Rhino graphical window fails. Only after hitting F5 (Recompute) twice is the dwg generated. A drag-n-drop of a GH script contaning the pdf export plugin works as expected.