Rocket Terminal Emulator

 View Only

 Automation via Python?

Sean Strickland's profile image
Sean Strickland posted 12-18-2020 21:56

Good evening!

Our company is running a couple of different versions of BlueZone (I’m aware of at least v5.2 and ~v7.1) and we use VBA automation for some of our repetitive processes. Is there a way to connect to BlueZone via python so we can build a better long-term solution?  We'd love to be able to integrate some python staples for us like pandas + SQL scripts and leverage python to read & write data through our BlueZone terminals for automation.

If not, are there any other options aside from VBA and VBScript? We’re looking for something more stable for our users since we’ve seen some intermittent issues as we migrate towards a more virtual environment.

I'd also be interested in anything around JavaScript for some persistent form-based implementations.

Thanks!
Sean

Sean Strickland's profile image
Sean Strickland
Bumping this thread, but also providing some additional information:

We currently have some legacy scripts that scrape data from BlueZone, process them in an MS Access database, and push updates back out to our BlueZone systems via a VBA macro within the Access database.  We're looking for something more stable for end-users and have been steadily migrating older processes like this to python scripts and other RPA tools and we're looking for a clean way to do the same here.  These legacy scripts typically rely on either a) some user input, or b) some data collected from other sources to push automated updates through our systems.

In solving for this, I'd also rather have our end-user experience as simple as possible to ensure the individuals running this (that don't have extensive automation/coding experience) can use the tools.  In today's world, simple Access Forms solve for this.
Mike Slater's profile image
ROCKETEER Mike Slater

Hi Sean,

We meant to post this earlier for answer to your original post:

Yes, you can certainly use the Python scripting language with BlueZone.  First, make sure you have installed the Win32 package for Python, for example by running a Cmd prompt As Administrator:

 

python -m pip install pywin32

 

This will provide the Win32 API in Python and will also support invoking COM objects in your Python scripts.  In your scripts include the import statements:

 

import win32com.client

import pythoncom

 

Now you can invoke and use BlueZone objects and APIs in Python, as a simple “hello world” example:

 

import sys

import os

import win32com.client

import pythoncom

 

if __name__ == '__main__':

  pythoncom.CoInitialize()

  bzo = win32com.client.Dispatch("BZWhll.WhllObj")

 

  bzo.Connect('');

  bzo.SendKey('hello world ');

  bzo.Disconnect();

 

To run the script, save the example to a .py script file, then start a BlueZone session and connect it to your host system.  In a Cmd prompt execute the command:

 

python c:\mypath\myscript.py

 

The BlueZone Host Automation objects documentation (Chapter 3 in Bzsh.pdf; or select Help-Help Topics within BlueZone Script Host) applies to any scripting language, even though the samples in the documentation use the Basic language syntax.

 
Does this help?

Mike Slater's profile image
ROCKETEER Mike Slater
MS Access objects can be invoked similarly and called in Python. There are many GUI toolkits for Python you can use to build forms for user input, such as Tkinter, wxPython, Kivy and PyQt. You'll want to do a little research and choose the best framework for your requirements and environment. It's not a trivial undertaking to migrate automation from VBA macros and legacy scripts, but Python seems to be the current trend. If it can stabilize your processes, and make it easier to manage and for your users, then it can be worth the effort in the long run.
Sean Strickland's profile image
Sean Strickland
@Mike Slater thanks for the follow-up.  I tried to connect and I'm getting "class not registered" - what do you think are the next steps to resolve that?  Excited that this looks to be close to what we're looking for!

Thanks,
Sean

Code:
import win32com.client
import pythoncom

pythoncom.CoInitialize()
bzo = win32com.client.Dispatch("BZWhll.WhllObj")

bzo.Connect('')
bzo.SendKey('hello world ')
bzo.Disconnect()​


Result:
Traceback (most recent call last):

File "C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\dynamic.py", line 89, in _GetGoodDispatch
IDispatch = pythoncom.connect(IDispatch)

com_error: (-2147221021, 'Operation unavailable', None, None)


File "C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)

com_error: (-2147221164, 'Class not registered', None, None)
Mike Slater's profile image
ROCKETEER Mike Slater
Hi Sean, we're glad to hear this info may be helpful to you ;)

There are two possible causes for this type of error:

1. BlueZone install Object/ProgID registration issue. We recommend using the same ProgID, "BZWhll.WhllObj", "BlueZone.System", "BlueZone.Application", etc. that you're currently using in your VBA macros and legacy scripts. Is their other automation that's working Ok with BlueZone objects on this system? If the problem persists then uninstalling and reinstalling BlueZone should resolve the issue.

or more likely:

2. 32-bit/64-bit bitness issue, a process of one bitness cannot load an object of another bitness. On 64-bit Windows, you need to make sure the bitness of the Python engine used matches the bitness of BlueZone installed, just as you need to match the bitness of MS Office, or the bitness of Windows Script Host, to load BlueZone objects in VBA macros and VBS scripts. The resolution is to install the other bitness of BlueZone; or alternatively to install or run the other bitness of the Python engine.

Thanks, please keep us posted on your progress.