Subscribe to this thread
Home - General / All posts - External app 'Can't launch script'
KlausDE

6,410 post(s)
#27-May-17 22:26

I have an external app written in c# that calls a VB .Net script in manifold. When I start a new script from scratch with references to standard .NET modules everything works until at some point I have a bug in my code. This results in a 'Can't launch script'-error 0x80020009.

And now it's getting mysterious. Commenting out more and more of the code that runs fine in GUI when the initial error is eliminated I can narrow don't the error persisting in the external application to a very basic part of the code:

' VB .Net

Imports M = Manifold.Interop

Imports Manifold.Interop.Scripts

Class Script

   Shared Sub Main

      Dim doc As M.Document, comps As M.ComponentSet

      doc = Context.Application.ActiveDocument

      comps = Doc.ComponentSet <- this line produces the error in an external app

'  ...

   End Sub

End Class

What may be the reason and how to get around? I have seen some threads covering this error but all solutions do not apply here. Whats really special is that it ran until I produced and eliminated an error some 50 lines of code below.

Could it be the external application doesn't offer the correct context for some reason? It has'nt been recompiled. Here is how I call the script in c#:

// c#

M.ComponentSet m_CompSet;

int BeforePageExport_index;

// Test if script "PlotSet_BeforePageExport" exists

BeforePageExport_index = m_CompSet.ItemByName("PlotSet_BeforePageExport");

if (BeforePageExport_index >= 0)

{

   if (m_CompSet[BeforePageExport_index].Type != M.ComponentType.ComponentScript)

   {

      BeforePageExport_index = -1;

      ret = MessageBox.Show(" Component 'PlotSet_BeforePageExport' present\nbut not of expected type 'Script'",

             "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning);

   }

 }

if (BeforePageExport_index >= 0)

   m_Script = (M.Script)m_CompSet[BeforePageExport_index];

// ...

m_Script.Run();

(Win 10 x64, a script in Mfd 8.0.29 called by my PlotSet_Manager (http://www.schnittstelle-oekologie.de/downloads/?p=73 - compiled for x86 as I have some machines running 32bit Mfd on x64 machines)


Do you really want to ruin economy only to save the planet?

adamw


10,447 post(s)
#28-May-17 10:09

Replace Context.Application.ActiveDocument with Context.Document.

Application.ActiveDocument only returns something when there is Manifold UI. Since you are using an external application, there is no Manifold UI and no 'active' document.

KlausDE

6,410 post(s)
#28-May-17 12:05

Thank you, Adam. That solved the 'Can't launch script' error in the first place!

But it produced others. Does this same error apply to

importer = Context.Application.NewImport("JPEG")

This line produces the same error regardless of ...Application... or not.

Is there a way to know which objects are disposed in GUI-less mode?

---

Found the solution

importer = Context.Document.NewImport("JPEG")


Do you really want to ruin economy only to save the planet?

adamw


10,447 post(s)
#28-May-17 12:30

Is there a way to know which objects are disposed in GUI-less mode?

Anything that needs a Document and is created by the Application / from ActiveDocument. (Import objects should put their data somewhere. Import objects created by Application.NewImport put their data into an active document = won't work from an external application.)

Manifold User Community Use Agreement Copyright (C) 2007-2021 Manifold Software Limited. All rights reserved.