0

このスクリプトは次のことを試みています:

  • 新しいフォルダを作成する
  • すべての画像の InDesign ドキュメントをスキャンする
  • Photoshop ですべての画像をグレースケールに変換する
  • Photoshop から新しいフォルダーに新しいグレースケール画像を保存する

Photoshop で画像をグレースケールに変換するには、BridgeTalkオブジェクトを使用する必要があります。これにより、InDesign と Photoshop の間の通信が可能になります (BridgeTalkオブジェクトの使用は Ajax の形式のようです)。

これまでのところ、新しいフォルダーが作成され、InDesign が を介して Photoshop と通信しているように見えるので、ほとんどBridgeTalk機能しています。しかし、Photoshop を開いても何も起こりません。新しい画像は保存されません。また、グレースケール変換が行われているかどうかもわかりません。

コードは次のとおりです。

#target "InDesign"

var inDesignDocument = app.activeDocument;
var newFolder = createFolder(inDesignDocument); // if subdirectory images DNE, create this folder with the function below

sendImagesToPhotoshop(inDesignDocument, newFolder);

//---------------------------------------------------------------------------------------------------------------

function createFolder(doc)
{
    try
    {
    /*
         * type-casting the filePath property (of type object) into a String type;
         * must be a String type to concatenate with the subdirectory variable (also of type String)
         */
        var docPath = String(doc.filePath);
        var subdirectory = "/BLACK AND WHITE IMAGES";
    }
    catch(e)
    {
        alert(e.message);
        exit();
    }

    var imagesFolder = docPath + subdirectory; // concatenating the two variables
    if(!Folder(imagesFolder).exists)
    {
        Folder(imagesFolder).create();
    }

    return imagesFolder; // for instantiation outside of this function

} // end of function createFolder

//---------------------------------------------------------------------------------------------------------------

function sendImagesToPhotoshop(doc, folder)
{
    var imgs = doc.allGraphics;
    var fileName = "";
    var img = "";
    var imgType = "";

    for(var i = 0; i < imgs.length; i++)
    {
        if(imgs[i].itemLink != null)
        {
            fileName = imgs[i].itemLink.name;
            img = new File(folder + "/" + fileName); // each image instantiated here
            imgType = imgs[i].imageTypeName; // image type is determined here (.tif, .jpg, .png, etc..)

            alert("The file \"" + fileName + "\"\n\tis a " + imgType + " file.");

            // each image exported to the new folder here, by file type
            switch(imgType)
            {
                case "GIF":
                    alert("This script cannot convert and export the GIF file:\n\t" + fileName + " !");
                    break;

            case "JPG":
            case "EPS":
                case "PNG":
                case "TIFF":

            createBridgeTalkMessage(folder);
                    break;

                default:
                    alert("\tUnlisted image type: " + imgType + "!\nAdd this type to the switch statement.");
                    break;

            } // end of switch statement

        } // end of if statement
    } // end of for loop

} // end of function sendImagesToPhotoshop

//---------------------------------------------------------------------------------------------------------------

function createBridgeTalkMessage(imagesFolder)
{
    var bt = new BridgeTalk();
    bt.target = "photoshop";
    bt.body = saveNewImageInPhotoshop.toSource() + "(" + imagesFolder.toSource() + ");";

    bt.onError = function(e)
    {
        alert("Error: " + e.body);
    }

    bt.onResult = function(resObj){};

    bt.send();

}// end of function createBridgeTalkMessage

//---------------------------------------------------------------------------------------------------------------

    // called from function createBridgeTalkMessage
    function saveNewImageInPhotoshop(imagePath)
    {
        var photoshopDoc = "";
        app.displayDialogs = DialogModes.NO; // Photoshop statement, prevents status alerts from interrupting
        photoshopDoc.changeMode(ChangeMode.GRAYSCALE); // convert image to GRAYSCALE

        photoshopDoc.saveAs(new File(imagePath) );
        photoshopDoc.close(SaveOptions.DONOTSAVECHANGES);

    } // end of function saveNewImageInPhotoshop


これは、http: //forums.adobe.com/message/3817782 にある Kasyan Servetsky の作業に基づいています。  

4

2 に答える 2

1

ええ、私は最近、単一行のコメントで問題を経験しましたが、実際に /* ... */ を使用するとうまくいきました。URL に文字列を渡すことはできると思いますが、スラッシュ文字をエスケープする必要があります。

于 2012-07-12T10:27:01.100 に答える
0

実際の画像ファイルではなく、フォルダをPhotoshopに渡しているようです。それはおそらくあなたの問題を説明するかもしれません;)

Loic

于 2012-07-10T16:48:41.197 に答える