Skip to main content
Inspiring
February 4, 2013
Answered

Error on .run() in bridge script

  • February 4, 2013
  • 1 reply
  • 766 views

Hello,

Can someone please help me on why the script is crashing on the createThumbnails().run(); line because i am pretty new to this.

Thanks!

#target bridge

function createThumbnails()

{

    try

    {

        this.requiredContext = "\tExecute against Bridge main engine.\nBridge must be running.";

        $.level = 1; // Debugging level

        this.panelRef = null;

        //alert(arguments[0]);

        Folder("c:\\temp\\centraliser").create();

        var loc = new Thumbnail(Folder("/C"));

        loc.open();

        this.t = new Thumbnail(File("/c/temp/aaa/BIB2.ai"));

        app.document.select(this.t);

     }

    catch(e) {

        alert( e + ":" + e.line );

    }

}

createThumbnails.prototype.run = function()

{

    if(!this.canRun())

    {

        return false;

    }

    var bmd = new BitmapData(this.t.spec);

    if(bmd instanceof BitmapData)

    {

        var expPath = "C:\\temp\\centraliser\\" + this.t.name + ".jpg";

        bmd.exportTo(new File(expPath));

        return true;

    }

    $.writeln("ERROR:: Cannot render thumb");

    return false;

}

createThumbnails.prototype.canRun = function()

{

    if(BridgeTalk.appName == "bridge") { return true; }

    $.writeln("ERROR:: Cannot render thumb");

    $.writeln(this.requiredContext);

    return false;

}

if(typeof(createThumbnails_unitTest)  == "undefined") {

    createThumbnails().run();

}

This topic has been closed for replies.
Correct answer Paul Riggott

Is this what you are trying to do?

#target bridge

main();

function main(){   

var outputFolder = Folder("/c/temp/centraliser");

if(!outputFolder.exists) outputFolder.create();

var sourceFile = File("/c/temp/aaa/BIB2.ai");

var Name = decodeURI(sourceFile.name).replace(/\.[^\.]+$/, '');

if(!sourceFile.exists){

    alert("source file does not exist!");

    return;

    }

var t = new Thumbnail(sourceFile);

var bmd = new BitmapData(t.spec);

if(bmd instanceof BitmapData) {

        var expPath = outputFolder + "/" + Name + ".jpg";

        bmd = bmd.rotate(t.rotation);

        bmd.exportTo(new File(expPath));

    }

}

1 reply

Paul Riggott
Paul RiggottCorrect answer
Inspiring
February 4, 2013

Is this what you are trying to do?

#target bridge

main();

function main(){   

var outputFolder = Folder("/c/temp/centraliser");

if(!outputFolder.exists) outputFolder.create();

var sourceFile = File("/c/temp/aaa/BIB2.ai");

var Name = decodeURI(sourceFile.name).replace(/\.[^\.]+$/, '');

if(!sourceFile.exists){

    alert("source file does not exist!");

    return;

    }

var t = new Thumbnail(sourceFile);

var bmd = new BitmapData(t.spec);

if(bmd instanceof BitmapData) {

        var expPath = outputFolder + "/" + Name + ".jpg";

        bmd = bmd.rotate(t.rotation);

        bmd.exportTo(new File(expPath));

    }

}

abjellyAuthor
Inspiring
February 5, 2013

ok thanks