11 Replies Latest reply on Nov 30, 2017 7:06 AM by jboyack

    Mass Hunter & IronPython

    jigr1969

      Hi there.

       

      I'm currently playing around with Iron Python and Mass Hunter 8 integration and was wondering if anyone has any experience of the such?

       

      I've currently got a working script which I'd like to be available on the Mass Hunter menu list, whilst putting it there isn't an issue, however, some of the "imports" in the Iron Python scripts such as CSV and WPF aren't being allowed/found by Mass Hunter. Therefore I was wondering if these can be added or is there a list of modules that are available within Mass Hunter to the Iron Python script.

       

      Any help would be gratefully received.

       

      Cheers

      James.

        • Re: Mass Hunter & IronPython
          ron_tackett

          James,

          Are you trying to get a csv file of the quant results in MassHunter Quant? If so I have 2 action scripts for this.

            • Re: Mass Hunter & IronPython
              jigr1969

              Currently I'm just starting on the combination of IronPython and Mass Hunter 8 within the business. I'm looking at creating a menu within Mass hunter that will run a number of scripts which will do everything that needs to be done without leaving the confines of the software.

               

              One of those 'external' tasks is reading in a XLSM file, a CSV file and using the two (the XLSM as a template file), creates a thrid CSV output file. This is simply a way of getting me use to IronPython and integrating it with Mass Hunter, along with simplifying the end users life, stops them having to run macros within Excel.

               

               

              import clr

              import sys

              import csv

              import os.path

              import wpf

               

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

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

               

              from System.Windows import Application, Window

              from Microsoft.Win32 import OpenFileDialog

              from System import Array

              from System.Windows.Forms import (

                  FolderBrowserDialog, MessageBox, MessageBoxButtons

              )

               

              # Needs to be below the addReference for Excel.

              import Microsoft.Office.Interop.Excel as Excel

               

              The imports in red above are causing me issues currently, therefore I'm wondering what environment is available to the Iron Python scripts when they run within Mass Hunter, or if there is some way of importing those modules.

              • Re: Mass Hunter & IronPython
                jigr1969

                Hi Ron.

                 

                Thanks for the offer if the action scripts for the results etc into a CSV file, but currently, I'm struggling with getting the import part of the IronPython script to run, although have had some success since my OP.

                 

                import clr

                import sys

                 

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

                 

                import csv

                import os.path

                #import wpf

                 

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

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

                 

                from System.Windows import Application, Window

                from System.Windows.Forms import FolderBrowserDialog

                from System.Windows.Forms import MessageBox, MessageBoxButtons

                from Microsoft.Win32 import OpenFileDialog

                from System import Array

                 

                import Microsoft.Office.Interop.Excel as Excel

                 

                Having added the line in blue I can import the CSV and OS.PATH module easily now, it is still complaining about the WPF module and if i comment this out, it then goes on to complain about the "import application" line. I'm wondering if anyone has got IronPython from within Mass Hunter to show or run a Windows like program (using WPF and file dialogue boxes etc - allowing users to select output files etc).

                  • Re: Mass Hunter & IronPython
                    jigr1969

                    The items in red are those that Mass Hunter complained about:

                     

                    import clr

                    import sys

                     

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

                     

                    import csv

                    import os.path

                    #import wpf

                     

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

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

                     

                    #from System.Windows import Application, Window

                    from System.Windows.Forms import FolderBrowserDialog

                    from System.Windows.Forms import MessageBox, MessageBoxButtons

                    #from Microsoft.Win32 import OpenFileDialog

                    from System import Array

                     

                    import Microsoft.Office.Interop.Excel as Excel

                     

                    Which has surprised me since I was expecting many more lines that would cause an issue.

                      • Re: Mass Hunter & IronPython
                        ron_tackett

                        This is what was received from our programing department.

                         

                        "Our programming is focused on reusing .NET classes which is IronPython’s main attraction.

                        The supported modules are defined by IronPython which outlines installation steps.

                         

                        Our understanding is modules written in a supported version of Python could be
                        utilized.

                        Some modules that use compiled DLLs such as Panda are not supported by IronPython."

                          • Re: Mass Hunter & IronPython
                            jigr1969

                            Hi Ron.

                             

                            I can fully understand having issues with the WPF since that is a compiled DLL, but for the two other imports (highlighted in red below), I'd thought would be standard within Iron Python, since by definition they are standard Window modules. For example if importing "FolderBrowserDialog" is okay, one would have thought that "OpenFileDialog" would have been okay (since they do roughly the same UI functionality). I know they come from different modules, but even when you have the "FolderBrowserDialog", "MessageBox" and "MessageBoxButtons" all working okay, you get "Application" and "Window" not working which are from the parent module/class.

                             

                            #from System.Windows import Application, Window

                            from System.Windows.Forms import FolderBrowserDialog

                            from System.Windows.Forms import MessageBox, MessageBoxButtons

                            #from Microsoft.Win32 import OpenFileDialog

                            from System import Array

                            • Re: Mass Hunter & IronPython
                              jigr1969

                              Looking through the internet for answers from various other software packages which is having issues with Iron Python, I've now checked the system variables for both the command line IPY64.EXE and running the Agilent software.

                               

                              I added the lines below:

                               

                              import os;

                              print(os.getcwd())

                              print(os.sys.version)

                              print(os.sys.winver)

                               

                              import sys;

                              print(sys.path)

                               

                              From the command line, IPY64, I get the following:

                               

                              2.7.5 (IronPython 2.7.5 (2.7.5.0) on .NET 4.0.30319.42000 (64-bit))

                              2.7

                              [

                              'WpfApplication4.py',

                                  'C:\\Users\\James.Grant\\My Documents\\Projects\\WpfApplication4\\WpfApplication4',

                                  'C:\\Program Files (x86)\\IronPython 2.7\\Lib',

                                  'C:\\Program Files (x86)\\IronPython 2.7\\DLLs',

                                  'C:\\Program Files (x86)\\IronPython 2.7',

                                  'C:\\Program Files (x86)\\IronPython 2.7\\lib\\site-packages',

                                  'C:\\Program Files (x86)\\IronPython 2.7\\Lib'

                              ]

                               

                              I originally got the following from the Agilent software:

                               

                              2.7.5 (IronPython 2.7.5 (2.7.5.0) on .NET 4.0.30319.42000 (64-bit))

                              2.7

                              [

                                  'C:\\Program Files\\Agilent\\MassHunter\\Workstation\\Quant\\bin\\tools',

                                  'C:\\Program Files\\Agilent\\MassHunter\\Workstation\\Quant\\bin\\applications\\ALS\\tools',

                                  'C:\\Program Files (x86)\\IronPython 2.7\\Lib'

                              ]

                               

                              Adding the following lines,

                               

                              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')

                               

                              Resulted in an output,

                               

                              2.7.5 (IronPython 2.7.5 (2.7.5.0) on .NET 4.0.30319.42000 (64-bit))

                              2.7

                              [

                                  'C:\\Program Files\\Agilent\\MassHunter\\Workstation\\Quant\\bin\\tools',

                                  'C:\\Program Files\\Agilent\\MassHunter\\Workstation\\Quant\\bin\\applications\\ALS\\tools',

                                  'C:\\Program Files (x86)\\IronPython 2.7\\Lib',

                                  'C:\\Program Files (x86)\\IronPython 2.7\\DLLs',

                                  'C:\\Program Files (x86)\\IronPython 2.7\\lib\\site-packages'

                              ]

                               

                              But this didn't make any difference to the outcome.

                              • Re: Mass Hunter & IronPython
                                jigr1969

                                Well, finally I've had a break through with removing the errors upon startup of Agilent and using a PY script. My code now look like:

                                 

                                # 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

                                 

                                from System.Windows import Application, Window

                                from Microsoft.Win32 import OpenFileDialog

                                from System import Array

                                from System.Windows.Forms import (

                                    FolderBrowserDialog, MessageBox, MessageBoxButtons

                                )

                                 

                                Some of the lines appending the path variable aren't probably required and I will remove at a later date.