要调用的 VBScript JavaScript

VBScript to call JavaScript

在这里冒险。有没有办法让 Photoshop VBScript 调用 JavaScript 文件?

或者至少将一些用户输入(变量或来自函数的 return)从一个脚本传递到另一个脚本。

我这样做的原因是什么?我在这个 question 中遇到过类似的问题,并考虑过使用 VBScript UI 来驱动 photoshop 脚本。将现有的 jsx 重写到 VBS 中并不是一个真正的选择。

这是我的。这个简单的 VBScript 要求用户输入他们的名字,然后在第二个脚本中将其创建为文本。

VBScript

' Ask User for input
Dim appRef
Set appRef = CreateObject( "Photoshop.Application" )

Dim askName : askName = InputBox("Enter name: ")

JavaScript

// create a document to work with
var docRef = app.documents.add(200, 100, 72, "Hello");

// Create a new art layer containing text
var artLayerRef = docRef.artLayers.add();
artLayerRef.kind = LayerKind.TEXT;

// Set the contents of the text layer.
var textItemRef = artLayerRef.textItem
textItemRef.contents = "Hello " + askName

我需要什么来连接这两者?

我没有使用 Photoshop 编写脚本的经验,做了一些研究。

以下代码已通过 Adob​​e Photoshop® CS6 测试。

PsJavaScriptExecutionMode 枚举常量是使用 Microsoft OLE/COM Object Viewer 从 scriptingsupport.8li (Adobe Photoshop CS6 Object Library) 中提取的。

VBScript:

'PsJavaScriptExecutionMode Enums
Const psNeverShowDebugger = 1, psDebuggerOnError = 2, psBeforeRunning = 3

Dim appRef
Set appRef = CreateObject("Photoshop.Application")

Dim askName
    askName = InputBox("Enter name: ")

appRef.DoJavaScriptFile "C:\scripts\myPSscript.jsx", Array(askName), psNeverShowDebugger

JavaScript (myPSscript.jsx):

// create a document to work with
var docRef = app.documents.add(200, 100, 72, "Hello");

// Create a new art layer containing text
var artLayerRef = docRef.artLayers.add();
artLayerRef.kind = LayerKind.TEXT;

// Set the contents of the text layer.
var textItemRef = artLayerRef.textItem
var askName = arguments[0]; // first argument passed from VBScript
textItemRef.contents = "Hello " + askName;

希望对您有所帮助。


Adobe® Creative Suite® 5 Photoshop® Scripting Guide