AnsweredAssumed Answered

Mass Hunter Crashing

Question asked by jigr1969 on Sep 21, 2017
Latest reply on Sep 22, 2017 by jigr1969

Hi all.

 

I have some code, penned in Iron Python, which I'm trying to get to run from a menu item selection. When I select and execute similar code using the Tools -> Actions -> Custom Action, it works as intended. If I put it within code to run when a menu item is clicked, it simply crashes the Mass Hunter Application! The log file complains about a global name not being defined, which I can imagine, but it isn't defined in either.

 

The code here is the one which runs when the button is clicked and is loaded with Mass hunter by using the "-app=" command line parameter.

 

# The two main imports for IronPython (as I've found out).

import clr

import sys

 

# This appends the path, adding the Iron Python libraries location.

sys.path.append(r'C:\Program Files (x86)\IronPython 2.7')

sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Lib')

sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\DLLs')

sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\lib\site-packages')

sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Platforms\Net40')

 

# Add in manually items required for the script.

clr.AddReference("Microsoft.Office.Interop.Excel")

clr.AddReference("System.Windows.Forms")

clr.AddReference('IronPython.Wpf')

 

# Import modules that were added manually from above.

import csv

import os;

import os.path

import wpf

import Microsoft.Office.Interop.Excel as Excel

 

# Import specific classes from modules as opposed to full modules.

from System.Windows import Application, Window

from Microsoft.Win32 import OpenFileDialog

from System import Array

from System.Windows.Forms import (

    FolderBrowserDialog, MessageBox, MessageBoxButtons

)

 

clr.AddReference("QuantUIScriptIF")

clr.AddReference("System.Windows.Forms")

 

import System

import Agilent

 

from Agilent.MassSpectrometry.DataAnalysis.Quantitative.UIScriptIF import *

 

def SetState(ToolState, UIState):

 

       # always enable the tool

       ToolState.Enabled = True

 

def Execute(ToolState, UIState):

 

        # Declare variables.

       batchId = 0

       SetTrue = bool(1)

 

       # Placed in order to allow the software to be seen as running.

       MessageBox.Show("Hi honey I'm home!", "Warning")

 

       # Access sample table with object model.

       batchTable = BatchDataSet.BatchTable

 

       # Retrieve samples in the batch

       sampleRows = batchTable.Select("BatchID=%s" %(str(batchId)))

 

       # Walk through all samples.

       for s in range(0, len(sampleRows)):

              sampleRow = sampleRows[s]

              sId = sampleRow["SampleID"]

              _commands.QuantSetSampleAttribute(batchId, sId, "SampleApproved", SetTrue)

 

 

The code below is called and executed by the Action script menu, which works as intended.

 

# The two main imports for IronPython (as I've found out).

import clr

import sys

 

# This appends the path, adding the Iron Python libraries location.

sys.path.append(r'C:\Program Files (x86)\IronPython 2.7')

sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Lib')

sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\DLLs')

sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\lib\site-packages')

sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Platforms\Net40')

 

# Add in manually items required for the script.

clr.AddReference("Microsoft.Office.Interop.Excel")

clr.AddReference("System.Windows.Forms")

clr.AddReference('IronPython.Wpf')

 

# Import modules that were added manually from above.

import csv

import os;

import os.path

import wpf

import Microsoft.Office.Interop.Excel as Excel

 

# Import specific classes from modules as opposed to full modules.

from System.Windows import Application, Window

from Microsoft.Win32 import OpenFileDialog

from System import Array

from System.Windows.Forms import (

    FolderBrowserDialog, MessageBox, MessageBoxButtons

)

 

# Declare variables.

batchId = 0

SetTrue = bool(1)

 

MessageBox.Show("Hi honey I'm home!", "Warning")

 

# Access sample table with object model.

batchTable = BatchDataSet.BatchTable

 

# Retrieve samples in the batch

sampleRows = batchTable.Select("BatchID=%s" %(str(batchId)))

 

# Walk through all samples.

for s in range(0, len(sampleRows)):

        sampleRow = sampleRows[s]

        sId = sampleRow["SampleID"]

        _commands.QuantSetSampleAttribute(batchId, sId, "SampleApproved", SetTrue)

 

 

Now the log file created when it crashes has the following entries of interest:

 

09/21/2017 03:24:38 PM [ERROR] ScriptToolHandler: Agilent.MassSpectrometry.DataAnalysis.Quantitative.ApplicationCommandException: Script runtime error: global name 'BatchDataSet' is not defined ---> IronPython.Runtime.UnboundNameException: global name 'BatchDataSet' is not defined

   at IronPython.Compiler.PythonGlobal.GetCachedValue(Boolean lightThrow)

   at Help_About$3.Execute$6(PythonFunction $function, Object ToolState, Object UIState) in C:\Program Files\Agilent\MassHunter\Workstation\Quant\bin\applications\MyApp\tools\Help_About.py:line 64

   at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)

   at Microsoft.Scripting.Interpreter.DynamicInstruction`5.Run(InterpretedFrame frame)

   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)

   at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)

   at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)

   at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)

   at Agilent.MassSpectrometry.DataAnalysis.Quantitative.UIScriptIFImpls.ScriptEngine.Execute(TextReader reader, Encoding encoding, IScriptScope scope)

   --- End of inner exception stack trace ---

   at Agilent.MassSpectrometry.DataAnalysis.Quantitative.UIScriptIFImpls.ScriptEngine.Execute(TextReader reader, Encoding encoding, IScriptScope scope)

   at Agilent.MassSpectrometry.DataAnalysis.Quantitative.UIUtils.ScriptToolHandler.Execute(IToolState toolState, Object objUiState)

09/21/2017 03:24:38 PM [ERROR] ToolbarsManagerBase: Agilent.MassSpectrometry.DataAnalysis.Quantitative.ApplicationCommandException: Script runtime error: global name 'BatchDataSet' is not defined ---> IronPython.Runtime.UnboundNameException: global name 'BatchDataSet' is not defined

   at IronPython.Compiler.PythonGlobal.GetCachedValue(Boolean lightThrow)

   at Help_About$3.Execute$6(PythonFunction $function, Object ToolState, Object UIState) in C:\Program Files\Agilent\MassHunter\Workstation\Quant\bin\applications\MyApp\tools\Help_About.py:line 64

   at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)

   at Microsoft.Scripting.Interpreter.DynamicInstruction`5.Run(InterpretedFrame frame)

   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)

   at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)

   at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)

   at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)

   at Agilent.MassSpectrometry.DataAnalysis.Quantitative.UIScriptIFImpls.ScriptEngine.Execute(TextReader reader, Encoding encoding, IScriptScope scope)

   --- End of inner exception stack trace ---

   at Agilent.MassSpectrometry.DataAnalysis.Quantitative.UIScriptIFImpls.ScriptEngine.Execute(TextReader reader, Encoding encoding, IScriptScope scope)

   at Agilent.MassSpectrometry.DataAnalysis.Quantitative.UIUtils.ScriptToolHandler.Execute(IToolState toolState, Object objUiState)

   at Agilent.MassSpectrometry.DataAnalysis.Quantitative.Toolbar.ToolbarsManagerBase.Execute(IToolState tool)

09/21/2017 03:24:38 PM [FINISH] ToolbarsManagerBase: Execute

 

This to me feels like that I'm not referencing a global variable in the correct manner, not for when it is being called from within a function.

 

Any help is greatly appreciated on this manner.

 

It is taking me a while to get to this stage with Mass Hunter and Iron Python and I can see the combination has plenty of potential.

Outcomes