[英]VBScript to call JavaScript
在這里走出去。 有沒有辦法讓Photoshop VBScript調用JavaScript文件?
或者至少將一些用戶輸入(變量或從函數返回)從一個腳本傳遞到另一個。
我的原因是什么? 我一直在問這個問題類似的問題,並考慮了VBScript UI來驅動photoshop腳本。 將現有的jsx重新寫入VBS並不是真正的選擇。
這就是我所擁有的。 這個簡單的VBScript要求用戶輸入其名稱,然后在第二個腳本中將其創建為文本。
VB腳本
' 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編寫腳本的經驗,做了一些研究。
以下代碼已經過AdobePhotoshop®CS6的測試。
通過使用Microsoft OLE / COM對象查看器,可以從scriptingsupport.8li
(Adobe Photoshop CS6對象庫)中提取PsJavaScriptExecutionMode
枚舉常量。
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;
希望能幫助到你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.