GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Working example of script with python?


#1

Hi all!
could someone please provide a minimum working example of a DO python script?
I tried using one older one written by juntalis I think, but I couldn't get it to work, and DO doesn't provide any error messages.
I also noticed that there is no option for parsing a python script in the editor. Only vbscript and jscript.
I have activepython 3.3, win 7 x64, dopus 11.0 beta9 (a bit too lazy to install and restart in my home computer)
thanks!


#2

Error messages to do with parsing etc. go to the log window, under Other Logs.

(Unless you are using the CLI window, which has its own log in the window itself.)


#3

right, sorry about that.
"Script Engine 'python' could not be opened"
Does is it mean it's a problem outside DO, is it certain?


#4

I think the name of the language may be something other than "python". Maybe "activepython" or something.

Not sure, though; I have never used it.


#5

I haven't used it either, but since ActiveState's Perl uses "perlscript", I'd go with trying "pythonscript".


#6

Thanks to both, I've tried every thing I could think of, but nothing seems to work. Case-sensitive combinations included. Maybe I need to activate something on my ActiveState python. I did run a related script as found on a website, but it made no difference. Maybe I need a restart. I'll give it a try and let you know. Thanks!


#7

The keyword is actually the name of a registry key that defines the CLSID for the script handler. E.g. "jscript" actually means HKEY_CLASSES_ROOT\JScript. So you could try doing a Find using regedit for keys with "python" in their name.


#8

thanks very much for this info! I couldn't find anything, but from running the pyscript.py file that registers python for activex (or something), I gather by the output that the name is "Python". It's still not working, so I guess something's wrong with my installation, and not with dopus..
If someone has actually installed this and worked with it, I would be grateful for some input.


#9

I've managed to get it working, not sure how, but most probably just by running pyscript.py --unregister and then pyscript.py --register.

Name is Python indeed.

Short script:

[code]@script Python

def OnClick(clickData):
dlg = clickData.func.Dlg
dlg.message = 'a'
dlg.buttons='bb|cc'
dlg.icon='info'
dlg.title='ala'
dlg.Show()[/code]

Now the problem is how to get DOpus and Script objects. I assume it should look like

[code]@script Python

import win32com

do = win32com.client.Dispatch('DOpus.DOpus')

[/code]

but I cannot find any relevant in HKLM/Software/Classes to use as proper ProgIDs.

I don't know even if it is the right way, this is my first brush with Windows COM.


#10

thanks for this, but I still can't get it to work.. I get the same "Script Engine Python could not be opened" error.
I can't imagine what else could be wrong..


#11

I will reinstall ActivePerl and retry the whole config path. I do this on XP 32-bit. BTW, do *.html demos work for you in IE (for me they work)?


#12

(sorry, what are we talking about? why Perl? and what are *.html demos?)


#13

Sorry, I meant ActivePython. In the python install directory you can find a couple of html files, which enable verifying if python activex control is active.


#14

pheww.. yes the demos are working correctly..


#15

I've retried ona Windows 7 64-bit that has never seen both DOpus and ActivePython. Right after installation, the error messahe was displayed.
But after:

c:\Python33\Lib\site-packages\win32comext\axscript\client>pyscript.py --unregister c:\Python33\Lib\site-packages\win32comext\axscript\client>pyscript.py --register
I got the sample with displaying dialog working, however with extra message after closing the dialog, disappearing after removing () after dlg.Show:

[quote]Error at line 9, position 0
dlg.Show()
^
Traceback (most recent call last):
File "", line 7, in OnClick
dlg.Show()
TypeError: 'int' object is not callable
(0x80020009)[/quote]

BTW, Leo, Jon, what are proper ProgIDs for DOpus and Script?


#16

They don't have ProgIDs as you can't create them outside of Opus.

The objects already exist for scripts run inside of Opus.


#17

Do you have any idea on how they could be obtained if they are not available in default namespace?


#18

I don't know anything about Python, sorry.


#19

Xyzzy, is there a step in the process I might have overlooked? I installed latest active python on win7 x64, on a brand new installation. sample python activex scripts I've tried seem to work.. but dopus always give me the same message.


#20

You could probably be up to speed in javascript in the time spent trying to get ActivePython to work. :slight_smile:

I get the impression ActivePython is not widely used, discussed or supported (its support forum has barely had any posts in the last year, if I looked in the right place, which seems a bad sign for a programming language) and I couldn't find much info on using it to access ActiveScripting objects provided by the host application. Everything I found assumed the script would be creating objects rather than using ones provided by the host environment. Maybe it can do it but nobody seems to talk about how, that I could find at least.

I think you are making life difficult for yourself by choosing a scripting language so few people use in this domain (ActiveScripting automation). Any short-term gain from familiarity with Python's syntax is easily offset by the convenience of having lots of examples, guides and people to help you if you go the more common route (jscript or vbscript). Plus those are built into Windows, which makes scripts written in them more useful to people who don't want to install a another language just to run them.