Fireworks CS4 automated scripting with Javascript
Finding any information on command line scripting for Fireworks CS4 was difficult. Below is an example script to get you started, along with some hard-to-find resources below. Feel free to add other examples / links to the comments section, so that hopefully this page can become a helpful resource to others.
This script goes across all layers in a Fireworks animated GIF source file (PNG format). It replaces all text layers of a specific name with specific text. I used Ruby to dynamically generate the "process_image( ... )" calls, as a way to iterate through many source files and save animated GIF's with variable text in them.
Save the file with a .jsf extension, and to call it from a Ruby command script, simply do:
Article with some information, and a few helpful links to resources:
http://www.adobe.com/devnet/fireworks/articles/demo_current_document_command.html
Link to PDF API documentation:
http://help.adobe.com/en_US/Fireworks/9.0_Extending/fireworks_cs3_extending.pdf
Fireworks Help
http://help.adobe.com/en_US/Fireworks/10.0_Using - (Automating Tasks)
Javscript source of existing Fireworks plugins found here (on a Mac machine using CS4). This is a good way to learn the scripting language by viewing plugins' source code:
This script goes across all layers in a Fireworks animated GIF source file (PNG format). It replaces all text layers of a specific name with specific text. I used Ruby to dynamically generate the "process_image( ... )" calls, as a way to iterate through many source files and save animated GIF's with variable text in them.
try
{
process_image( "hello world" );
process_image( "konichi wa sekai")
}
catch(e)
{
alert(e);
}
// this will insert text into every text layer (of every state, if an animated GIF) called "dynamic_text"
function process_image( text )
{
var dom = fw.openDocument( "foo.png" );
if ( dom == null )
{
alert( "Could not open fireworks file: foo.png" );
return;
}
if ( !iterate_and_replace_layers( dom, text ) )
{
alert( "Did not find a layer to replace in " + source_file + ". Be sure you have the updated source files." );
return;
}
var opts = new ExportOptions();
opts.exportFormat = "GIF animation";
var output = save_directory + source_file_name + '_' + phone_number + '_' + creative_id + '.gif';
var save_result = fw.exportDocumentAs( dom, output, opts );
fw.closeDocument( dom, false );
}
function iterate_and_replace_layers( dom, text )
{
var layer_replaced = false;
for(var i = 0 ; i < dom.frames.length ; i++)
{
for(var j = 0 ; j < dom.frames[i].topLayers.length - 1 ; j++)
{
var topLayer = dom.frames[i].topLayers[j];
var elems = topLayer.elemsandsublayers;
for(var k = 0; k < elems.length; k++)
{
// add to layer
if ( elems[k].name == "dynamic_text" )
{
set_text( elems[k], number );
layer_replaced = true;
}
}
}
}
return layer_replaced;
}
function set_text( element, number )
{
var runs = element.textRuns;
var runsArray = new Array();
runsArray[0] = { changedAttrs: {}, characters: number };
runs.textRuns = runsArray;
element.textRuns = runs;
}
Save the file with a .jsf extension, and to call it from a Ruby command script, simply do:
system( "open script_fw.jsf" )
Article with some information, and a few helpful links to resources:
http://www.adobe.com/devnet/fireworks/articles/demo_current_document_command.html
Link to PDF API documentation:
http://help.adobe.com/en_US/Fireworks/9.0_Extending/fireworks_cs3_extending.pdf
Fireworks Help
http://help.adobe.com/en_US/Fireworks/10.0_Using - (Automating Tasks)
Javscript source of existing Fireworks plugins found here (on a Mac machine using CS4). This is a good way to learn the scripting language by viewing plugins' source code:
~/Applications/Adobe Fireworks CS4/Configuration/commands/
Labels: javascript, tech

0 Comments:
Post a Comment
Links to this post:
Create a Link
<< Home