Mittwoch, 16. April 2014

Start external application from form

From a waste water industry model form we want to launch an external application with certain parameters. In Map form designer you can add a button with VB.net script. Map API provides a function called OpenURL which seemed to be a good starting point. 

Map API Industry Model Docs

 The following script will open Notepad++:

Public Overrides Sub Button_Click()
      Me.Application.OpenUrl("C:\Program Files (x86)\Notepad++\notepad++.exe")
End Sub


It doesn't just open Notepad++. Notepad++ also tries to open a file C:\0:


Notepad++ message when called from Map form
It seems Map adds a parameter to the call which Notepad++ interprets as a reference to a file to be opened. Unfortunately I was not able to call Notepad++ with further parameters - such as a specific file name.

I couldn't figure out whether OpenURL is a suitable function for calling external apps or not. Instead of using Map API one can use the .Net Framework functionality as well. The following VB.net script launches the external app including certain startup parameters:

Public Overrides Sub Button_Click()   

 'Haltung auslesen
 dim d as Autodesk.Map.IM.Forms.DialogControls.TextBox
 dim name_number as String
 d = Me.Dialog.Controls.Item("NAME_NUMBER")
 name_number = d.Value
 dim parameter as String =  " /p Q:\KINS\Daten\öffKanal/h " + name_number

 'Msgbox( "Aufruf von:C:\Program Files (x86)\KINS\KINS.EXE " + parameter)
 'Aufruf
   
 Dim startInfo As New System.Diagnostics.ProcessStartInfo
 startInfo.FileName = "C:\Program Files (x86)\KINS\KINS.EXE"
 startInfo.Arguments = parameter
 Dim pro As New System.Diagnostics.Process
 pro.Start(startInfo)

End Sub

 
Map 2013 SP2


Keine Kommentare:

Kommentar veröffentlichen