Quantcast
Viewing latest article 33
Browse Latest Browse All 84

is it possible to run a PS script from within an AI script....

I'm working on improving my workflow by automating some of the things I tend to do alot, and since I tend to go back and forth quite a bit between AI and PS I want to be able to script some of this.

 

Now I've cobbled together a basic script that will export a .pdf from illustrator and then open it up in photoshop.
what I want to be able to do is run another script on the file in PS once it's opened up (without having to go into the menu and select it each time).

I've seen examples of sending bridgetalk messages to photoshop containing a few lines of code but in my case the script I want to run is a bit more complicated so I think I would need to open up and run from the .jsx file somehow.... just not sure where to put it or how to get it to run from the first script.

 

Anyway here is my first script to export the file from illustrator and then open it up in PS, apologies if it's a little messy, I'm learning as I go....

 

var destFolder, sourceFolder, files, fileType, sourceDoc, targetFile, pdfSaveOpts;

//=============Find Current Documents path================//
var CurrentPath = activeDocument.path;
//=============Establish current documents destination===============//
var folderPDF = Folder(CurrentPath + '/' + 'PDFs for photoshop');
//=============Check if it exist, if not create it.============//
if(!folderPDF.exists) folderPDF.create();

var docName = app.activeDocument.name.match(/^.*[^.ai]/i);
var myDoc = app.activeDocument.name.match();

        if (folderPDF) {            if ( app.documents.length > 0 ) {                var sourceDoc = app.activeDocument;                targetFile = getNewName();                pdfSaveOpts = getPDFOptions2( );                sourceDoc.saveAs( targetFile, pdfSaveOpts );                sourceDoc.close();                }            }               var workingFile = File( folderPDF + '/' + docName + '.pdf' );         photoshop.open(workingFile);

 function getNewName()
{
        var ext, docName, newName, saveInFile, docName;        docName = sourceDoc.name;        ext = '.pdf';        newName = "";        for ( var i = 0 ; docName[i] != "." ; i++ )    {        newName += docName[i];    }        newName += ext;        saveInFile = new File( folderPDF + '/' + newName );        return saveInFile;
}

function getPDFOptions2()
{
        var pdfSaveOpts = new PDFSaveOptions();        pdfSaveOpts.pDFPreset = "PDF for artworks";        return pdfSaveOpts;
}


and here is the script I want to get to run on the new file in photoshop (thanks to c.pfaffenbichler for this one)


(just providing the full thing for context, it's probably not too important which script I'm trying to run, I just need to know how to call it up from within the illustrator script....or to know if it's even possible)

 

   // split color regions  of an rgb image into layers;    // 2016, use it at your own risk;    #target photoshop    if (app.documents.length > 0) {    if (app.activeDocument.mode == DocumentMode.RGB) {    var time1 = Number(timeString());    var myDocument = app.activeDocument.duplicate("theCopy", true);    var theLayer = myDocument.activeLayer;    var histo = myDocument.histogram;    var total = 0;    for (var n = 0; n < histo.length; n++) {    total = total + histo[n];    };    // collect histograms and non-0-values;    var theHistos = new Array;    for (var m = 0; m < 3; m++) {    var histo = myDocument.channels[m].histogram;    var theValues = new Array;    for (var n = 0; n < histo.length; n++) {      if (histo[n] != 0) {theValues.push(n)}      };    theHistos.push([histo, theValues])    };    ////////////////////////////////////    var theArray = new Array;    // create difference layer to determine which combinations of values exist more or less;    var theSolid = solidColorLayer (55, 128, 200, "aaa", charIDToTypeID("Dfrn"));    // try;    for (var n = 0; n < theHistos[0][1].length; n++) {    ////////////////////////////////////    for (var o = 0; o < theHistos[1][1].length; o++) {    ////////////////////////////////////    for (var p = 0; p < theHistos[2][1].length; p++) {    ////////////////////////////////////    try {    $.writeln(theHistos[0][1][n]+"___"+theHistos[1][1][o]+"___"+theHistos[2][1][p]);    changeSolidColorLayer (theHistos[0][1][n], theHistos[1][1][o], theHistos[2][1][p]);    var checkHisto = myDocument.histogram;    if (checkHisto[0] > 0) {    theArray.push([theHistos[0][1][n], theHistos[1][1][o], theHistos[2][1][p]])    };    }    catch (e) {};    ////////////////////////////////////    };    ////////////////////////////////////    };    ////////////////////////////////////    };    theSolid.remove();    // try to cut to layers;    for (var a = 0; a < theArray.length; a++) {    try {    selectColorRange (theArray[a][0], theArray[a][1], theArray[a][2], 0);    cutToLayer ();    myDocument.activeLayer = theLayer;    }    catch (e) {};    };    var time2 = Number(timeString());    alert(((time2-time1)/1000)+" seconds\nstart "+time1+"\nend "+time2)    }    };    ////// select color range //////    function selectColorRange (theR, theG, theB, fuzziness) {    // =======================================================    var idClrR = charIDToTypeID( "ClrR" );        var desc4 = new ActionDescriptor();        var idFzns = charIDToTypeID( "Fzns" );        desc4.putInteger( idFzns, fuzziness );        var idMnm = charIDToTypeID( "Mnm " );            var desc5 = new ActionDescriptor();            var idR = charIDToTypeID( "Rd  " );            desc5.putDouble( idR, theR );            var idG = charIDToTypeID( "Grn " );            desc5.putDouble( idG, theG );            var idB = charIDToTypeID( "Bl  " );            desc5.putDouble( idB, theB );        var idRGCl = charIDToTypeID( "RGBC" );        desc4.putObject( idMnm, idRGCl, desc5 );        var idMxm = charIDToTypeID( "Mxm " );            var desc6 = new ActionDescriptor();            var idR = charIDToTypeID( "Rd  " );            desc6.putDouble( idR, theR );            var idG = charIDToTypeID( "Grn " );            desc6.putDouble( idG, theG );            var idB = charIDToTypeID( "Bl  " );            desc6.putDouble( idB, theB );        var idRGCl = charIDToTypeID( "RGBC" );        desc4.putObject( idMxm, idRGCl, desc6 );        var idcolorModel = stringIDToTypeID( "colorModel" );        desc4.putInteger( idcolorModel, 0 );    executeAction( idClrR, desc4, DialogModes.NO );    };    ////// cut to layer //////    function cutToLayer () {    try {    // =======================================================    var idCtTL = charIDToTypeID( "CtTL" );    executeAction( idCtTL, undefined, DialogModes.NO );    return activeDocument.activeLayer    } catch (e) {return undefined}    };    ////// create solid color layer //////    function solidColorLayer (theR, theG, theB, theName, theBlendMode) {    // =======================================================    var idMk = charIDToTypeID( "Mk  " );        var desc10 = new ActionDescriptor();        var idnull = charIDToTypeID( "null" );            var ref1 = new ActionReference();            var idcontentLayer = stringIDToTypeID( "contentLayer" );            ref1.putClass( idcontentLayer );        desc10.putReference( idnull, ref1 );        var idUsng = charIDToTypeID( "Usng" );            var desc11 = new ActionDescriptor();            var idNm = charIDToTypeID( "Nm  " );            desc11.putString( idNm, theName );            var idMd = charIDToTypeID( "Md  " );            var idBlnM = charIDToTypeID( "BlnM" );            var idMltp = theBlendMode ;            desc11.putEnumerated( idMd, idBlnM, idMltp );            var idType = charIDToTypeID( "Type" );                var desc12 = new ActionDescriptor();                var idClr = charIDToTypeID( "Clr " );                    var desc13 = new ActionDescriptor();                    var idRd = charIDToTypeID( "Rd  " );                    desc13.putDouble( idRd, theR );                    var idGrn = charIDToTypeID( "Grn " );                    desc13.putDouble( idGrn, theG );                    var idBl = charIDToTypeID( "Bl  " );                    desc13.putDouble( idBl, theB );                var idRGBC = charIDToTypeID( "RGBC" );                desc12.putObject( idClr, idRGBC, desc13 );            var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );            desc11.putObject( idType, idsolidColorLayer, desc12 );        var idcontentLayer = stringIDToTypeID( "contentLayer" );        desc10.putObject( idUsng, idcontentLayer, desc11 );    executeAction( idMk, desc10, DialogModes.NO );    return app.activeDocument.activeLayer    };    ////// changeSolidColor //////    function changeSolidColorLayer (theR, theG, theB) {    try {    // =======================================================    var idsetd = charIDToTypeID( "setd" );        var desc17 = new ActionDescriptor();        var idnull = charIDToTypeID( "null" );            var ref2 = new ActionReference();            var idcontentLayer = stringIDToTypeID( "contentLayer" );            var idOrdn = charIDToTypeID( "Ordn" );            var idTrgt = charIDToTypeID( "Trgt" );            ref2.putEnumerated( idcontentLayer, idOrdn, idTrgt );        desc17.putReference( idnull, ref2 );        var idT = charIDToTypeID( "T   " );            var desc18 = new ActionDescriptor();            var idClr = charIDToTypeID( "Clr " );                var desc19 = new ActionDescriptor();                var idRd = charIDToTypeID( "Rd  " );                desc19.putDouble( idRd, theR );                var idGrn = charIDToTypeID( "Grn " );                desc19.putDouble( idGrn, theG );                var idBl = charIDToTypeID( "Bl  " );                desc19.putDouble( idBl, theB );            var idRGBC = charIDToTypeID( "RGBC" );            desc18.putObject( idClr, idRGBC, desc19 );        var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );        desc17.putObject( idT, idsolidColorLayer, desc18 );    executeAction( idsetd, desc17, DialogModes.NO );    return true    } catch (e) {return false}    };    ////// function to get the date //////    function timeString () {      var now = new Date();      return now.getTime()      };

 

I've tried saving it in different places and inserting this line for example into the first script (at line 25) to no avail.

 

 photoshop.executeScript("C:\test.jsx");  

 


thanks for any light you can shed on this matter!

Image may be NSFW.
Clik here to view.

Viewing latest article 33
Browse Latest Browse All 84

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>