Working example of script with python?

Brevity and clarity are two very different things.

There are also many ways to write that code in VBScript. I could have used regular expressions in VBScript but prefer not to. I didn't expect something I wrote quickly to solve a problem would become the ambassador piece of code for the language to be compared against others, either.

I'm not here to defend VBScript -- I think it's a terrible language -- but these comparisons are a bit silly.

[quote="leo"]
I'm not here to defend VBScript -- I think it's a terrible language -- but these comparisons are a bit silly.[/quote]

This is right... almost. While for a couple of small tasks there is not much difference regarding language choice, if any - if one plans to grow with time, choosing the right thing at the beginning saves your time, energy, creativity - everything.

While I don't like everything about Python, for the purpose of scripting with DO, it is just the best tool (and I have been using perl as well, and a bit of VB, plus I know Java and C++ pretty well, as for non-programmer).

ActivePython with xyzzy's script results in the error shown below when I save the script to Opus' Script Addins folder. What am I doing wrong?

I also tried Python.org's v3.4 and, like sfranky, consistently get the error "Script Engine 'python' could not be opened". sfranky, did you ever manage to get a Python script to work?

I'm running Opus v11.4.1 64-bit.

Regards, AB


Script add-ins don't use @script.

[quote="aussieboykie"]
I also tried Python.org's v3.4 and, like sfranky, consistently get the error "Script Engine 'python' could not be opened".[/quote]

Have you installed pywin32 as well (despite its name - it has also 64-bit version)? This is what enables Windows-specific 'things' in python.

@aussieboykie: nope, but i'm not really aware of how this whole thing works. I didn't even know there was a difference between script add-ins and other scripts.

After Jon pointed out my problem (see above) I copied your code into a button.

[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]
When clicked, the script runs, apparently successfully, but no dialog pops up.

Successfully initialized 'Python' engine Script started successfully Script completed
What am I missing? Do I need to install pywin32 in addition to ActivePython? Anything else?

Regards, AB

For ActivePython you don't need pywin32 - it's included. You need it only for plain python.org version.
Could you check if the popped-up dialog is not hidden somewhere in the background?
Could you try to change dlg.Show into dlg.Show() (I remember some strange things around this call - and still I am not sure why it worked without () for me)

i still can't make anything work ;(
Script Engine 'Python' could not be opened..

[quote="sfranky"]i still can't make anything work ;(
Script Engine 'Python' could not be opened..[/quote]

ActivePython? Did you run pyscript.py --register? What was the output?

You can always post to python-win32 mailing list. Mark Hammond answers there.

Can you make it work with wscript and some short pys script? Some samples here: icodeguru.com/WebServer/Pyth ... 2/ch21.htm

Xyzzy - I am intrigued as to how you are able to get your Python driven dialog to work from a button. I have now tried your button code in two clean Windows 7 64-bit VMs, one configured with ActivePython and the other with Python.org + PyWin. In both environments, the button generates log output indicating no errors..

Successfully initialized 'Python' engine Script started successfully Script completed
.. but no pop-up dialog ever appears. Python is evidently registered properly on my system as confirmed by the successfully initialised message. I am using Opus 11.4.1 (Beta) x64 with a stock configuration. Any idea as to what you might have done that I have not?

Regards, AB

[quote="aussieboykie"]Xyzzy - I am intrigued as to how you are able to get your Python driven dialog to work from a button. I have now tried your button code in two clean Windows 7 64-bit VMs, one configured with ActivePython and the other with Python.org + PyWin. In both environments, the button generates log output indicating no errors..
[/quote]

I will check this sample again with the latest DO and post results.

[quote="Xyzzy"]
I will check this sample again with the latest DO and post results.[/quote]

Hmm, it just works here.

I took a fresh VM of W2k8 R2 64-bit (no Win 7 at hand) with some base software (antivirus, drivers - no updates).
Installed the following packets in this order (no reboots, all default selections for python packages, all integration/replacement options for DO unselected in installer):

  • python-3.4.0.amd64.msi
  • pywin32-219.win-amd64-py3.4.exe
  • DOpusInstall64.exe ( 11.4 b5229)

Created button


Clicked it and got the dialog


Could you try to debug data to a file or DO log? Do you get dlg object correctly, what Show returns etc?

Aaargh! A basic error on my behalf. I had the button set as a STANDARD button instead of a SCRIPT button.

Apologies.... AB :blush:

Xyzzy, would you mind posting a sample script to demonstrate using the DOpus object with Python?

Regards, AB

[quote="Xyzzy"][quote="sfranky"]i still can't make anything work ;(
Script Engine 'Python' could not be opened..[/quote]

ActivePython? Did you run pyscript.py --register? What was the output?

You can always post to python-win32 mailing list. Mark Hammond answers there.

Can you make it work with wscript and some short pys script? Some samples here: icodeguru.com/WebServer/Pyth ... 2/ch21.htm[/quote]

sorry for the late reply, i'm struggling to find some free time to test this..thanks for the suggestions!
The pyscript.py --register was the first thing you suggested, so yes, i tried that and it seems to be working fine:

Requesting elevation and retrying...
Registered: Python

I had also tried some activescript tests as proposed by you again i think, and they seemed to be working.
Any other suggestions? Anyone?

No need. I played around some more and have managed to get some simple stuff working with the DOpus object. Not everything works as expected but given that (a) Python is not formally supported and (b) I'm no Python expert, I will keep quiet and wait to see what develops.

Regards, AB

No need. I played around some more and have managed to get some simple stuff working with the DOpus object. Not everything works as expected but given that (a) Python is not formally supported and (b) I'm no Python expert, I will keep quiet and wait to see what develops.
[/quote]

Good you made if work. There are some still issues I post to this forum - adding (python) to subject. Please post there if you have different observations.

What about are you talking about? Python? Or ActivePython? ActivePython is not a must, it is just convenient packaging. As for Python + pywin32, there is lots of support. Mark Hammond, the author of pywin32, answers questions related to pywin32, much as you do here.
No support, no community? Please... : wiki.python.org/moin/LocalUserGroups

And here's actual TIOBE tiobe.com/index.php/content/ ... index.html