Ask a Question related to Macromedia Fireworks, Design and Development.
-
Coen Naninck #1
Re: Back to Batch -- Requires Active Document?
Please share the code of the script so I can take a look at it.
Also, if you want to avoid returning to the My Pictures folder, download
TweakUI from Microsoft for you operating system and set the folder
(temporarily) to a new location (for example where you want your output
to be!). See the image at the referring url for details where to set this.
Referring URL: [url]http://members.home.nl/forum/tweakui.jpg[/url]
HTH
GLMoore wrote:
--> Back to FW Batch routine ... I have about a dozen folders with as few as 6
> and as many as 200 jpg files to be rescaled.
>
> I ran the batch on the first set of 6 files, established the scale (Scale to
> Fit Area) and the custom location for the batch output. I saved these
> settings as a script, and then used the script on the second set of 6 files.
> Both these ran OK.
>
> But on the third set of files, the batch process terminates almost
> immediately and displays this message:
>
> "Could not run the script. This command requires an active document."
>
> I can batch process if I set it up by hand, but not using the script. This
> is a time-waster on par with the fact that each new batch process request
> returns me to "My Pictures" folder instead of going back to the directly I
> was last working in, so I need to re-navigate each time ...
>
> What does the message refer to and what is required to cure the problem?
>
> Thanks for your assistance,
>
> GLMoore
>
>
Kind regards,
Coen Naninck
_______________________________
Please, don't E-mail me about Fireworks questions. Post them on the Forum.
If you are sending me a file on my own request for help purposes,
then please include the thread subject header.
E-mail : ccnk at home.nl
================================
Enhance Fireworks with these Productivity Resources
DevNet
[url]http://www.macromedia.com/devnet/mx/fireworks/[/url]
Styles
[url]http://www.macromedia.com/devnet/mx/fireworks/articles/style_samples.html[/url]
[url]http://wetworks.nl/freestyler[/url]
[url]http://richiebee.ca/fireworks.htm[/url]
Flash Panels
[url]http://www.macromedia.com/devnet/mx/studio/articles/fw_command_in_flash.html[/url]
Coen Naninck Guest
-
Get the name of active document
Good Morning, I want to know if it's possible to automatically insert the filename of an image in the "Titolo Documento" of the FileInfo Thanks... -
Run Batch File when user Saves a Document
I am trying to figure out how to do this. I want to be able to run a batch file whenever the users saves any document. Is this possible? I... -
Correct way to document.write a flash movie??? A workaround for the IE active content
Hey all, Ive been told to try a javascript document.write solution for the IE active content issue. I am trying: <script... -
Back to... document "appearance (8.5X11)" vs artboard size...
My new printshop (who I just started working with, and is conveniently located right down the street) is convinced that although I sized my .ai... -
Batch- New Document
I am in a pickle. I've written 6 or 7 batches. The first action in each batch begins with "set file info for current document" or "convert to... -
GLMoore #2
Re: Back to Batch -- Requires Active Document?
I tried posting the code but I get an error msg that says
Outlook Express could not post your message. Subject 'Re: Back to Batch --
Requires Active Document?', Account: 'forums.macromedia.com', Server:
'forums.macromedia.com', Protocol: NNTP, Server Response: '441 437 Article
exceeds local limit of 10000 bytes', Port: 119, Secure(SSL): No, Server
Error: 441, Error Number: 0x800CCCA9
Is there some part in particular I should post, or is there an email address
to which I can send the text of the entire script?
Thanks,
GLMoore
Coen Naninck <ccnkHAHA@home.nl> wrote in message
news:bjsr9s$bep$1@forums.macromedia.com...6> Please share the code of the script so I can take a look at it.
> Also, if you want to avoid returning to the My Pictures folder, download
> TweakUI from Microsoft for you operating system and set the folder
> (temporarily) to a new location (for example where you want your output
> to be!). See the image at the referring url for details where to set this.
>
> Referring URL: [url]http://members.home.nl/forum/tweakui.jpg[/url]
>
> HTH
>
> GLMoore wrote:
>> > Back to FW Batch routine ... I have about a dozen folders with as few as(Scale to> > and as many as 200 jpg files to be rescaled.
> >
> > I ran the batch on the first set of 6 files, established the scalefiles.> > Fit Area) and the custom location for the batch output. I saved these
> > settings as a script, and then used the script on the second set of 6This> > Both these ran OK.
> >
> > But on the third set of files, the batch process terminates almost
> > immediately and displays this message:
> >
> > "Could not run the script. This command requires an active document."
> >
> > I can batch process if I set it up by hand, but not using the script.request> > is a time-waster on par with the fact that each new batch processI> > returns me to "My Pictures" folder instead of going back to the directly[url]http://www.macromedia.com/devnet/mx/studio/articles/fw_command_in_flash.html[/url]>> > was last working in, so I need to re-navigate each time ...
> >
> > What does the message refer to and what is required to cure the problem?
> >
> > Thanks for your assistance,
> >
> > GLMoore
> >
> >
> --
>
>
> Kind regards,
>
> Coen Naninck
> _______________________________
>
> Please, don't E-mail me about Fireworks questions. Post them on the Forum.
>
> If you are sending me a file on my own request for help purposes,
> then please include the thread subject header.
>
> E-mail : ccnk at home.nl
>
> ================================
> Enhance Fireworks with these Productivity Resources
>
> DevNet
>
> [url]http://www.macromedia.com/devnet/mx/fireworks/[/url]
>
> Styles
>
> [url]http://www.macromedia.com/devnet/mx/fireworks/articles/style_samples.html[/url]
> [url]http://wetworks.nl/freestyler[/url]
> [url]http://richiebee.ca/fireworks.htm[/url]
>
> Flash Panels
>
>>
GLMoore Guest
-
Coen Naninck #3
Re: Back to Batch -- Requires Active Document? ** The Code **
// Macromedia Fireworks Batch Script Template
// Copyright (c) 1998, 1999, 2000 Macromedia. All rights reserved.
var gBatchOperationsArray =
[
"operation:scale"
]
;
var gBatchSettings =
{
doBackupFiles:true,
findAndReplaceParms:null,
batchScaleParms:{
percentScale:100,
xSize:-300,
ySize:-300,
cropTop:0,
cropLeft:0,
cropBottom:0,
cropRight:0,
applyScale:true,
useScale:false,
crop:false
},
batchRenameParms:null,
outputDir:"file:///C|/ArtResources/CanterburyArt/ForEveryBody/Resized",
doIncrementalBackup:true,
exportOptions:null,
overwriteExstFiles:false
}
;
// ----------------------------------------------------------
if (this.fw == null) {
var msg = Errors.EBadJsVersion;
if (msg == null)
msg = "This script does not work in this version of Fireworks.";
alert(msg);
theDocList = null;
} else {
fw.checkFwJsVersion(0);
if (theDocList == null || theDocList.length == 0) {
theDocList =
App.chooseScriptTargetDialog(App.getPref("MultiFil eBatchTypes"));
}
}
if (theDocList == null) {
// The user must have canceled the "select files" dialog.
} else if (theDocList.length == 0) {
// The user did something like "current files" when no files are open.
alert(Errors.ENoFilesSelected);
} else {
App.progressCountCurrent = 0;
App.progressCountTotal = theDocList.length;
for (var i = 0; i < theDocList.length; i++) {
App.progressCountCurrent = i + 1;
App.batchStatusString = "";
if (ProcessOneDocPath(theDocList[i]) == false)
break;
}
}
// ----------------------------------------------------------
function ProcessOneDocPath(docPathName)
{
var result = true;
var theDocWasOpen = false;
var theDoc = App.findOpenDocument(docPathName);
if (theDoc == null) {
theDoc = App.openDocument(docPathName, false);
theDocWasOpen = false;
} else {
theDocWasOpen = true;
}
if (ProcessOneDoc(theDoc) == false)
result = false;
if (theDoc != null && theDocWasOpen == false)
theDoc.close(false); // discard changes
return result;
}
// ----------------------------------------------------------
function ProcessOneDoc(theDoc)
{
fw.setActiveWindow(theDoc);
// If sourceDocumentPath is null, the file is either a new document,
// was opened as untitled (e.g., via stationery), or is a nonnative
// file format (e.g., .psd). In these cases, get the revert file path.
// If *that* is null, abort.
var sourceDocumentPath = theDoc.filePathForSave;
if (sourceDocumentPath == null)
sourceDocumentPath = theDoc.filePathForRevert;
if (sourceDocumentPath == null) {
alert(Errors.EInternalError);
return false;
}
App.batchStatusString = Files.getFilename(sourceDocumentPath);
var batchSettings = gBatchSettings;
// Handle backup options before looping.
if (batchSettings && (batchSettings.doBackupFiles)) {
backupPath = GetBackupFile(sourceDocumentPath,
batchSettings.doIncrementalBackup);
if (backupPath == null) {
return false;
}
var errorString = SafeMoveFileTo(sourceDocumentPath, backupPath);
if (errorString != null) {
alert(errorString);
return false;
}
// Note that Files.swap(), and thus SafeMoveFileTo(), will change
theDoc to
// refer to backupPath rather than sourceDocumentPath. We don't want
this,
// so we force the issue by setting it back to what we want. Note
also that
// it is not necessarily the case that theDoc.filePathForSave ==
sourceDocumentPath
// (e.g., if the document was not originally a native Fireworks
file), so we
// really only want to reset it if it changed.
if (theDoc.filePathForSave == backupPath) {
theDoc.filePathForSave = sourceDocumentPath;
}
}
// These are always done last, regardless of where they are in the list.
var donelast = {
doRename:false,
doExport:false,
};
for (var i = 0; i < 1000; i++) {
if (gBatchOperationsArray[i]) {
if (ProcessOneDocForOneBatch(
theDoc,
sourceDocumentPath,
gBatchOperationsArray[i],
batchSettings,
donelast) == false)
return false;
} else {
break;
}
}
// Only go through the DoRename function if:
// 1. We are NOT exporting - if we are exporting, renaming is taken
care of there.
// 2. The file is a FW png file (i.e., has a savefile) - if it is
not, it exports by default.
if ((donelast.doRename) && (!donelast.doExport) &&
(theDoc.filePathForSave != null)) {
// NOTE: DoRename only renames original if original file is overwritten.
// If a (*different*) custom output is specified, renaming is taken
care of there
DoRename(theDoc, sourceDocumentPath, batchSettings);
}
// If we are exporting, doExport takes care of exporting to the right
location.
if (donelast.doExport) {
DoExport(theDoc, sourceDocumentPath, batchSettings);
} else {
if (theDoc.filePathForSave == null) {
// It's a non-FW file. We must export in order to "save".
DoForceExport(theDoc, sourceDocumentPath, batchSettings);
} else {
if (!batchSettings.overwriteExstFiles) {
// If there is a custom destination, alter theDoc.filePathForSave
// to point to the desired custom destination, and save again.
DoFillInCustomDestinationForSave(theDoc, sourceDocumentPath,
batchSettings);
}
theDoc.save(false);
}
}
return true;
}
// ----------------------------------------------------------
function DoForceExport(theDoc, sourceDocumentPath, batchSettings)
{
var curExportFormatOptions = theDoc.exportFormatOptions;
// Always disable cropping.
curExportFormatOptions.crop = false;
var theDir = Files.getDirectory(sourceDocumentPath);
if (!batchSettings.overwriteExstFiles) {
theDir = batchSettings.outputDir;
}
var theName = Files.getFilename(sourceDocumentPath, true).toString();
// strip extension, if any, and ensure string-ness
var theExtension = Files.getExtension(sourceDocumentPath).toString();
if (batchSettings.batchRenameParms) {
if (batchSettings.batchRenameParms.filenamePrefix != null)
theName = batchSettings.batchRenameParms.filenamePrefix + theName;
if (batchSettings.batchRenameParms.filenameSuffix != null)
theName = theName + batchSettings.batchRenameParms.filenameSuffix;
}
// re-add the original extension, if any. (Note that exportTo() will
replace this
// extension with the correct one for the export format, if
necessary, but re-adding
// the extension allows us to handle filenames with multiple periods
more cleanly.)
theName += theExtension;
if (App.platform == "mac") {
// Macintosh filenames are limited to 31 characters (including the
extension)
// which is easy to overflow by accident, and produces weird errors
if we
// try to use 'em. The exporter will typically append an extension
to the
// end, which may be up to 5 characters long (well, it actually
could be longer
// but rarely is). So we will constrain the base filename here to 26
characters
// ( == 31 - 5) so that this problem is minimized.
if (theName.length > 26) {
theName = theName.substr(0, 26);
}
}
var exportPath = Files.makePathFromDirAndFile(theDir, theName);
theDoc.exportTo(exportPath, curExportFormatOptions);
}
// ----------------------------------------------------------
function DoExport(theDoc, sourceDocumentPath, batchSettings)
{
if (batchSettings && (batchSettings.exportOptions != null)) {
var curExportFormatOptions;
if (batchSettings.exportOptions.useFormatOptionsFromE achFile) {
curExportFormatOptions = theDoc.exportFormatOptions;
} else {
curExportFormatOptions =
Document.findExportFormatOptionsByName(batchSettin gs.exportOptions.exportFormatOptions.name);
if (curExportFormatOptions == null)
curExportFormatOptions =
batchSettings.exportOptions.exportFormatOptions;
}
// Copy the scaling/cropping info back over, since we may have
// gotten that info from the doc or the named settings,
// and want to override it here.
if (batchSettings.exportOptions.exportFormatOptions != null) {
curExportFormatOptions.applyScale =
batchSettings.exportOptions.exportFormatOptions.ap plyScale;
curExportFormatOptions.useScale =
batchSettings.exportOptions.exportFormatOptions.us eScale;
curExportFormatOptions.percentScale =
batchSettings.exportOptions.exportFormatOptions.pe rcentScale;
curExportFormatOptions.xSize =
batchSettings.exportOptions.exportFormatOptions.xS ize;
curExportFormatOptions.ySize =
batchSettings.exportOptions.exportFormatOptions.yS ize;
curExportFormatOptions.cropTop =
batchSettings.exportOptions.exportFormatOptions.cr opTop;
curExportFormatOptions.cropLeft =
batchSettings.exportOptions.exportFormatOptions.cr opLeft;
curExportFormatOptions.cropBottom =
batchSettings.exportOptions.exportFormatOptions.cr opBottom;
curExportFormatOptions.cropRight =
batchSettings.exportOptions.exportFormatOptions.cr opRight;
curExportFormatOptions.crop =
batchSettings.exportOptions.exportFormatOptions.cr op;
}
// Always disable cropping.
curExportFormatOptions.crop = false;
// If you want to actually modify the document, jam the settings
back in here, like so:
// theDoc.exportFormatOptions = curExportFormatOptions;
// We don't usually want to do this; instead, we pass the export
settings
// as the (optional) second argument to exportTo(), which will leave
the document
// unaffected.
var theDir = Files.getDirectory(sourceDocumentPath);
if (!batchSettings.overwriteExstFiles) {
theDir = batchSettings.outputDir;
}
var theName = Files.getFilename(sourceDocumentPath,
true).toString(); // strip extension, if any, and ensure string-ness
var theExtension = Files.getExtension(sourceDocumentPath).toString();
if (batchSettings.batchRenameParms) {
if (batchSettings.batchRenameParms.filenamePrefix != null)
theName = batchSettings.batchRenameParms.filenamePrefix + theName;
if (batchSettings.batchRenameParms.filenameSuffix != null)
theName = theName + batchSettings.batchRenameParms.filenameSuffix;
}
// re-add the original extension, if any. (Note that exportTo() will
replace this
// extension with the correct one for the export format, if
necessary, but re-adding
// the extension allows us to handle filenames with multiple periods
more cleanly.)
theName += theExtension;
if (App.platform == "mac") {
// Macintosh filenames are limited to 31 characters (including the
extension)
// which is easy to overflow by accident, and produces weird errors
if we
// try to use 'em. The exporter will typically append an extension
to the
// end, which may be up to 5 characters long (well, it actually
could be longer
// but rarely is). So we will constrain the base filename here to
26 characters
// ( == 31 - 5) so that this problem is minimized.
if (theName.length > 26) {
theName = theName.substr(0, 26);
}
}
var exportPath = Files.makePathFromDirAndFile(theDir, theName);
theDoc.exportTo(exportPath, curExportFormatOptions);
}
}
// ----------------------------------------------------------
Coen Naninck Guest
-
Coen Naninck #4
Re: Back to Batch -- Requires Active Document? ** The Code Part 2**
function DoRename(theDoc, sourceDocumentPath, batchSettings)
{
// do not do anything if there is no prefix or suffix for renaming
if ((batchSettings.batchRenameParms.filenamePrefix != null) ||
(batchSettings.batchRenameParms.filenameSuffix != null)) {
var origDir = Files.getDirectory(sourceDocumentPath);
theDir = batchSettings.outputDir;
if (theDir == null)
theDir = origDir;
// only rename if original files are overwritten
// or if custom output destination is the original location
if ((batchSettings.overwriteExstFiles) || (theDir == origDir)) {
var origName = Files.getFilename(sourceDocumentPath,
true).toString(); // strip extension, if any, and ensure string-ness
var theName = Files.getFilename(sourceDocumentPath,
true).toString(); // strip extension, if any, and ensure string-ness
var theExtension = Files.getExtension(sourceDocumentPath).toString();
if (batchSettings.batchRenameParms.filenamePrefix != null)
theName = batchSettings.batchRenameParms.filenamePrefix + theName;
if (batchSettings.batchRenameParms.filenameSuffix != null)
theName = theName + batchSettings.batchRenameParms.filenameSuffix;
// re-add the original extension, if any.
origName += theExtension;
theName += theExtension;
var savePath = Files.makePathFromDirAndFile(theDir, theName);
var origPath = Files.makePathFromDirAndFile(origDir, origName);
if (Files.deleteFileIfExisting(savePath)) {
theDoc.save(false);
Files.copy(origPath, savePath);
} else {
// existing file could not be deleted for some reason
}
}
}
}
// ----------------------------------------------------------
function DoScale(theDoc, batchSettings)
{
if (batchSettings && (batchSettings.batchScaleParms != null)) {
if (batchSettings.batchScaleParms.crop) {
var cropRect;
cropRect.left = batchSettings.batchScaleParms.cropLeft;
cropRect.top = batchSettings.batchScaleParms.cropTop;
cropRect.right = batchSettings.batchScaleParms.cropRight;
cropRect.bottom = batchSettings.batchScaleParms.cropBottom;
theDoc.setDocumentCanvasSize(cropRect);
} else {
if (batchSettings.batchScaleParms.applyScale) {
var oldDocRect = {
left:theDoc.left,
top:theDoc.top,
right:theDoc.left+theDoc.width,
bottom:theDoc.top+theDoc.height,
};
var newDocRect = {
left:0,
top:0,
right:0,
bottom:0,
};
if (batchSettings.batchScaleParms.useScale) { // use percentage
newDocRect.right = batchSettings.batchScaleParms.percentScale *
0.01 *(oldDocRect.right - oldDocRect.left);
newDocRect.bottom = batchSettings.batchScaleParms.percentScale *
0.01 *(oldDocRect.bottom - oldDocRect.top);
} else {
if (batchSettings.batchScaleParms.xSize < 0) {
// scaling to fit
var xPct = - (batchSettings.batchScaleParms.xSize /
(oldDocRect.right - oldDocRect.left));
var yPct = - (batchSettings.batchScaleParms.ySize /
(oldDocRect.bottom - oldDocRect.top));
var scalePct = xPct;
if (xPct <= yPct) {
scalePct = xPct;
} else {
scalePct = yPct;
}
newDocRect.right = scalePct * (oldDocRect.right - oldDocRect.left);
newDocRect.bottom = scalePct * (oldDocRect.bottom - oldDocRect.top);
} else if ((batchSettings.batchScaleParms.xSize == 0) ||
(batchSettings.batchScaleParms.ySize == 0)) {
var scalePct = 1.0;
if (batchSettings.batchScaleParms.xSize ==
batchSettings.batchScaleParms.ySize) {
// this is illegal, but let it go
scalePct = 1.0;
}
else if (batchSettings.batchScaleParms.xSize == 0) {
// xScale is zero, use yScale
scalePct = batchSettings.batchScaleParms.ySize /
(oldDocRect.bottom - oldDocRect.top);
}
else {
// yScale is zero, use xScale
scalePct = batchSettings.batchScaleParms.xSize /
(oldDocRect.right - oldDocRect.left);
}
// make sure scalePct is positive
if (scalePct < 0) {
scalePct = scalePct * -1.0;
}
newDocRect.right = scalePct * (oldDocRect.right - oldDocRect.left);
newDocRect.bottom = scalePct * (oldDocRect.bottom - oldDocRect.top);
} else {
// scaling to size
newDocRect.right = batchSettings.batchScaleParms.xSize;
newDocRect.bottom = batchSettings.batchScaleParms.ySize;
}
}
var newDocResolution = {
pixelsPerUnit:theDoc.resolution,
units:theDoc.resolutionUnits,
};
theDoc.setDocumentImageSize(newDocRect, newDocResolution);
}
}
}
}
// ----------------------------------------------------------
function DoFindAndReplace(theDoc, sourceDocumentPath, batchSettings)
{
if (batchSettings && (batchSettings.findAndReplaceParms != null)) {
var theFinder = theDoc.makeFind(batchSettings.findAndReplaceParms) ;
var replacedAnything = theFinder.replaceAll();
if (theDoc.filePathForSave == null) {
theDoc.filePathForSave =
Document.makeGoodNativeFilePath(sourceDocumentPath );
if (theDoc.filePathForSave == null) {
// This should never happen, but check, just in case.
alert(Errors.EInternalError);
return false;
}
}
if (false == replacedAnything) {
// Don't save the file ... we didn't do anything.
// But, if we are doing backups, make a copy of the original file
// (now located in the Original Files folder) back in the original
spot.
if (batchSettings.doBackupFiles && backupPath != null &&
sourceDocumentPath != null) {
var errorString = SafeCopyFileTo(backupPath, sourceDocumentPath);
if (errorString != null) {
alert(errorString);
return false;
}
}
}
if (theDoc.filePathForSave == null) {
// This should never happen, but check, just in case.
alert(Errors.EInternalError);
return false;
}
}
}
// ----------------------------------------------------------
function DoFillInCustomDestinationForSave(theDoc, sourceDocumentPath,
batchSettings)
{
var theName = Files.getFilename(sourceDocumentPath, true).toString();
// strip extension, if any, and ensure string-ness
var theExtension = Files.getExtension(sourceDocumentPath).toString();
if (batchSettings.batchRenameParms) {
if (batchSettings.batchRenameParms.filenamePrefix != null)
theName = batchSettings.batchRenameParms.filenamePrefix + theName;
if (batchSettings.batchRenameParms.filenameSuffix != null)
theName = theName + batchSettings.batchRenameParms.filenameSuffix;
}
// re-add the original extension, if any.
theName += theExtension;
theDoc.filePathForSave =
Files.makePathFromDirAndFile(batchSettings.outputD ir, theName);
}
// ----------------------------------------------------------
function ProcessOneDocForOneBatch(theDoc, sourceDocumentPath,
batchOperation, batchSettings, donelast)
{
var backupPath = null;
// chop the batchOperation string at the leftmost : character
// if that == "operation:" then process it
// else if that == "commandfile:" then run the script specified
// note that the "operation:" and "commandfile:" prefixes, as
// well as the operation names, must not be changed in this template
var opString = "operation:";
var commandString = "commandfile:";
if (batchOperation.substring(0, opString.length) == opString) {
var rightString = batchOperation.substring(opString.length,
batchOperation.length);
if (rightString == "rename") {
donelast.doRename = true;
} else if (rightString == "export") {
donelast.doExport = true;
} else if (rightString == "scale") {
DoScale(theDoc, batchSettings);
} else if (rightString == "findreplace") {
DoFindAndReplace(theDoc, sourceDocumentPath, batchSettings);
}
} else if (batchOperation.substring(0, commandString.length) ==
commandString) {
var rightCommandString =
batchOperation.substring(commandString.length, batchOperation.length);
// rightString is the commandfile URL
fw.runScript(rightCommandString);
// It would be nice to return a useful value. Maybe someday.
}
return true;
}
// ----------------------------------------------------------
function UniquePathnameWithSameExtension(pathname)
{
if (Files.exists(pathname) == false) {
return pathname; // already unique
}
var filename = Files.getFilename(pathname).toString(); // make sure
it's a string, not a number
var extension = "";
var curlength = filename.length;
for (var i = 1; i < curlength - 1; i++) {
if (filename.charAt(curlength - i) == ".") {
extension = filename.substr(curlength - i);
filename = filename.substr(0, curlength - i);
break;
}
}
var newpathname = pathname;
var newfilename = "";
for (var j = 1; j < 10000; j++) {
newfilename = filename + "-" + j + extension;
newpathname = Files.setFilename(pathname, newfilename);
if (Files.exists(newpathname) == false)
return newpathname;
}
// We should never get here.
return null;
}
// ----------------------------------------------------------
function GetBackupDirectory(pathname)
{
if (Files.exists(pathname) == false) {
return null;
}
var dir = Files.getDirectory(pathname);
var dirName = App.getPref("OriginalFilesFolderName");
var bkupDir = Files.makePathFromDirAndFile(dir, dirName);
if (Files.exists(bkupDir) == false)
Files.createDirectory(bkupDir);
if (Files.exists(bkupDir) == false) {
return null;
}
if (Files.isDirectory(bkupDir) == false) {
return null;
}
return bkupDir;
}
// ----------------------------------------------------------
function GetBackupFile(pathname, doIncrementalBackup)
{
var bkupDir = GetBackupDirectory(pathname);
if (bkupDir == null)
return null;
var filename = Files.getFilename(pathname);
var backupFile = Files.makePathFromDirAndFile(bkupDir, filename);
if (doIncrementalBackup)
backupFile = UniquePathnameWithSameExtension(backupFile);
// If your on windows then call checkForPathLength
if (App.platform != "mac") {
backupFile = checkForPathLength(backupFile);
}
return backupFile;
}
// ----------------------------------------------------------
function SafeCopyFileTo(sourcePath, destPath)
{
if (Files.deleteFileIfExisting(destPath) == false)
return Files.getLastErrorString();
if (Files.copy(sourcePath, destPath) == false)
return Files.getLastErrorString();
return null;
}
// ----------------------------------------------------------
function SafeMoveFileTo(sourcePath, destPath)
{
if (Files.deleteFileIfExisting(destPath) == false)
return Files.getLastErrorString();
// Note: if destPath exists, the two files are swapped; if destPath
// does not exist, sourcePath is moved to destPath. Either way,
// both source and dest must point to the same volume, or the call
// will fail.
if (Files.swap(sourcePath, destPath) == false)
return Files.getLastErrorString();
return null;
}
// ----------------------------------------------------------
function checkForPathLength(backupFile)
{
backupFile = backupFile .toString();
if (backupFile.length > 256){
alert("This file path is too long:" + backupFile + ". Windows
requires the full path be less than 256 characters")
backupFile = null;
}
return backupFile;
}
Coen Naninck Guest
-
Coen Naninck #5
Re: Back to Batch -- Requires Active Document? ** The Code Part 2**
Errr,
I was expecting a little bit less code. This can take some time...
Have you tried adjusting the MyPictures Folder yet?
Believe me, I always try to help anyone even it it seems impossible, but
this code is too long - it will take weeks to dig.
I would like you to read this Technote and tell me if that matches your
problem:
Fireworks Technote 16507:
[url]http://www.macromedia.com/support/fireworks/ts/documents/optimize_tosize.htm[/url]
Get back to me
Coen Naninck wrote:
--> function DoRename(theDoc, sourceDocumentPath, batchSettings)
> {
> // do not do anything if there is no prefix or suffix for renaming
> if ((batchSettings.batchRenameParms.filenamePrefix != null) ||
> (batchSettings.batchRenameParms.filenameSuffix != null)) {
>
> var origDir = Files.getDirectory(sourceDocumentPath);
> theDir = batchSettings.outputDir;
> if (theDir == null)
> theDir = origDir;
>
> // only rename if original files are overwritten
> // or if custom output destination is the original location
> if ((batchSettings.overwriteExstFiles) || (theDir == origDir)) {
>
> var origName = Files.getFilename(sourceDocumentPath,
> true).toString(); // strip extension, if any, and ensure string-ness
> var theName = Files.getFilename(sourceDocumentPath,
> true).toString(); // strip extension, if any, and ensure string-ness
> var theExtension = Files.getExtension(sourceDocumentPath).toString();
> if (batchSettings.batchRenameParms.filenamePrefix != null)
> theName = batchSettings.batchRenameParms.filenamePrefix + theName;
> if (batchSettings.batchRenameParms.filenameSuffix != null)
> theName = theName + batchSettings.batchRenameParms.filenameSuffix;
> // re-add the original extension, if any.
> origName += theExtension;
> theName += theExtension;
>
> var savePath = Files.makePathFromDirAndFile(theDir, theName);
> var origPath = Files.makePathFromDirAndFile(origDir, origName);
>
> if (Files.deleteFileIfExisting(savePath)) {
> theDoc.save(false);
> Files.copy(origPath, savePath);
> } else {
> // existing file could not be deleted for some reason
> }
> }
> }
> }
>
> // ----------------------------------------------------------
>
> function DoScale(theDoc, batchSettings)
> {
> if (batchSettings && (batchSettings.batchScaleParms != null)) {
> if (batchSettings.batchScaleParms.crop) {
> var cropRect;
> cropRect.left = batchSettings.batchScaleParms.cropLeft;
> cropRect.top = batchSettings.batchScaleParms.cropTop;
> cropRect.right = batchSettings.batchScaleParms.cropRight;
> cropRect.bottom = batchSettings.batchScaleParms.cropBottom;
> theDoc.setDocumentCanvasSize(cropRect);
> } else {
> if (batchSettings.batchScaleParms.applyScale) {
> var oldDocRect = {
> left:theDoc.left,
> top:theDoc.top,
> right:theDoc.left+theDoc.width,
> bottom:theDoc.top+theDoc.height,
> };
>
> var newDocRect = {
> left:0,
> top:0,
> right:0,
> bottom:0,
> };
>
> if (batchSettings.batchScaleParms.useScale) { // use percentage
> newDocRect.right = batchSettings.batchScaleParms.percentScale *
> 0.01 *(oldDocRect.right - oldDocRect.left);
> newDocRect.bottom = batchSettings.batchScaleParms.percentScale *
> 0.01 *(oldDocRect.bottom - oldDocRect.top);
> } else {
> if (batchSettings.batchScaleParms.xSize < 0) {
> // scaling to fit
> var xPct = - (batchSettings.batchScaleParms.xSize /
> (oldDocRect.right - oldDocRect.left));
> var yPct = - (batchSettings.batchScaleParms.ySize /
> (oldDocRect.bottom - oldDocRect.top));
> var scalePct = xPct;
> if (xPct <= yPct) {
> scalePct = xPct;
> } else {
> scalePct = yPct;
> }
> newDocRect.right = scalePct * (oldDocRect.right - oldDocRect.left);
> newDocRect.bottom = scalePct * (oldDocRect.bottom - oldDocRect.top);
> } else if ((batchSettings.batchScaleParms.xSize == 0) ||
> (batchSettings.batchScaleParms.ySize == 0)) {
> var scalePct = 1.0;
> if (batchSettings.batchScaleParms.xSize ==
> batchSettings.batchScaleParms.ySize) {
> // this is illegal, but let it go
> scalePct = 1.0;
> }
> else if (batchSettings.batchScaleParms.xSize == 0) {
> // xScale is zero, use yScale
> scalePct = batchSettings.batchScaleParms.ySize /
> (oldDocRect.bottom - oldDocRect.top);
> }
> else {
> // yScale is zero, use xScale
> scalePct = batchSettings.batchScaleParms.xSize /
> (oldDocRect.right - oldDocRect.left);
> }
>
> // make sure scalePct is positive
> if (scalePct < 0) {
> scalePct = scalePct * -1.0;
> }
>
> newDocRect.right = scalePct * (oldDocRect.right - oldDocRect.left);
> newDocRect.bottom = scalePct * (oldDocRect.bottom - oldDocRect.top);
> } else {
> // scaling to size
> newDocRect.right = batchSettings.batchScaleParms.xSize;
> newDocRect.bottom = batchSettings.batchScaleParms.ySize;
> }
> }
>
> var newDocResolution = {
> pixelsPerUnit:theDoc.resolution,
> units:theDoc.resolutionUnits,
> };
>
> theDoc.setDocumentImageSize(newDocRect, newDocResolution);
> }
> }
> }
> }
>
> // ----------------------------------------------------------
>
> function DoFindAndReplace(theDoc, sourceDocumentPath, batchSettings)
> {
> if (batchSettings && (batchSettings.findAndReplaceParms != null)) {
> var theFinder = theDoc.makeFind(batchSettings.findAndReplaceParms) ;
> var replacedAnything = theFinder.replaceAll();
> if (theDoc.filePathForSave == null) {
> theDoc.filePathForSave =
> Document.makeGoodNativeFilePath(sourceDocumentPath );
> if (theDoc.filePathForSave == null) {
> // This should never happen, but check, just in case.
> alert(Errors.EInternalError);
> return false;
> }
> }
>
> if (false == replacedAnything) {
> // Don't save the file ... we didn't do anything.
> // But, if we are doing backups, make a copy of the original file
> // (now located in the Original Files folder) back in the original
> spot.
> if (batchSettings.doBackupFiles && backupPath != null &&
> sourceDocumentPath != null) {
> var errorString = SafeCopyFileTo(backupPath, sourceDocumentPath);
> if (errorString != null) {
> alert(errorString);
> return false;
> }
> }
> }
> if (theDoc.filePathForSave == null) {
> // This should never happen, but check, just in case.
> alert(Errors.EInternalError);
> return false;
> }
> }
>
> }
>
> // ----------------------------------------------------------
>
> function DoFillInCustomDestinationForSave(theDoc, sourceDocumentPath,
> batchSettings)
> {
> var theName = Files.getFilename(sourceDocumentPath, true).toString();
> // strip extension, if any, and ensure string-ness
>
> var theExtension = Files.getExtension(sourceDocumentPath).toString();
>
> if (batchSettings.batchRenameParms) {
> if (batchSettings.batchRenameParms.filenamePrefix != null)
> theName = batchSettings.batchRenameParms.filenamePrefix + theName;
> if (batchSettings.batchRenameParms.filenameSuffix != null)
> theName = theName + batchSettings.batchRenameParms.filenameSuffix;
> }
>
> // re-add the original extension, if any.
> theName += theExtension;
>
> theDoc.filePathForSave =
> Files.makePathFromDirAndFile(batchSettings.outputD ir, theName);
> }
>
> // ----------------------------------------------------------
>
> function ProcessOneDocForOneBatch(theDoc, sourceDocumentPath,
> batchOperation, batchSettings, donelast)
> {
> var backupPath = null;
>
> // chop the batchOperation string at the leftmost : character
>
> // if that == "operation:" then process it
> // else if that == "commandfile:" then run the script specified
> // note that the "operation:" and "commandfile:" prefixes, as
> // well as the operation names, must not be changed in this template
> var opString = "operation:";
> var commandString = "commandfile:";
>
> if (batchOperation.substring(0, opString.length) == opString) {
>
> var rightString = batchOperation.substring(opString.length,
> batchOperation.length);
>
> if (rightString == "rename") {
>
> donelast.doRename = true;
>
> } else if (rightString == "export") {
>
> donelast.doExport = true;
>
> } else if (rightString == "scale") {
>
> DoScale(theDoc, batchSettings);
>
> } else if (rightString == "findreplace") {
>
> DoFindAndReplace(theDoc, sourceDocumentPath, batchSettings);
>
> }
>
> } else if (batchOperation.substring(0, commandString.length) ==
> commandString) {
>
> var rightCommandString =
> batchOperation.substring(commandString.length, batchOperation.length);
>
> // rightString is the commandfile URL
> fw.runScript(rightCommandString);
>
> // It would be nice to return a useful value. Maybe someday.
>
> }
>
>
> return true;
> }
>
> // ----------------------------------------------------------
>
> function UniquePathnameWithSameExtension(pathname)
> {
> if (Files.exists(pathname) == false) {
> return pathname; // already unique
> }
>
> var filename = Files.getFilename(pathname).toString(); // make sure
> it's a string, not a number
> var extension = "";
> var curlength = filename.length;
> for (var i = 1; i < curlength - 1; i++) {
> if (filename.charAt(curlength - i) == ".") {
> extension = filename.substr(curlength - i);
> filename = filename.substr(0, curlength - i);
> break;
> }
> }
>
> var newpathname = pathname;
> var newfilename = "";
> for (var j = 1; j < 10000; j++) {
> newfilename = filename + "-" + j + extension;
> newpathname = Files.setFilename(pathname, newfilename);
> if (Files.exists(newpathname) == false)
> return newpathname;
> }
>
> // We should never get here.
> return null;
> }
>
> // ----------------------------------------------------------
>
> function GetBackupDirectory(pathname)
> {
> if (Files.exists(pathname) == false) {
> return null;
> }
>
> var dir = Files.getDirectory(pathname);
> var dirName = App.getPref("OriginalFilesFolderName");
> var bkupDir = Files.makePathFromDirAndFile(dir, dirName);
>
> if (Files.exists(bkupDir) == false)
> Files.createDirectory(bkupDir);
>
> if (Files.exists(bkupDir) == false) {
> return null;
> }
>
> if (Files.isDirectory(bkupDir) == false) {
> return null;
> }
>
> return bkupDir;
> }
>
> // ----------------------------------------------------------
>
> function GetBackupFile(pathname, doIncrementalBackup)
> {
> var bkupDir = GetBackupDirectory(pathname);
> if (bkupDir == null)
> return null;
> var filename = Files.getFilename(pathname);
> var backupFile = Files.makePathFromDirAndFile(bkupDir, filename);
>
> if (doIncrementalBackup)
> backupFile = UniquePathnameWithSameExtension(backupFile);
>
> // If your on windows then call checkForPathLength
> if (App.platform != "mac") {
> backupFile = checkForPathLength(backupFile);
> }
>
> return backupFile;
> }
>
> // ----------------------------------------------------------
>
> function SafeCopyFileTo(sourcePath, destPath)
> {
> if (Files.deleteFileIfExisting(destPath) == false)
> return Files.getLastErrorString();
>
> if (Files.copy(sourcePath, destPath) == false)
> return Files.getLastErrorString();
>
> return null;
> }
>
> // ----------------------------------------------------------
>
> function SafeMoveFileTo(sourcePath, destPath)
> {
> if (Files.deleteFileIfExisting(destPath) == false)
> return Files.getLastErrorString();
>
> // Note: if destPath exists, the two files are swapped; if destPath
> // does not exist, sourcePath is moved to destPath. Either way,
> // both source and dest must point to the same volume, or the call
> // will fail.
> if (Files.swap(sourcePath, destPath) == false)
> return Files.getLastErrorString();
>
> return null;
> }
>
> // ----------------------------------------------------------
>
> function checkForPathLength(backupFile)
> {
> backupFile = backupFile .toString();
> if (backupFile.length > 256){
> alert("This file path is too long:" + backupFile + ". Windows
> requires the full path be less than 256 characters")
> backupFile = null;
> }
> return backupFile;
> }
>
>
Kind regards,
Coen Naninck
_______________________________
Please, don't E-mail me about Fireworks questions. Post them on the Forum.
If you are sending me a file on my own request for help purposes,
then please include the thread subject header.
E-mail : ccnk at home.nl
================================
Enhance Fireworks with these Productivity Resources
DevNet
[url]http://www.macromedia.com/devnet/mx/fireworks/[/url]
Styles
[url]http://www.macromedia.com/devnet/mx/fireworks/articles/style_samples.html[/url]
[url]http://wetworks.nl/freestyler[/url]
[url]http://richiebee.ca/fireworks.htm[/url]
Flash Panels
[url]http://www.macromedia.com/devnet/mx/studio/articles/fw_command_in_flash.html[/url]
Coen Naninck Guest
-
GLMoore #6
Re: Back to Batch -- Requires Active Document? ** The Code Part 2 **
Just had time for a quick peek ... I'm not on Mac, but the error msg doesn't
seem to be the same as the one I'm getting on WinXP. I will look it over
more closely first thing next week.
Yes, the amount of code is enormous ... that really baffled me ... all the
script does is select size to a specific area (300 X 300 px) and save in a
selected folder ... I'm not competent in java script tho' so I have no idea
what would be considered excessive.
Thanks for your help with this.
GLMoore
Coen Naninck <ccnkHAHA@home.nl> wrote in message
news:bjt6vq$2v8$5@forums.macromedia.com...[url]http://www.macromedia.com/support/fireworks/ts/documents/optimize_tosize.htm[/url]> Errr,
>
> I was expecting a little bit less code. This can take some time...
> Have you tried adjusting the MyPictures Folder yet?
>
> Believe me, I always try to help anyone even it it seems impossible, but
> this code is too long - it will take weeks to dig.
>
> I would like you to read this Technote and tell me if that matches your
> problem:
>
> Fireworks Technote 16507:
>Files.getExtension(sourceDocumentPath).toString();>
> Get back to me
>
>
> Coen Naninck wrote:
>> > function DoRename(theDoc, sourceDocumentPath, batchSettings)
> > {
> > // do not do anything if there is no prefix or suffix for renaming
> > if ((batchSettings.batchRenameParms.filenamePrefix != null) ||
> > (batchSettings.batchRenameParms.filenameSuffix != null)) {
> >
> > var origDir = Files.getDirectory(sourceDocumentPath);
> > theDir = batchSettings.outputDir;
> > if (theDir == null)
> > theDir = origDir;
> >
> > // only rename if original files are overwritten
> > // or if custom output destination is the original location
> > if ((batchSettings.overwriteExstFiles) || (theDir == origDir)) {
> >
> > var origName = Files.getFilename(sourceDocumentPath,
> > true).toString(); // strip extension, if any, and ensure string-ness
> > var theName = Files.getFilename(sourceDocumentPath,
> > true).toString(); // strip extension, if any, and ensure string-ness
> > var theExtension =oldDocRect.left);> > if (batchSettings.batchRenameParms.filenamePrefix != null)
> > theName = batchSettings.batchRenameParms.filenamePrefix + theName;
> > if (batchSettings.batchRenameParms.filenameSuffix != null)
> > theName = theName + batchSettings.batchRenameParms.filenameSuffix;
> > // re-add the original extension, if any.
> > origName += theExtension;
> > theName += theExtension;
> >
> > var savePath = Files.makePathFromDirAndFile(theDir, theName);
> > var origPath = Files.makePathFromDirAndFile(origDir, origName);
> >
> > if (Files.deleteFileIfExisting(savePath)) {
> > theDoc.save(false);
> > Files.copy(origPath, savePath);
> > } else {
> > // existing file could not be deleted for some reason
> > }
> > }
> > }
> > }
> >
> > // ----------------------------------------------------------
> >
> > function DoScale(theDoc, batchSettings)
> > {
> > if (batchSettings && (batchSettings.batchScaleParms != null)) {
> > if (batchSettings.batchScaleParms.crop) {
> > var cropRect;
> > cropRect.left = batchSettings.batchScaleParms.cropLeft;
> > cropRect.top = batchSettings.batchScaleParms.cropTop;
> > cropRect.right = batchSettings.batchScaleParms.cropRight;
> > cropRect.bottom = batchSettings.batchScaleParms.cropBottom;
> > theDoc.setDocumentCanvasSize(cropRect);
> > } else {
> > if (batchSettings.batchScaleParms.applyScale) {
> > var oldDocRect = {
> > left:theDoc.left,
> > top:theDoc.top,
> > right:theDoc.left+theDoc.width,
> > bottom:theDoc.top+theDoc.height,
> > };
> >
> > var newDocRect = {
> > left:0,
> > top:0,
> > right:0,
> > bottom:0,
> > };
> >
> > if (batchSettings.batchScaleParms.useScale) { // use percentage
> > newDocRect.right = batchSettings.batchScaleParms.percentScale *
> > 0.01 *(oldDocRect.right - oldDocRect.left);
> > newDocRect.bottom = batchSettings.batchScaleParms.percentScale *
> > 0.01 *(oldDocRect.bottom - oldDocRect.top);
> > } else {
> > if (batchSettings.batchScaleParms.xSize < 0) {
> > // scaling to fit
> > var xPct = - (batchSettings.batchScaleParms.xSize /
> > (oldDocRect.right - oldDocRect.left));
> > var yPct = - (batchSettings.batchScaleParms.ySize /
> > (oldDocRect.bottom - oldDocRect.top));
> > var scalePct = xPct;
> > if (xPct <= yPct) {
> > scalePct = xPct;
> > } else {
> > scalePct = yPct;
> > }
> > newDocRect.right = scalePct * (oldDocRect.right -oldDocRect.top);> > newDocRect.bottom = scalePct * (oldDocRect.bottom -oldDocRect.left);> > } else if ((batchSettings.batchScaleParms.xSize == 0) ||
> > (batchSettings.batchScaleParms.ySize == 0)) {
> > var scalePct = 1.0;
> > if (batchSettings.batchScaleParms.xSize ==
> > batchSettings.batchScaleParms.ySize) {
> > // this is illegal, but let it go
> > scalePct = 1.0;
> > }
> > else if (batchSettings.batchScaleParms.xSize == 0) {
> > // xScale is zero, use yScale
> > scalePct = batchSettings.batchScaleParms.ySize /
> > (oldDocRect.bottom - oldDocRect.top);
> > }
> > else {
> > // yScale is zero, use xScale
> > scalePct = batchSettings.batchScaleParms.xSize /
> > (oldDocRect.right - oldDocRect.left);
> > }
> >
> > // make sure scalePct is positive
> > if (scalePct < 0) {
> > scalePct = scalePct * -1.0;
> > }
> >
> > newDocRect.right = scalePct * (oldDocRect.right -oldDocRect.top);> > newDocRect.bottom = scalePct * (oldDocRect.bottom -[url]http://www.macromedia.com/devnet/mx/studio/articles/fw_command_in_flash.html[/url]>> > } else {
> > // scaling to size
> > newDocRect.right = batchSettings.batchScaleParms.xSize;
> > newDocRect.bottom = batchSettings.batchScaleParms.ySize;
> > }
> > }
> >
> > var newDocResolution = {
> > pixelsPerUnit:theDoc.resolution,
> > units:theDoc.resolutionUnits,
> > };
> >
> > theDoc.setDocumentImageSize(newDocRect, newDocResolution);
> > }
> > }
> > }
> > }
> >
> > // ----------------------------------------------------------
> >
> > function DoFindAndReplace(theDoc, sourceDocumentPath, batchSettings)
> > {
> > if (batchSettings && (batchSettings.findAndReplaceParms != null)) {
> > var theFinder = theDoc.makeFind(batchSettings.findAndReplaceParms) ;
> > var replacedAnything = theFinder.replaceAll();
> > if (theDoc.filePathForSave == null) {
> > theDoc.filePathForSave =
> > Document.makeGoodNativeFilePath(sourceDocumentPath );
> > if (theDoc.filePathForSave == null) {
> > // This should never happen, but check, just in case.
> > alert(Errors.EInternalError);
> > return false;
> > }
> > }
> >
> > if (false == replacedAnything) {
> > // Don't save the file ... we didn't do anything.
> > // But, if we are doing backups, make a copy of the original file
> > // (now located in the Original Files folder) back in the original
> > spot.
> > if (batchSettings.doBackupFiles && backupPath != null &&
> > sourceDocumentPath != null) {
> > var errorString = SafeCopyFileTo(backupPath, sourceDocumentPath);
> > if (errorString != null) {
> > alert(errorString);
> > return false;
> > }
> > }
> > }
> > if (theDoc.filePathForSave == null) {
> > // This should never happen, but check, just in case.
> > alert(Errors.EInternalError);
> > return false;
> > }
> > }
> >
> > }
> >
> > // ----------------------------------------------------------
> >
> > function DoFillInCustomDestinationForSave(theDoc, sourceDocumentPath,
> > batchSettings)
> > {
> > var theName = Files.getFilename(sourceDocumentPath, true).toString();
> > // strip extension, if any, and ensure string-ness
> >
> > var theExtension = Files.getExtension(sourceDocumentPath).toString();
> >
> > if (batchSettings.batchRenameParms) {
> > if (batchSettings.batchRenameParms.filenamePrefix != null)
> > theName = batchSettings.batchRenameParms.filenamePrefix + theName;
> > if (batchSettings.batchRenameParms.filenameSuffix != null)
> > theName = theName + batchSettings.batchRenameParms.filenameSuffix;
> > }
> >
> > // re-add the original extension, if any.
> > theName += theExtension;
> >
> > theDoc.filePathForSave =
> > Files.makePathFromDirAndFile(batchSettings.outputD ir, theName);
> > }
> >
> > // ----------------------------------------------------------
> >
> > function ProcessOneDocForOneBatch(theDoc, sourceDocumentPath,
> > batchOperation, batchSettings, donelast)
> > {
> > var backupPath = null;
> >
> > // chop the batchOperation string at the leftmost : character
> >
> > // if that == "operation:" then process it
> > // else if that == "commandfile:" then run the script specified
> > // note that the "operation:" and "commandfile:" prefixes, as
> > // well as the operation names, must not be changed in this template
> > var opString = "operation:";
> > var commandString = "commandfile:";
> >
> > if (batchOperation.substring(0, opString.length) == opString) {
> >
> > var rightString = batchOperation.substring(opString.length,
> > batchOperation.length);
> >
> > if (rightString == "rename") {
> >
> > donelast.doRename = true;
> >
> > } else if (rightString == "export") {
> >
> > donelast.doExport = true;
> >
> > } else if (rightString == "scale") {
> >
> > DoScale(theDoc, batchSettings);
> >
> > } else if (rightString == "findreplace") {
> >
> > DoFindAndReplace(theDoc, sourceDocumentPath, batchSettings);
> >
> > }
> >
> > } else if (batchOperation.substring(0, commandString.length) ==
> > commandString) {
> >
> > var rightCommandString =
> > batchOperation.substring(commandString.length, batchOperation.length);
> >
> > // rightString is the commandfile URL
> > fw.runScript(rightCommandString);
> >
> > // It would be nice to return a useful value. Maybe someday.
> >
> > }
> >
> >
> > return true;
> > }
> >
> > // ----------------------------------------------------------
> >
> > function UniquePathnameWithSameExtension(pathname)
> > {
> > if (Files.exists(pathname) == false) {
> > return pathname; // already unique
> > }
> >
> > var filename = Files.getFilename(pathname).toString(); // make sure
> > it's a string, not a number
> > var extension = "";
> > var curlength = filename.length;
> > for (var i = 1; i < curlength - 1; i++) {
> > if (filename.charAt(curlength - i) == ".") {
> > extension = filename.substr(curlength - i);
> > filename = filename.substr(0, curlength - i);
> > break;
> > }
> > }
> >
> > var newpathname = pathname;
> > var newfilename = "";
> > for (var j = 1; j < 10000; j++) {
> > newfilename = filename + "-" + j + extension;
> > newpathname = Files.setFilename(pathname, newfilename);
> > if (Files.exists(newpathname) == false)
> > return newpathname;
> > }
> >
> > // We should never get here.
> > return null;
> > }
> >
> > // ----------------------------------------------------------
> >
> > function GetBackupDirectory(pathname)
> > {
> > if (Files.exists(pathname) == false) {
> > return null;
> > }
> >
> > var dir = Files.getDirectory(pathname);
> > var dirName = App.getPref("OriginalFilesFolderName");
> > var bkupDir = Files.makePathFromDirAndFile(dir, dirName);
> >
> > if (Files.exists(bkupDir) == false)
> > Files.createDirectory(bkupDir);
> >
> > if (Files.exists(bkupDir) == false) {
> > return null;
> > }
> >
> > if (Files.isDirectory(bkupDir) == false) {
> > return null;
> > }
> >
> > return bkupDir;
> > }
> >
> > // ----------------------------------------------------------
> >
> > function GetBackupFile(pathname, doIncrementalBackup)
> > {
> > var bkupDir = GetBackupDirectory(pathname);
> > if (bkupDir == null)
> > return null;
> > var filename = Files.getFilename(pathname);
> > var backupFile = Files.makePathFromDirAndFile(bkupDir, filename);
> >
> > if (doIncrementalBackup)
> > backupFile = UniquePathnameWithSameExtension(backupFile);
> >
> > // If your on windows then call checkForPathLength
> > if (App.platform != "mac") {
> > backupFile = checkForPathLength(backupFile);
> > }
> >
> > return backupFile;
> > }
> >
> > // ----------------------------------------------------------
> >
> > function SafeCopyFileTo(sourcePath, destPath)
> > {
> > if (Files.deleteFileIfExisting(destPath) == false)
> > return Files.getLastErrorString();
> >
> > if (Files.copy(sourcePath, destPath) == false)
> > return Files.getLastErrorString();
> >
> > return null;
> > }
> >
> > // ----------------------------------------------------------
> >
> > function SafeMoveFileTo(sourcePath, destPath)
> > {
> > if (Files.deleteFileIfExisting(destPath) == false)
> > return Files.getLastErrorString();
> >
> > // Note: if destPath exists, the two files are swapped; if destPath
> > // does not exist, sourcePath is moved to destPath. Either way,
> > // both source and dest must point to the same volume, or the call
> > // will fail.
> > if (Files.swap(sourcePath, destPath) == false)
> > return Files.getLastErrorString();
> >
> > return null;
> > }
> >
> > // ----------------------------------------------------------
> >
> > function checkForPathLength(backupFile)
> > {
> > backupFile = backupFile .toString();
> > if (backupFile.length > 256){
> > alert("This file path is too long:" + backupFile + ". Windows
> > requires the full path be less than 256 characters")
> > backupFile = null;
> > }
> > return backupFile;
> > }
> >
> >
> --
>
>
> Kind regards,
>
> Coen Naninck
> _______________________________
>
> Please, don't E-mail me about Fireworks questions. Post them on the Forum.
>
> If you are sending me a file on my own request for help purposes,
> then please include the thread subject header.
>
> E-mail : ccnk at home.nl
>
> ================================
> Enhance Fireworks with these Productivity Resources
>
> DevNet
>
> [url]http://www.macromedia.com/devnet/mx/fireworks/[/url]
>
> Styles
>
> [url]http://www.macromedia.com/devnet/mx/fireworks/articles/style_samples.html[/url]
> [url]http://wetworks.nl/freestyler[/url]
> [url]http://richiebee.ca/fireworks.htm[/url]
>
> Flash Panels
>
>>
GLMoore Guest
-
GLMoore #7
Re: Back to Batch -- Requires Active Document? ** The Code Part 2 **
Well, I've re-read that TechNote and really, that's a different matter:
It is about - vs. - I am experiencing:
--Mac vs. PC
--Optimize to a specific size vs. optimize to fit a specifically-sized area
--Application quits vs. error msg specific to problems w/ script appears
--Can't process JPGs via batch vs. batch works fine w/ JPGs, it's the script
that won't run.
So, somewhere in that jungle of script is, I suppose, the answer. You'll
deserve great respect if you can ferret it out.
The TweakUI for XP fix (to have it open somewhere other than My Pictures) is
certainly a possibility ... but I thought whether or not the user would
return to the same folder on subsequent save or open commands was a function
of the application, not the OS ... I infer this from the fact that various
applications do handle it differently (e.g., PSP will always return to the
last-accessed folder for subsequent save or open operations.)
Thanks for your assistance w/ all this.
GLMoore
Coen Naninck <ccnkHAHA@home.nl> wrote in message
news:bjtesj$g6s$2@forums.macromedia.com...doesn't> Keep me informed if you can.
>
> GLMoore wrote:> > Just had time for a quick peek ... I'm not on Mac, but the error msgover> > seem to be the same as the one I'm getting on WinXP. I will look itthe> > more closely first thing next week.
> >
> > Yes, the amount of code is enormous ... that really baffled me ... alla> > script does is select size to a specific area (300 X 300 px) and save inidea> > selected folder ... I'm not competent in java script tho' so I have no> > what would be considered excessive.
> >
> > Thanks for your help with this.
> >
> > GLMoore
> >
> >
> > Coen Naninck <ccnkHAHA@home.nl> wrote in message
> > news:bjt6vq$2v8$5@forums.macromedia.com...
> >> >>Errr,
> >>
> >>I was expecting a little bit less code. This can take some time...
> >>Have you tried adjusting the MyPictures Folder yet?
> >>
> >>Believe me, I always try to help anyone even it it seems impossible, but[url]http://www.macromedia.com/support/fireworks/ts/documents/optimize_tosize.htm[/url]> >> >>this code is too long - it will take weeks to dig.
> >>
> >>I would like you to read this Technote and tell me if that matches your
> >>problem:
> >>
> >>Fireworks Technote 16507:
> >>
> >>> >> >>Get back to me
> >>
> >>
> >>Coen Naninck wrote:
> >>
GLMoore Guest
-
Coen Naninck #8
Re: Back to Batch -- Requires Active Document? ** The Code Part 2**
| I infer this from the fact that various applications do handle it
differently (e.g., PSP will always return to the last-accessed folder
for subsequent save or open operations.)
They fixed this in Fireworks MX 2004.
I can not help you futher with this one problem other than the TweakUI
fix. Perhaps other can step in here but I would consider reposting the
item since old items get skipped sooner once new ones arrive (at least,
that is how I think it works, it does with me.. :-) )
If you go with the TweakUI fix at least you have that problem solved.
Currently I am working on a new website which details BatchProcessing
and other powertools in more detail. When I get to the topic of
Batchprocessing I will certainly look up this thread (and other) again
to write about the most commonly found issues and try to resolve them.
Just currently I have some many other things in my life. I would really
like to help you with this, but alas.. I can't.
Hope you can work it out.
Coen
GLMoore wrote:
--> Well, I've re-read that TechNote and really, that's a different matter:
>
> It is about - vs. - I am experiencing:
>
> --Mac vs. PC
> --Optimize to a specific size vs. optimize to fit a specifically-sized area
> --Application quits vs. error msg specific to problems w/ script appears
> --Can't process JPGs via batch vs. batch works fine w/ JPGs, it's the script
> that won't run.
>
> So, somewhere in that jungle of script is, I suppose, the answer. You'll
> deserve great respect if you can ferret it out.
>
> The TweakUI for XP fix (to have it open somewhere other than My Pictures) is
> certainly a possibility ... but I thought whether or not the user would
> return to the same folder on subsequent save or open commands was a function
> of the application, not the OS ... I infer this from the fact that various
> applications do handle it differently (e.g., PSP will always return to the
> last-accessed folder for subsequent save or open operations.)
>
> Thanks for your assistance w/ all this.
>
> GLMoore
>
>
> Coen Naninck <ccnkHAHA@home.nl> wrote in message
> news:bjtesj$g6s$2@forums.macromedia.com...
>>>>Keep me informed if you can.
>>
>>GLMoore wrote:
>>>>>Just had time for a quick peek ... I'm not on Mac, but the error msg
> doesn't
>>>>>seem to be the same as the one I'm getting on WinXP. I will look it
> over
>>>>>more closely first thing next week.
>>>
>>>Yes, the amount of code is enormous ... that really baffled me ... all
> the
>>>>>script does is select size to a specific area (300 X 300 px) and save in
> a
>>>>>selected folder ... I'm not competent in java script tho' so I have no
> idea
>>>>>what would be considered excessive.
>>>
>>>Thanks for your help with this.
>>>
>>>GLMoore
>>>
>>>
>>>Coen Naninck <ccnkHAHA@home.nl> wrote in message
>>>news:bjt6vq$2v8$5@forums.macromedia.com...
>>>
>>>
>>>>Errr,
>>>>
>>>>I was expecting a little bit less code. This can take some time...
>>>>Have you tried adjusting the MyPictures Folder yet?
>>>>
>>>>Believe me, I always try to help anyone even it it seems impossible, but
>> [url]http://www.macromedia.com/support/fireworks/ts/documents/optimize_tosize.htm[/url]>>>>this code is too long - it will take weeks to dig.
>>>>
>>>>I would like you to read this Technote and tell me if that matches your
>>>>problem:
>>>>
>>>>Fireworks Technote 16507:
>>>>
>>>
>>>
>>>>>>>>Get back to me
>>>>
>>>>
>>>>Coen Naninck wrote:
>>>>
>
Kind regards,
Coen Naninck
_______________________________
Please, don't E-mail me about Fireworks questions. Post them on the Forum.
If you are sending me a file on my own request for help purposes,
then please include the thread subject header.
E-mail : ccnk at home.nl
================================
Enhance Fireworks with these Productivity Resources
DevNet
[url]http://www.macromedia.com/devnet/mx/fireworks/[/url]
Styles
[url]http://www.macromedia.com/devnet/mx/fireworks/articles/style_samples.html[/url]
[url]http://wetworks.nl/freestyler[/url]
[url]http://richiebee.ca/fireworks.htm[/url]
Flash Panels
[url]http://www.macromedia.com/devnet/mx/studio/articles/fw_command_in_flash.html[/url]
Coen Naninck Guest
-
GLMoore #9
Re: Back to Batch -- Requires Active Document? ** The Code Part 2**
NP, I understand the demands on time. Your help so far has been valuable,
since it is very meaningful to know that one problem is definitely the
result of a bug in FW which has apparently been addressed in the new release
.... and no doubt the failure of the scaling script to perform properly is an
application bug also.
I can work around both these things for the time being.
Thanks for your assistance,
GLMoore
Coen Naninck <ccnkHAHA@home.nl> wrote in message
news:bk58gb$ca8$1@forums.macromedia.com...area> | I infer this from the fact that various applications do handle it
> differently (e.g., PSP will always return to the last-accessed folder
> for subsequent save or open operations.)
>
> They fixed this in Fireworks MX 2004.
>
> I can not help you futher with this one problem other than the TweakUI
> fix. Perhaps other can step in here but I would consider reposting the
> item since old items get skipped sooner once new ones arrive (at least,
> that is how I think it works, it does with me.. :-) )
>
> If you go with the TweakUI fix at least you have that problem solved.
>
> Currently I am working on a new website which details BatchProcessing
> and other powertools in more detail. When I get to the topic of
> Batchprocessing I will certainly look up this thread (and other) again
> to write about the most commonly found issues and try to resolve them.
> Just currently I have some many other things in my life. I would really
> like to help you with this, but alas.. I can't.
>
> Hope you can work it out.
>
> Coen
>
> GLMoore wrote:
>> > Well, I've re-read that TechNote and really, that's a different matter:
> >
> > It is about - vs. - I am experiencing:
> >
> > --Mac vs. PC
> > --Optimize to a specific size vs. optimize to fit a specifically-sizedscript> > --Application quits vs. error msg specific to problems w/ script appears
> > --Can't process JPGs via batch vs. batch works fine w/ JPGs, it's theYou'll> > that won't run.
> >
> > So, somewhere in that jungle of script is, I suppose, the answer.Pictures) is> > deserve great respect if you can ferret it out.
> >
> > The TweakUI for XP fix (to have it open somewhere other than Myfunction> > certainly a possibility ... but I thought whether or not the user would
> > return to the same folder on subsequent save or open commands was avarious> > of the application, not the OS ... I infer this from the fact thatthe> > applications do handle it differently (e.g., PSP will always return toin> > last-accessed folder for subsequent save or open operations.)
> >
> > Thanks for your assistance w/ all this.
> >
> > GLMoore
> >
> >
> > Coen Naninck <ccnkHAHA@home.nl> wrote in message
> > news:bjtesj$g6s$2@forums.macromedia.com...
> >> >> >>Keep me informed if you can.
> >>
> >>GLMoore wrote:
> >>
> >>>Just had time for a quick peek ... I'm not on Mac, but the error msg
> > doesn't
> >> >> >>>seem to be the same as the one I'm getting on WinXP. I will look it
> > over
> >> >> >>>more closely first thing next week.
> >>>
> >>>Yes, the amount of code is enormous ... that really baffled me ... all
> > the
> >> >>>script does is select size to a specific area (300 X 300 px) and savebut> >
> > a
> >> >> >>>selected folder ... I'm not competent in java script tho' so I have no
> > idea
> >> >>>what would be considered excessive.
> >>>
> >>>Thanks for your help with this.
> >>>
> >>>GLMoore
> >>>
> >>>
> >>>Coen Naninck <ccnkHAHA@home.nl> wrote in message
> >>>news:bjt6vq$2v8$5@forums.macromedia.com...
> >>>
> >>>
> >>>>Errr,
> >>>>
> >>>>I was expecting a little bit less code. This can take some time...
> >>>>Have you tried adjusting the MyPictures Folder yet?
> >>>>
> >>>>Believe me, I always try to help anyone even it it seems impossible,your> >
> >> >>>>this code is too long - it will take weeks to dig.
> >>>>
> >>>>I would like you to read this Technote and tell me if that matches[url]http://www.macromedia.com/support/fireworks/ts/documents/optimize_tosize.htm[/url]> >> >>>>problem:
> >>>>
> >>>>Fireworks Technote 16507:
> >>>>
> >>>
> >>>[url]http://www.macromedia.com/devnet/mx/studio/articles/fw_command_in_flash.html[/url]>> >> >> >>>>Get back to me
> >>>>
> >>>>
> >>>>Coen Naninck wrote:
> >>>>
> >>
> >
> --
>
>
> Kind regards,
>
> Coen Naninck
> _______________________________
>
> Please, don't E-mail me about Fireworks questions. Post them on the Forum.
>
> If you are sending me a file on my own request for help purposes,
> then please include the thread subject header.
>
> E-mail : ccnk at home.nl
>
> ================================
> Enhance Fireworks with these Productivity Resources
>
> DevNet
>
> [url]http://www.macromedia.com/devnet/mx/fireworks/[/url]
>
> Styles
>
> [url]http://www.macromedia.com/devnet/mx/fireworks/articles/style_samples.html[/url]
> [url]http://wetworks.nl/freestyler[/url]
> [url]http://richiebee.ca/fireworks.htm[/url]
>
> Flash Panels
>
>>
GLMoore Guest



Reply With Quote

