首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如何从Powershell启动ExtendScript JSX脚本

如何从Powershell启动ExtendScript JSX脚本
EN

Stack Overflow用户
提问于 2018-10-26 04:37:29
回答 1查看 249关注 0票数 0

我希望能够通过Windows Powershell执行Adobe Illustrator ExtendScript。我相信这应该是可能的,因为this answer描述了通过COM使用VB。

这是我的Powershell脚本:

代码语言:javascript
代码运行次数:0
运行
复制
$illustratorRef = New-Object -ComObject Illustrator.Application
$conversionScript = New-Object -ComObject Scripting.FileSystemObject
$scriptFile = $conversionScript.OpenTextFile("C:\ws\ArtConversion\alert-test.jsx")
$fileContents = $scriptFile.ReadAll()
$scriptFile.Close()

$fileToRun = $fileContents + "main(arguments)"

$args = "line1", "line2"

$illustratorRef.DoJavaScript($fileToRun, $args, 1)

下面是alert-test.jsx脚本:

代码语言:javascript
代码运行次数:0
运行
复制
function main(argv) {
    alert('message: ' + argv[0]);
    return argv[0];
}

运行Powershell脚本将打开Illustrator,但在遇到$illustratorRef.DoJavaScript时会抛出以下错误

代码语言:javascript
代码运行次数:0
运行
复制
Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED))

我使用的是Adobe Illustrator 2019 CC (64位)和Powershell 5.1.16299.666

EN

回答 1

Stack Overflow用户

发布于 2018-11-03 06:08:25

我实现了我的目标,但是用Powershell不能做到100%。

2017 Adobe Illustrator Scripting Guide在第22页包含以下声明:

在Illustrator中,有多种方法可以创建VBScript实例。

然而,当提到JavaScript时,它说:

有关从JavaScript启动

的信息不在本指南的讨论范围内。

我找不到任何有关如何使用VB以外的其他语言在Windows上以编程方式启动Illustrator的官方文档,因此我最终让Powershell脚本处理目录遍历和日志记录的繁重工作,同时通过Visual Basic脚本打开Illustrator。

从Powershell到VB的调用如下所示:

代码语言:javascript
代码运行次数:0
运行
复制
$convertFile = "cmd /C cscript .\run-illustrator-conversion.vbs $arg1, $arg2"
$output = Invoke-Expression $convertFile

VB脚本最终如下所示:

代码语言:javascript
代码运行次数:0
运行
复制
Dim appRef
Dim javaScriptFile
Dim argsArr()

Dim fsObj : Set fsObj = CreateObject("Scripting.FileSystemObject")
Dim jsxFile : Set jsxFile = fsObj.OpenTextFile(".\script-to-run.jsx", 1, False)
Dim fileContents : fileContents = jsxFile.ReadAll
jsxFile.Close
Set jsxFile = Nothing
Set fsObj = Nothing

javascriptFile = fileContents & "main(arguments);"

Set appRef = CreateObject("Illustrator.Application.CS5")
ReDim argsArr(Wscript.Arguments.length - 1)

For i = 0 To Wscript.Arguments.length - 1
    argsArr(i) = Wscript.Arguments(i)
Next

Wscript.Echo appRef.DoJavaScript(javascriptFile, argsArr, 1)

注意:查看脚本指南以获取适合您的Illustrator版本的正确字符串。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52997729

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档