我希望能够通过Windows Powershell执行Adobe Illustrator ExtendScript。我相信这应该是可能的,因为this answer描述了通过COM使用VB。
这是我的Powershell脚本:
$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
脚本:
function main(argv) {
alert('message: ' + argv[0]);
return argv[0];
}
运行Powershell脚本将打开Illustrator,但在遇到$illustratorRef.DoJavaScript
时会抛出以下错误
Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED))
我使用的是Adobe Illustrator 2019 CC (64位)和Powershell 5.1.16299.666
发布于 2018-11-02 22:08:25
我实现了我的目标,但是用Powershell不能做到100%。
2017 Adobe Illustrator Scripting Guide在第22页包含以下声明:
在Illustrator中,有多种方法可以创建VBScript实例。
然而,当提到JavaScript时,它说:
有关从JavaScript启动
的信息不在本指南的讨论范围内。
我找不到任何有关如何使用VB以外的其他语言在Windows上以编程方式启动Illustrator的官方文档,因此我最终让Powershell脚本处理目录遍历和日志记录的繁重工作,同时通过Visual Basic脚本打开Illustrator。
从Powershell到VB的调用如下所示:
$convertFile = "cmd /C cscript .\run-illustrator-conversion.vbs $arg1, $arg2"
$output = Invoke-Expression $convertFile
VB脚本最终如下所示:
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版本的正确字符串。
https://stackoverflow.com/questions/52997729
复制相似问题