06-20-2017 11:01 AM
Good day all.
I created a data plugin for our custom Binary Data File and associated its extension to DIAdem inside Windows.
My problem is that every time I double-click on one of our files, DIAdem start a new program. My need it to have only one instance of DIAdem running at the time; every time I double-click on a new Binary Data file, the execution has to be inside the already opened DIAdem instance.
PS: for the second time I will need the same behaviour, but in the command line.
Thank you in advance.
Regards,
Eric G.
06-21-2017 01:47 AM
You can drag the files onto DIAdem window to avoid loading a new instance.
To do the same thing from command line you need to use the DIAdem Automation interface.
The interface is accessed by COM which is accessible by most programming languages.
Use windows VBS file. Create a file LoadFile2Diadem.vbs on your desktop with the following content
Option Explicit if 0 = WScript.Arguments.Count then WScript.Echo "No filepath given. One parameter expected" else dim path : path = WScript.Arguments(0) dim oDIAdem : Set oDIAdem = CreateObject("DIAdem.TOCommand") oDIAdem.CmdExecuteSync("DataFileLoad('" & path & "')") end if
If you drag a file on the icon of the vbs file it will load the file to single DIAdem instance
The vbs file can also be used to load from batch.
Create file LoadFile2Diadem.bat beneath it with the following content
@ECHO OFF REM use cscript.exe if message box is not meant to pop up wscript.exe //Nologo "%~dp0LoadFile2Diadem.vbs" %*
Now you can also drop the file on the batch which will also load the file to DIAdem.
06-21-2017 10:22 AM
Hi Eric,
To be specific, you need to drag your data file(s) from Windows Explorer onto the Data Portal of the DIAdem instance you want to load them into. If you try to drag your files onto random locations in the DIAdem interface, you will get different results, some of which are not what you want. DIAdem allows dragging of all kinds of files into it: VIEW and REPORT layout files, VBScript files, SUDialog files, etc. In all cases you should either drag the file into the panel of DIAdem that most closely matches the file's function, or you should drag the file into the lower left (grey) corner of DIAdem, where DIAdem will know to try to sort out the file's intent by file extension.
Brad Turpin
DIAdem Product Support Engineer
National Instruments
06-23-2017 10:20 PM - edited 06-23-2017 10:22 PM
Thank you it works like a charm... This is my "final" solution to load multiple files inside the same instance and start DIAdem if isn't started yet...
Another question, I wish to run a specific script after these importations (some functions aren’t available in the DataPlugin “interface”). How I can do it inside the loading VBS?
(Look at “XX HERE I wish to RUN the personal SCRIPT below XX”)
Thank you again,
Eric G.
Option Explicit Dim oDIAdem Dim StrFileName , StrFilePath Dim StrUserName, wshShell Dim ScriptArgument Dim BolChkIsProcessRunning Const ConstStrProcessToStart = "C:\Program Files\National Instruments\DIAdem 2017\DIAdem.exe" Const ConstStrProcessName = "DIAdem.exe" Const ConsStrComputer = "." Const ConstMiliSecondDelayWait = 5000 Set wshShell = WScript.CreateObject( "WScript.Shell" ) StrUserName = wshShell.ExpandEnvironmentStrings( "%USERNAME%" ) ' '.............................................................................. If WScript.Arguments.Count = 0 Then WScript.Echo "Usage: " & Wscript.ScriptName & " " & "Filename" WScript.Quit End If '.............................................................................. ' If ( not IsProcessRunning(ConsStrComputer , ConstStrProcessName , StrUserName ) ) Then wshShell.Run chr(34) & ConstStrProcessToStart & chr(34) , 0 WScript.Sleep(ConstMiliSecondDelayWait) If ( not IsProcessRunning(ConsStrComputer , ConstStrProcessName , StrUserName ) ) Then wshShell.Run chr(34) & ConstStrProcessToStart & chr(34) , 0 WScript.Sleep(ConstMiliSecondDelayWait) If ( not IsProcessRunning(ConsStrComputer , ConstStrProcessName , StrUserName ) ) Then 'call MsgBox ("Impossible de démarrer " & strProcess , vbCritical , " Erreur") call MsgBox ("Unable to start " & strProcess , vbCritical , " Error") WScript.Quit End If End If End If ' ' '.............................................................................. Set oDIAdem = CreateObject("DIAdem.TOCommand") For Each ScriptArgument in WScript.Arguments call SetFileInfo(ScriptArgument) oDIAdem.CmdExecuteSync("DataFileLoad('" & StrFilePath & StrFileName & "')") Next '.............................................................................. ' XX HERE I wish to RUN the personal SCRIPT below XX
'Dim oChnGrp , oChannel
'
' For Each oChnGrp in data.root.ChannelGroups
' For Each oChannel in oChnGrp.Channels
' if (oChannel.Name = "Temps UTC") then
' oChannel.Properties("displaytype").Value = "Time"
' end if
' Next
'Next
'XX END OF SCRIPT XX
'.............................................................................. ' '############################################################################## 'Source: https://stackoverflow.com/questions/19328981/vbscript-to-check-for-open-process-by-user Function isProcessRunning(ByRef strComputer, ByRef strProcess, ByRef strUserName) Dim objWMIService, strWMIQuery, objProcess Dim strOwner, Response strWMIQuery = "SELECT * FROM Win32_Process WHERE NAME = '" & strProcess & "'" Set objWMIService = GETOBJECT("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2").ExecQuery(strWMIQuery) If objWMIService.Count > 0 Then For Each objProcess in objWMIService Response = objProcess.GetOwner(strOwner) If Response <> 0 Then isProcessRunning = False Else If strUserName = strOwner Then isProcessRunning = True Else isProcessRunning = False End If End If Next Else isProcessRunning = False End If End Function '############################################################################## '#Source: http://automation-beyond.com/2009/10/25/how-to-separate-file-name-and-path/ '#And: EGamache : 2017-06-01 , eric.gamache@gmail.com Sub SetFileInfo(FilenameNPath) Dim FSO , objFile Set FSO = CreateObject("Scripting.FileSystemObject") Set objFile = FSO.GetFile(FilenameNPath) StrFileName = objFile.Name StrFilePath = objFile.Path StrFilePath = Left(StrFilePath, Len(StrFilePath)-Len(StrFileName)) Set objFile = Nothing Set FSO = Nothing End Sub '##############################################################################
06-26-2017 01:17 AM - edited 06-26-2017 01:23 AM
Put you personal script into an own file and start it using
oDIAdem.CmdExecuteSync("ScriptStart('C:\temp\myscript.vbs')")
As far as I know you do not have to start DIAdem by calling run.
The TOCommand will start DIAdem if it is not already open and using bDontCloseApplication will avoid it to close automatically.
Set oDIAdem = CreateObject("DIAdem.TOCommand") oDIAdem.bDontCloseApplication = True
So my example is missing this line
Option Explicit if 0 = WScript.Arguments.Count then WScript.Echo "No filepath given. One parameter expected" else dim path : path = WScript.Arguments(0) dim oDIAdem : Set oDIAdem = CreateObject("DIAdem.TOCommand") oDIAdem.bDontCloseApplication = True oDIAdem.CmdExecuteSync("DataFileLoad('" & path & "')") end if
would be correct.
06-29-2017 12:17 PM
Thank you,
It works perfectly.
E.G.