Scripting issues

Here everybody can post his problems with PhotoLine
User avatar
russellcottrell
Mitglied
Posts: 114
Joined: Sat 26 Jul 2014 10:13

Scripting issues

Post by russellcottrell » Wed 12 Sep 2018 22:38

Hello; I have been trying to work with scripting; than you very much for implementing it. A few thoughts; I apologize if they have been addressed elsewhere but I couldn’t find much about it.

May I propose Javascript as the “standard” scripting language? It is cross-platform, and seems better to me than “VB Script for Windows and Apple Script for Mac.” I am a Windows user and I never use VB Script, even in active server pages. I thought I saw some .js files somwhere, maybe when I installed a beta; but I seem to have lost them.

Here is a simple .js file:

Code: Select all

var pl = new ActiveXObject("PhotoLine.application");
var doc = pl.ActiveDocument;

if(doc != null)
  doc.DoOperation("Scale", "Mode", 2, "ValueX", 200, "ValueY", 200, "Interpolation", 5);

pl = null;
I have tried some other operations with mixed success. For example, according to the (VBS) documentation, this should return an array of strings, but I can’t tell that it does:

var docArray = pl.OpenDialog();

It would help if the alert() function were implemented; it is hard to debug scripts without it.

I could not find a way to create a layer; doc.LayerArray.Insert() does not work.

A number of other operations would be useful; I can’t find any documentation for them:
-set the foreground/background color
-select a rectangle
-fill the selection with color
-change document size
-rotate document
-flatten image

Also, being able to open a dialog to accept user input would be handy.

User avatar
Herbert123
Mitglied
Posts: 1735
Joined: Sat 12 May 2012 21:38

Re: Scripting issues

Post by Herbert123 » Thu 13 Sep 2018 07:54

Javascript is supported as well. The v20 beta versions included JS examples as well

JS:
var pl = new ActiveXObject("PhotoLine.application");
var doc = pl.ActiveDocument;
var page;

pl.Visible = 1;

if(doc != null)
{
page = doc.ActivePage;
if (page != null)
{
var layer = page.RootLayer.First;
while (layer != null)
{
// 1 means Image (PhotoLine.LayerType.LTImage)
if (layer.Type == 1)
layer.DoOperation("Dither", "RasterSize", 32, "Angle", 0);
layer = layer.next;
}
}
}

VB:

Dim pl
Dim doc
Dim page
Dim layer

Set pl = CreateObject("PhotoLine.Application")
Set doc = pl.ActiveDocument

pl.Visible = True

If Not doc Is Nothing Then
For Each page In doc
Set layer = page.RootLayer.First
While (Not layer Is Nothing)
' 1 means Image (PhotoLine.LayerType.LTImage)
If (layer.Type = 1) Then
layer.DoOperation "Dither", "RasterSize", 32, "Angle", 0
End If
Set layer = layer.Next
wend
Next
End If
/*---------------------------------------------*/
System: Win10 64bit - i7 920@3.6Ghz, p6t Deluxe v1, 48gb (6x8gb RipjawsX), Nvidia GTX1080 8GB, Revodrive X2 240gb, e-mu 1820, 2XSamsung SA850 (2560*1440) and 1XHP2408H 1920*1200 portrait

User avatar
Gerhard Huber
Entwickler
Entwickler
Posts: 3586
Joined: Mon 18 Nov 2002 15:30
Location: Bad Gögging

Re: Scripting issues

Post by Gerhard Huber » Thu 13 Sep 2018 08:01

Herbert123 wrote:
Thu 13 Sep 2018 07:54
Javascript is supported as well. The v20 beta versions included JS examples as well
Javascript works, but we don't support it. VBS on Windows and AppleScript on macOS are the only supported scripting languages at the moment.

Martin Huber
Entwickler
Entwickler
Posts: 3357
Joined: Tue 19 Nov 2002 15:49

Re: Scripting issues

Post by Martin Huber » Thu 13 Sep 2018 10:03

russellcottrell wrote:
Wed 12 Sep 2018 22:38
var docArray = pl.OpenDialog();
This returns a COM SAFERARRAY. In JScript it has to be converted to an JScript array by

var jscriptArray = VBArray(docArray).toArray();

See:
https://blogs.msdn.microsoft.com/david. ... afe-array/
russellcottrell wrote:
Wed 12 Sep 2018 22:38
It would help if the alert() function were implemented; it is hard to debug scripts without it.
You can use:

var msgBox = new ActiveXObject("WScript.Shell");
msgBox.Popup("text");
russellcottrell wrote:
Wed 12 Sep 2018 22:38
I could not find a way to create a layer; doc.LayerArray.Insert() does not work.
There should be some samples in Scripting folder, that create new layers:
- AdjustmentWithGradient
- NewVector
- TextNewWithPageNumber

Martin

User avatar
russellcottrell
Mitglied
Posts: 114
Joined: Sat 26 Jul 2014 10:13

Re: Scripting issues

Post by russellcottrell » Fri 14 Sep 2018 05:27

Hello, and thank you for the feedback. One little glitch is that .js runs in Wine, .vbs doesn't. I used winetricks to install wsh57, vcrun6, and vb6run; I can run a simple "Hello, world." script with wscript; but the .vbs scripts still do not run in PhotoLine. Can you suggest anything else, other dependencies that are needed?

Martin Huber
Entwickler
Entwickler
Posts: 3357
Joined: Tue 19 Nov 2002 15:49

Re: Scripting issues

Post by Martin Huber » Mon 17 Sep 2018 09:32

russellcottrell wrote:
Fri 14 Sep 2018 05:27
Hello, and thank you for the feedback. One little glitch is that .js runs in Wine, .vbs doesn't. I used winetricks to install wsh57, vcrun6, and vb6run;
I am not a Wine expert, but according to what i found that should be sufficient.
russellcottrell wrote:
Fri 14 Sep 2018 05:27
I can run a simple "Hello, world." script with wscript; but the .vbs scripts still do not run in PhotoLine. Can you suggest anything else, other dependencies that are needed?
The built-in scripts don't work either? For example "AdjustmentWithGradient"?

I think it's strange that JScript is working, but VBScript isn't.

Martin

User avatar
russellcottrell
Mitglied
Posts: 114
Joined: Sat 26 Jul 2014 10:13

Re: Scripting issues

Post by russellcottrell » Thu 29 Nov 2018 09:31

Hello; I have been able to convert just about everything I have from VBScript to JavaScript, with one exception. There is no prompt dialog for user input in JavaScript scripting. (Which is something of an outrage.) I have read that it is possible to call the VBScript function InputBox from JavaScript, but I have been unable to do it. Do you know a way, or some other way to get user input? Thank you . . . .

Martin Huber
Entwickler
Entwickler
Posts: 3357
Joined: Tue 19 Nov 2002 15:49

Re: Scripting issues

Post by Martin Huber » Thu 29 Nov 2018 15:15

russellcottrell wrote:
Thu 29 Nov 2018 09:31
Hello; I have been able to convert just about everything I have from VBScript to JavaScript, with one exception. There is no prompt dialog for user input in JavaScript scripting. (Which is something of an outrage.) I have read that it is possible to call the VBScript function InputBox from JavaScript, but I have been unable to do it. Do you know a way, or some other way to get user input? Thank you . . . .
Yes, these days there doesn't seem to be a way to display an input box easily.
With 32 bit one could "embed" VBScript code in JScript and thus using VBScript's InputBox by using ScriptControl. But Microsoft didn't bother to update it to 64 bit :-(

I will check the effort to offer an InputBox function via PhotoLine.

Martin

User avatar
russellcottrell
Mitglied
Posts: 114
Joined: Sat 26 Jul 2014 10:13

Re: Scripting issues

Post by russellcottrell » Thu 29 Nov 2018 18:14

Thank you for the assistance. This may be a long shot, but . . . I have been using the QtWeb browser to open .htm documents for user input. It is small, just a 7.5MB .exe that can go into the PhotoLine folder and be referenced by scripts very easily. It is also open source. I don’t suppose there is a way to integrate a little browser like this into PhotoLine? It would have fewer requirements than a full browser; no bookmarks, antivirus, etc., just an html interface and javascript. So it could pass the user input directly back to a script, and serve as a custom dialog box.

mwenz
Mitglied
Posts: 107
Joined: Fri 13 May 2011 23:50

Re: Scripting issues

Post by mwenz » Fri 30 Nov 2018 16:56

The reason an application such as InDesign is able to make such wonderful dialog boxes that accept and pass along user input in JavaScript is the use of the ExtendScript API. ES also obviates the inherent issues with JavaScript as it can interact with the entire DOM.

I don't use PL's scripting. I only use PL for "simple" image manipulation. As such, I have no idea whether PL's JS is ECMA based or not and as such have no idea how easily it can be extended to incorporate user input dialogs as ECMA only has a simple dialog system by design.

Martin Huber
Entwickler
Entwickler
Posts: 3357
Joined: Tue 19 Nov 2002 15:49

Re: Scripting issues

Post by Martin Huber » Mon 03 Dec 2018 17:22

mwenz wrote:
Fri 30 Nov 2018 16:56
As such, I have no idea whether PL's JS is ECMA based or not and as such have no idea how easily it can be extended to incorporate user input dialogs as ECMA only has a simple dialog system by design.
PhotoLine doesn't have a built-in language, but offers a COM interface on Windows. Any language supporting COM can be used to communicate with PhotoLine. So for example it is no problem to write a C# or VB.net application performing certain tasks.

Martin

User avatar
russellcottrell
Mitglied
Posts: 114
Joined: Sat 26 Jul 2014 10:13

Re: Scripting issues

Post by russellcottrell » Fri 11 Jan 2019 23:16

I finally tried scripting on a Mac. Does javascript work? I couldn't get it to see .js files.

Martin Huber
Entwickler
Entwickler
Posts: 3357
Joined: Tue 19 Nov 2002 15:49

Re: Scripting issues

Post by Martin Huber » Sat 12 Jan 2019 12:17

russellcottrell wrote:
Fri 11 Jan 2019 23:16
I finally tried scripting on a Mac. Does javascript work? I couldn't get it to see .js files.
There is JavaScript for Automation (JXA), but from what I've been reading, it is inferior to AppleScript, and I've never used it.
Both - AppleScript and JXA - are created using the Script Editor (an Apple application).

Martin

User avatar
russellcottrell
Mitglied
Posts: 114
Joined: Sat 26 Jul 2014 10:13

Re: Scripting issues

Post by russellcottrell » Sun 13 Jan 2019 20:30

Is there a way to convert the applescript properties and methods ("active layer", "first child", "do operation", etc.) into javascript? The usual ones do not work.

Martin Huber
Entwickler
Entwickler
Posts: 3357
Joined: Tue 19 Nov 2002 15:49

Re: Scripting issues

Post by Martin Huber » Mon 14 Jan 2019 17:47

russellcottrell wrote:
Sun 13 Jan 2019 20:30
Is there a way to convert the applescript properties and methods ("active layer", "first child", "do operation", etc.) into javascript? The usual ones do not work.
The properties should be straightforward: activeLayer, firstChild. Commands are a different thing. Basically it is doOperation, but I don't know the correct way of transferring the layer object.
That being said: I just tried translating an AppleScript script to JXA, and it didn't work. JXA is simply missing too much and is lacking documentation. I recommend against using it.

Martin