Link in Zwischenablage kopieren
Kopiert
I am trying to run an InDesign scirpt from Photoshop using a BridgeTalk example from Paul Riggott. The InDesign part works in ESTK with InDesign as the target but not as part of a Photoshop script through BridgeTalk.
So I have some questions.
1. What am I doing wrong?
2. The script needs to work with both CS3 and CS4. Do I need to set the version in the BridgeTalk message.
3. Is there a way to test if InDesign is running. Open it if not and close it if it wasn't already running.
My code is bellow. It makes a multi page PDF for the list of 300px X 250px psd files on the desktop and saves the pdf there as well.
var myImages = new Array();
myImages.push(new File('~/Desktop/Layer Comp 1.psd'));
myImages.push(new File('~/Desktop/Layer Comp 2.psd'));
myImages.push(new File('~/Desktop/Layer Comp 3.psd'));
myImages.push(new File('~/Desktop/Layer Comp 4.psd'));
myImages.push(new File('~/Desktop/Layer Comp 5.psd'));
myImages.push(new File('~/Desktop/Layer Comp 6.psd'));
myImages.push(new File('~/Desktop/Layer Comp 7.psd'));
myImages.push(new File('~/Desktop/Layer Comp 8.psd'));
var pdfFile = new File('~/Desktop/myFirstTest.pdf')
// adapted from Paul Riggott
// Code for send message and handling response
// in the sending application (any message-enabled application)
var res = undefined;
var bt = new BridgeTalk;
bt.target = "indesign-6.0";
// the script passed to the target application
var myScript = ("var ftn = " + psRemote.toSource() + "; ftn("+myImages.toSource()+","+300+","+250+","+pdfFile+");");//define the work function and call it with arguments
bt.body = myScript;
bt.onResult = function( inBT ) {myReturnValue(inBT.body); }// call the result processing function
// send the message and wait up to 10 sec for responce
bt.send(20);
// function to process the return string
function myReturnValue(str){
//process the results. here just assign strings
res = str;
caption = str;
}
// wrap your script in a function
// this function is in whatever DOM the bridgeTalk target is.
// cann't have comments in the psRemote function
function psRemote( images, w, h, pdfFile ){
function addDocument ( w, h ){
var myDocument = app.documents.add(false);
myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;
myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;
myDocument.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;
myDocument.documentPreferences.pageWidth = w;
myDocument.documentPreferences.pageHeight = h;
myDocument.documentPreferences.facingPages = false;
var myMasterSpread = myDocument.masterSpreads.item(0);
var myMarginPreferences = myMasterSpread.pages.item(0).marginPreferences;
myMarginPreferences.left = 0;
myMarginPreferences.top = 0;
myMarginPreferences.right = 0;
myMarginPreferences.bottom = 0;
myMarginPreferences.columnCount = 1;
myMarginPreferences.columnGutter = 0;
myDocument.pages[0].appliedMaster = myMasterSpread;
return myDocument;
}
function addPage( doc ){
var page = doc.pages.add();
page.appliedMaster = NothingEnum.NOTHING;
return page;
}
function placeImage( doc, page, bounds, imageFile ){
r = page.rectangles.add();
r.geometricBounds = bounds;
r.strokeWeight = 0;
r.strokeColor = doc.swatches.item("None")
r.place ( imageFile, false );
}
function mySnippet( doc, pdfFile ){
var myDocument = doc;
with(app.pdfExportPreferences){
pageRange = PageRange.allPages;
acrobatCompatibility = AcrobatCompatibility.acrobat6;
exportGuidesAndGrids = false;
exportLayers = false;
exportNonPrintingObjects = false;
exportReaderSpreads = false;
generateThumbnails = false;
try{
ignoreSpreadOverrides = false;
}
catch(e){}
includeBookmarks = false;
includeHyperlinks = false;
includeICCProfiles = true;
includeSlugWithPDF = false;
includeStructure = false;
interactiveElements = false;
subsetFontsBelow = 0;
colorBitmapCompression = BitmapCompression.zip;
colorBitmapQuality = CompressionQuality.eightBit;
colorBitmapSampling = Sampling.none;
grayscaleBitmapCompression = BitmapCompression.zip;
grayscaleBitmapQuality = CompressionQuality.eightBit;
grayscaleBitmapSampling = Sampling.none;
monochromeBitmapCompression = BitmapCompression.zip;
monochromeBitmapSampling = Sampling.none;
compressionType = PDFCompressionType.compressNone;
compressTextAndLineArt = true;
contentToEmbed = PDFContentToEmbed.embedAll;
cropImagesToFrames = true;
optimizePDF = true;
bleedMarks = false;
colorBars = false;
cropMarks = false;
omitBitmaps = false;
omitEPS = false;
omitPDF = false;
pageInformationMarks = false;
pdfColorSpace = PDFColorSpace.unchangedColorSpace;
registrationMarks = false;
try{
simulateOverprint = false;
}
catch(e){}
useDocumentBleedWithPDF = false;
viewPDF = false;
}
myDocument.exportFile( ExportFormat.pdfType, pdfFile, false );
}
w = w+'pt';
h = h+'pt';
var bounds = ['0pt', '0pt', h, w ];
var doc = addDocument( w, h );
placeImage( doc, doc.pages.item(0), bounds, images[0] );
if( images.length > 1 ){
for( var i = 1; i < images.length; i++ ){
var page = addPage( doc );
placeImage( doc, page, bounds, images );
}
}
mySnippet( doc, pdfFile );
doc.close(SaveOptions.NO);
'done';
}
Sorry I haven't done ant tests like that so don't know.
Link in Zwischenablage kopieren
Kopiert
I don't have inDesign but this should test if its running and start it if not.
if (!BridgeTalk.isRunning("indesign")){
BridgeTalk.launch("indesign");
}
Link in Zwischenablage kopieren
Kopiert
Thanks for that Paul. Even though you don't have InDesign, do you know if BridgeTalk messages have a lenght limit? I can get short scripts to work but for some reason this will not.
Link in Zwischenablage kopieren
Kopiert
Sorry I haven't done ant tests like that so don't know.
Link in Zwischenablage kopieren
Kopiert
Turned out that there was something wrong with the message string.
Which I don't understand. I thought that wrapping the code in a function then using toSource took care of any string conversion issues.
Link in Zwischenablage kopieren
Kopiert
Mike any bridgetalk message will launch the target app if its NOT already running as long as 'body' contains some string.
In my ESTK data browser there are lots of options which come from the installed Adobe libraries for checking versioning etc.
Does all this still exist in CS3 & CS4?
In 'indesign4' [object Object] there is an 'isAppInstalledAndIsItTheLastestVersion' function() that I can use something like this…
var getID = indesign4.isAppInstalledAndIsItTheLatestVersion('indesign', 4);
if (getID) {
alert('Correct Version of ID');
if (!BridgeTalk.isRunning('indesign')) {
BridgeTalk.launch('indesign');
}
// indesign4.activate();
// indesign4.executeScriptFile(scriptPath);
}
else {
alert('Incorrect Version of ID');
}
I also have an 'apps' Array that I can check in…
var x = apps[4];
$.writeln(x);
Link in Zwischenablage kopieren
Kopiert
Thanks Mark. I found out about launching when I forgot to open InDesign before running the script.
isAppInstalledAndIsItTheLastestVersion returns false for me even though I have InDesign CS4.
Does executeScriptFile work in InDesign? It doesn't seem to work of the Photoshop version.
apps[4] for me returns bridge-2.0.
I also found BridgeTalk.getTargets() which lets you supply a version argument so BridgeTalk.getTargets(6) for me returns indesign-6.0
Link in Zwischenablage kopieren
Kopiert
Michael,
A quick test for versions is
parseInt (app.version)
which returns 10 if PS CS3 is targeted, and 6 when InDesign CS4 is targeted. Saves you some typing ![]()
As to executeScriptFile, I don't know about that, but app.doScript (...) works so maybe you could use that.
Link in Zwischenablage kopieren
Kopiert
I would agree with Peter. ID got this right app.doScript() is much better than what PS or AI have.
Link in Zwischenablage kopieren
Kopiert
Maybe I'm missing something but wouldn't app.doScript need to be run in InDesign? I am trying to get InDesign to do something from a Photoshop script so app in that case returns photoshop. Wouldn't I have to send the app.doScript to InDesign with BridgeTalk anyway?
Weitere Inspirationen, Events und Ressourcen finden Sie in der neuen Adobe Community
Jetzt ansehen