Copy link to clipboard
Copied
Hello everyone,
I am working on a file saving script. I am trying to figure out how to send information from bridge to my illustrator script. I need to know the file path that is active in bridge, I can do this in a bridge script by app.document.presentationPath; I am just trying to send that information to use in illustrator for my file saving.
#target "illustrator-60.064"
var targetApp = BridgeTalk.getSpecifier( "bridge-5.064");
if( targetApp ) {
var bt = new BridgeTalk;
bt.target = targetApp;
bt.body = app.document.presentationPath; //error
bt.send();
}
alert (bt);
I'm new to bridgetalk I have never used it, I know I am using it wrong hence the error lol, if anyone could get me on track it would be greatly appreciated.
Thanks!!
You will have to , once again, put your parentFolder variable into the string:
new_bt.body = "var docRef = app.activeDocument; alert('"+parentFolder"');";
Copy link to clipboard
Copied
I used this thread as a reference
Re: How to get result from BridgeTalk message?
And I used this:
#target "illustrator"
#targetengine "session"
function infoFrombr() {
var bt = new BridgeTalk;
bt.target = "bridge";
bt.body = "app.document.presentationPath;"
bt.onResult = function(resObj) {
var myResult = resObj.body;
$.writeln( "BridgeTalk result = " + myResult );
doSomethingNow( myResult );
}
bt.send();
}
function doSomethingNow( result ) {
alert(result);
}
infoFrombr();
I get an alert message in Illustrator of the file path that is open in bridge, so it is working and I am pretty excited about that!!
The only thing is, for some reason it opens the extendscript application. Is there a way for it not to do that? If not, its not the end of the world to have it open in the background.
Thanks!
Copy link to clipboard
Copied
The only thing is, for some reason it opens the extendscript application. Is there a way for it not to do that?
$.writeln() is an ESTK function
![]()
Copy link to clipboard
Copied
Thanks for your response!
I thought I had a breakthrough yesterday with getting Illustrator to alert the correct file path from bridge, but I am having trouble finding a way to do anything with that file path, like make into a variable and to use in my file save script. Here is the file script I made that I am using now.
/*
Copy and paste the file path to your destination folder and place it anywhere in the document.
*/
var docRef = app.activeDocument;
function exportFileAsEPS (destFile) {
var newFile = new File(destFile);
var saveDoc = app.activeDocument;
var saveOpts = new EPSSaveOptions();
saveOpts.saveMultipleArtboards = true;
saveDoc.saveAs( newFile, saveOpts );
}
var textRef = docRef.textFrames;
for (i=0; i < textRef.length; i++) {
var contents = textRef.contents;
var contentsStr = contents.toString();
var check = contentsStr.indexOf("Roland Heat Press");
if (check == 20) {
//Bridge has a backslash at end of path, windows explorer does not.
if (contentsStr[contentsStr.length-1] != "\\")
{
contentsStr = contentsStr + "\\"
}
var apath = contentsStr;
var bname = docRef.name.substr (0, 30);
exportFileAsEPS (apath + bname + ".eps");
docRef.close();
{ break }
}
}
It still saves time but I am trying to eliminate the step of having to copy and paste the file path. I was really hoping that was achievable through bridgetalk by getting the path from bridge and turning it into my (var apath) but if I can only use that information as an alert message that does no good. Frustrating lol
Copy link to clipboard
Copied
You should be able to make a File object from a path string, just like any other script. I think you need to make the file object to pass into the export function, most likely.
Hey, that's what I get for reading too fast- you already do this.
So, are you using the latest pasted snippet in your onResult function?
Allow me to try to redeem myself:
I think the issue was that you were getting a parent folder, not the file's path.
Google yields this: "app.document.selections[0].spec"
So I was able to get this to work here:
#target illustrator
function test(){
function infoFrombr() {
var bt = new BridgeTalk;
bt.target = "bridge";
bt.body = "app.document.selections[0].spec;"
bt.onResult = function(resObj) {
var myResult = resObj.body;
doSomethingNow( myResult );
}
bt.send();
}
function doSomethingNow( result ) {
app.open(File(result));
}
infoFrombr();
}
test();
Copy link to clipboard
Copied
Thanks for your response.
I kind of get whats going wrong. For some reason it performs the bridge talk last, even if the function is written first. In this test here, I get that the infoFrombr(); performs last because of the order of the alert messages.
#target "illustrator"
function doSomethingNow( result ) {
var apath = result;
alert(apath);
}
function infoFrombr() {
var bt = new BridgeTalk;
bt.target = "bridge";
bt.body = "app.document.presentationPath;"
bt.onResult = function(resObj) {
var myResult = resObj.body;
$.writeln( "BridgeTalk result = " + myResult );
doSomethingNow( myResult );
}
bt.send();
}
for (i = 0; i < 3; i++) {
//Happens last...
infoFrombr();
}
// Happens first
alert(apath);
// So all of the below stuff would happen before apath is defined as the correct destination folder path so it won't work.
// Not worrying about this part now. just trying to get the destination folder path as the apath variable.
/*
var docRef = app.activeDocument;
function exportFileAsEPS (destFile) {
var newFile = new File(destFile);
var saveDoc = app.activeDocument;
var saveOpts = new EPSSaveOptions();
saveOpts.saveMultipleArtboards = true;
saveDoc.saveAs( newFile, saveOpts );
}
var bname = docRef.name.substr (0, 30);
exportFileAsEPS (apath + bname + ".eps");
docRef.close();
*/
Copy link to clipboard
Copied
Well, the way bt works is not synchronous to the script which launches a bt action. Your script will completely run through, and the non-related call through bt will perform in its own timeline in a parallel universe. So, usually anything you want done to work in your script after the result of the bt call will need to be enclosed inside the bt onResult function.
Copy link to clipboard
Copied
I see. So if I do this, everything would be working chronologically correct.
function doSomethingNow( result ) {
var apath = result;
alert(apath);
}
function infoFrombr() {
var bt = new BridgeTalk;
bt.target = "bridge";
bt.body = "app.document.presentationPath;"
bt.onResult = function(resObj) {
var myResult = resObj.body;
$.writeln( "BridgeTalk result = " + myResult );
doSomethingNow( myResult );
//wont work
#target illustrator
var docRef = app.activeDocument;
function exportFileAsEPS (destFile) {
var newFile = new File(destFile);
var saveDoc = app.activeDocument;
var saveOpts = new EPSSaveOptions();
saveOpts.saveMultipleArtboards = true;
saveDoc.saveAs( newFile, saveOpts );
}
var bname = docRef.name.substr (0, 30);
exportFileAsEPS (apath + bname + ".eps");
docRef.close();
}
bt.send();
}
infoFrombr();
I am assuming it won't work because inside of bt I am targeting bridge, so it doesn't know what the Illustrator DOM is.
Copy link to clipboard
Copied
your stuff for Illustrator should be inside the doSomething()
Copy link to clipboard
Copied
Thanks for barring with me, I am still getting an error, maybe it just can't be done lol.
function doSomethingNow( result ) {
var apath = result;
alert(apath);
#target illustrator
var docRef = app.activeDocument; // right here it's telling me the document doesn't exist
function exportFileAsEPS (destFile) {
var newFile = new File(destFile);
var saveDoc = app.activeDocument;
var saveOpts = new EPSSaveOptions();
saveOpts.saveMultipleArtboards = true;
saveDoc.saveAs( newFile, saveOpts );
}
Copy link to clipboard
Copied
your #target illustrator should be outside of the function, because you are calling bt from Illustrator, and your onResult is performed in Illustrator. Don't give up. Soon you shall be teaching others.
(But, first, make sure that your braces are matching up)
It should go like the one example I had up top which is working.
Copy link to clipboard
Copied
#target illustrator
function test(){
function infoFrombr() {
var bt = new BridgeTalk;
bt.target = "bridge";
bt.body = "app.document.presentationPath;"
bt.onResult = function(resObj) {
var myResult = resObj.body;
doSomethingNow( myResult );
}
bt.send();
}
function doSomethingNow( result ) {
var parentFolder = result + "\\"
alert (parentFolder)
var docRef = app.activeDocument; //error
}
infoFrombr();
}
test();
Thanks for the encouragement. I'm still getting the same error however. Btw how do you embed the cool list to view your code on, is it the html mode?
Copy link to clipboard
Copied
So, do you have an active document in your Illustrator? If you do not, you will certainly get the error.
To do syntax highlighting, use "use advanced editor" and click the blue >> to reveal the menu for it. I like to paste my code first, then highlight, then use the syntax highlighting. Otherwise, it used to give me problems when pasting into a syntaxed area.
Copy link to clipboard
Copied
Thanks, yea I have an active document open. I've never had an error for that before, weird.
Copy link to clipboard
Copied
Okay, so what does the read, exactly? Hmm also there should be semicolons in your doSomething. Perhaps they are causing a problem.
Copy link to clipboard
Copied
#target illustrator
function test(){
function infoFrombr() {
var bt = new BridgeTalk;
bt.target = "bridge";
bt.body = "app.document.presentationPath;"
bt.onResult = function(resObj) {
var myResult = resObj.body;
doSomethingNow( myResult );
}
bt.send();
}
function doSomethingNow( result ) {
var parentFolder = result + "\\";
// alert (parentFolder);
var docRef = app.activeDocument; //error
}
infoFrombr();
}
test();
The error at the bottom says "There is no document". Not sure why that is because I have a document open, and I copied and pasted that line in a separate script and ran it and no error came up. Weird stuff
Copy link to clipboard
Copied
Oh DERP!!!! I am SO used to only targeting Illustrator with bridgetalk that I completely overlooked that it's targeting bridge! Doy!
Okay, please try the following. We are going to make a bridgetalk inside a bridgetalk and this stubborn error will be conquered!
Notice how it's a whole lot more elaborate than a regular script due to having to send it via string. The myResult which contains the file paths needs to have quotes around it, to make it a string. Within the script string.
#target illustrator
function test(){
function infoFrombr() {
var bt = new BridgeTalk;
bt.target = "bridge";
bt.body = "app.document.selections[0].spec;"
bt.onResult = function(resObj) {
var myResult = resObj.body;
var new_bt = new BridgeTalk;
new_bt.target = "illustrator";
new_bt.body = "app.open(File('"+myResult+"'));var doc = app.activeDocument; alert(doc.name);";
new_bt.send();
}
bt.send();
}
infoFrombr();
}
test();
Edit: to vindicate you, you were absolutely right! It was indeed not sensing the DOM, thank you for bearing with me instead of the other way around!!
* for long scripts, they usually have functions to stringify either functions, or entire .jsx files. There are some custom bridgetalkEncode functions people have used to send their scripts through bt thus that return characters are preserved in strings, for example.
** In fact, I have been so used to only targeting AI, I assumed that onResult would be correctly performed in the #target-ed app. However, this demonstrates that to have the proper DOM, it really should go via BT.
Copy link to clipboard
Copied
#target illustrator
function test(){
function infoFrombr() {
var bt = new BridgeTalk;
bt.target = "bridge";
bt.body = "app.document.presentationPath;"
bt.onResult = function(resObj) {
var myResult = resObj.body;
var parentFolder = myResult + "\\";
//This alert happens first, so I know parentFolder gets identified correctly!
alert(parentFolder);
var new_bt = new BridgeTalk;
new_bt.target = "illustrator";
//This one works, so it bypasses the error we had before!
new_bt.body = "var docRef = app.activeDocument; alert(docRef.name);";
//This one does not work for some reason, the script gets very angry lol
//new_bt.body = "var docRef = app.activeDocument; alert(parentFolder);";
new_bt.send();
}
bt.send();
}
infoFrombr();
}
test();
Thanks for all of your help I really appreciate it. It seems to recognize the active document now. For some reason, it will not display the parentFolder variable that was identified beforehand in the first bridge talk. It will actually open a new tab in the extendtoolkit and place just that one line of code in it, something I have never seen before haha.
Copy link to clipboard
Copied
You will have to , once again, put your parentFolder variable into the string:
new_bt.body = "var docRef = app.activeDocument; alert('"+parentFolder"');";
Copy link to clipboard
Copied
#target illustrator
#targetengine "session"
function test(){
function infoFrombr() {
var bt = new BridgeTalk;
bt.target = "bridge";
bt.body = "app.document.presentationPath;"
bt.onResult = function(resObj) {
var myResult = resObj.body;
var parentFolder = myResult + "\\";
var new_bt = new BridgeTalk;
new_bt.target = "illustrator";
new_bt.body = "var docRef = app.activeDocument; var bname = docRef.name.substr (0, 30); function exportFileAsEPS (destFile) {var newFile = new File(destFile); var saveDoc = app.activeDocument; var saveOpts = new EPSSaveOptions(); saveOpts.saveMultipleArtboards = true; saveDoc.saveAs( newFile, saveOpts );} exportFileAsEPS ('"+parentFolder+"' + bname + '.eps'); docRef.close();";
new_bt.send();
}
bt.send();
}
infoFrombr();
}
test();
Thanks for all of your help I really appreciate it. This appears to be working, I don't know anything about the engines but "session" seems to work when I slide it into my file. Really cool, I am pretty hyped up about this haha. Thanks again!!
Copy link to clipboard
Copied
To add to this, I found my all-purpose workaround for having to send bt messages and having to do string-replacement on the bt message bodies to include my general-scope code (such as for document manipulation), is to send the entire script wrapper function as the message, and have some arguments passed in which can affect which of the functions inside would be ran at this time.
Copy link to clipboard
Copied
It will actually open a new tab in the extendtoolkit and place just that one line of code in it, something I have never seen before haha.
It does that because the error is raised for an undefined variable. Usually when you run a script in ESTK, you get an error message highlighted on the line of code that is suspected to be offensive. Now, when the script is actually not a .jsx file, but string sent via bridgetalk, the script is in limbo: there's no parent file for it. So what it does is put your bt.body into a new ESTK document and says: Hey, there's a fault in this script here.
Copy link to clipboard
Copied
Sorry I should have clarified, apath is for the parent folder. The correct parent folder is what I have opened in bridge, so I am just adding the filename to the end of that that's what bname is. When I export I put the eps files in a separate location.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now