View Full Version : incremental saveing
wwwwoody 01-29-2007, 08:25 AM READ LAST POST FROM ME ! LAST VERSION OF SCRIPT FREE !
hi all, i have a problem with photoshop script for saving documents. i need script for save document as version of document (like 3ds max). here is my script, but i dont know, how convert string to "file" or how modify file name
function autosave() {
if (app.documents.length == 0 || !app.activeDocument) {
alert("no active document");
return;
} else {
var doc = app.activeDocument;
try {
doc.fullName;
} catch(e) {
alert("this document has no default file name associated with it; use File > Save As");
return;
}
// --------------------------------------------------------------------------------------------------------
var filename = app.activeDocument.fullName.toString();
var number = filename.split("_");
var extension = filename.split(".");
var newfilename = "";
for (i=0; i<(number.length - 1); i++) {
newfilename += number[i];
}
if (parseInt(number[number.length - 1]) < 9) {
newfilename += "_0" + (parseInt(number[number.length - 1]) + 1) + "." + extension[extension.length - 1];
} else {
newfilename += "_" + (parseInt(number[number.length - 1]) + 1) + "." + extension[extension.length - 1];
}
// --------------------------------------------------------------------------------------------------------
doc.saveAs(newfilename);
}
}
autosave();
thx for help :-)
| |
wwwwoody
01-29-2007, 08:37 AM
this is right code - incremental saveing for photoshop CS2/CS3
#target photoshop
app.bringToFront();
function autosave() {
if (app.documents.length == 0 || !app.activeDocument) {
alert("Není otevřen žádný dokument.");
return;
} else {
var doc = app.activeDocument;
try {
doc.fullName;
} catch(e) {
alert("Dokument není ještě uložen. Použij File / Save as... k uložení dokumentu.");
return;
}
// --------------------------------------------------------------------------------------------------------
var filename = app.activeDocument.fullName.toString();
var number = filename.split("_");
var extension = filename.split(".");
var newfilename = "";
for (i=0; i<(number.length - 1); i++) {
newfilename += number[i];
}
if (parseInt(number[number.length - 1]) < 9) {
newfilename += "_0" + (parseInt(number[number.length - 1]) + 1) + "." + extension[extension.length - 1];
} else {
newfilename += "_" + (parseInt(number[number.length - 1]) + 1) + "." + extension[extension.length - 1];
}
// --------------------------------------------------------------------------------------------------------
var newfile = new File(newfilename);
doc.saveAs(newfile);
}
}
autosave();
dannyduke
01-29-2007, 11:01 AM
can that code work for CS too?
wwwwoody
01-29-2007, 11:21 AM
no, it isnt work on ps CS. this script is for CS2/CS3 only, but i try type a script for ps7 and CS too.
berniebernie
01-29-2007, 11:45 AM
just remove app.bringToFront() and it should work with CS
btw use the 'code' or 'php' tags on the forum for the ease of the eyes:
function autosave() {
if (app.documents.length == 0 || !app.activeDocument) {
alert("Není otevřen žádný dokument.");
return;
} else {
var doc = app.activeDocument;
try {
doc.fullName;
} catch(e) {
alert("Dokument není ještě uložen. Použij File / Save as... k uložení dokumentu.");
return;
}
// --------------------------------------------------------------------------------------------------------
var filename = app.activeDocument.fullName.toString();
var number = filename.split("_");
var extension = filename.split(".");
var newfilename = "";
for (i=0; i<(number.length - 1); i++) {
newfilename += number[i];
}
if (parseInt(number[number.length - 1]) < 9) {
newfilename += "_0" + (parseInt(number[number.length - 1]) + 1) + "." + extension[extension.length - 1];
} else {
newfilename += "_" + (parseInt(number[number.length - 1]) + 1) + "." + extension[extension.length - 1];
}
// --------------------------------------------------------------------------------------------------------
var newfile = new File(newfilename);
doc.saveAs(newfile);
}
}
autosave();
wwwwoody
01-29-2007, 01:15 PM
i tested this script in CS (i remove app.bringToFront()), but doesnt work correctly
berniebernie
01-29-2007, 11:28 PM
works perfectly on my machine
if your doc doesn't have _# or _## (underscore + digits) it just saves as _NaN though (not a number...) but i believe it behaves the same way in Cs2+
wwwwoody
01-30-2007, 12:43 AM
works perfectly on my machine
if your doc doesn't have _# or _## (underscore + digits) it just saves as _NaN though (not a number...) but i believe it behaves the same way in Cs2+
i know, i debug this problem. i think up timer for this script and i create interface for pack of tools for ps. and i localize these tools to some languages :-) i want to create silent mode for this tool too etc.
i want to create incremental autobackup for ps :-)
thx for interest :-)
berniebernie
01-30-2007, 02:20 PM
I love scripting as well, make sure you visit www.ps-scripts.com/bb/ for great script authors and if you really want to push your scripts forward (and why not make plug-ins to integrate it better to PS), try to get your hands on a Photoshop Source Development Kit (SDK) which you can register for (free) over at the Adobe website
mlk
wwwwoody
01-30-2007, 02:34 PM
I love scripting as well, make sure you visit www.ps-scripts.com/bb/ (http://www.ps-scripts.com/bb/) for great script authors and if you really want to push your scripts forward (and why not make plug-ins to integrate it better to PS), try to get your hands on a Photoshop Source Development Kit (SDK) which you can register for (free) over at the Adobe website
mlk
this forum i know, but admin didnt activate my account yet :sad:
I post a request of ps SDK yesterday :-) during 4 days i will have a answer :)
:thumbsup:
wwwwoody
01-31-2007, 04:58 PM
hi :) i have photoshop SDK now :)
but only for Visual Studio NET, grr, i use Delphi. i find sdk for delphi, but its old version without new features :sad:
wwwwoody
02-01-2007, 02:01 AM
#target photoshop
//app.bringToFront();
function autosave() {
// check active document
if (app.documents.length == 0 || !app.activeDocument) {
//alert("Není otevřen žádný dokument.", "w-tools | Incremental saveing");
return;
} else {
var doc = app.activeDocument;
try {
doc.fullName;
} catch(e) {
var alertmsg = {en: "This document has no default file name associated with it. Use File > Save As", cz: "Dokument není ještě uložen. Použij Soubor > Uložit jako... k uložení dokumentu."};
alert(localize(alertmsg), "w-tools | Incremental saveing");
return;
}
// --------------------------------------------------------------------------------------------------------
// rename document
var filename = app.activeDocument.fullName.toString();
var number = filename.split("_");
var extension = filename.split(".");
var newfilename = "";
var fname = "";
var limit = 5; // 0 = unlimited
var path = "H:/"; // if empty, path same as original document
var folder = new Folder (path);
if ((path != "") && (folder.exists)) {
var name = filename.split("/");
fname = path + name[name.length - 1].substr(0, (name[name.length - 1].length - extension[extension.length - 1].length - 1));
} else {
fname = filename.substr(0, (filename.length - extension[extension.length - 1].length - 1));
}
if (!isNaN(fname.substr(-2, 2)) && fname.substr(-3, 1) == '_') {
newfilename = fname.substr(0, fname.length - 3);
if ((parseInt(number[number.length - 1]) < limit) || (limit == 0)) { // limit of backup files
if (parseInt(number[number.length - 1]) < 9) {
newfilename += "_0" + (parseInt(number[number.length - 1]) + 1) + "." + extension[extension.length - 1];
} else {
newfilename += "_" + (parseInt(number[number.length - 1]) + 1) + "." + extension[extension.length - 1];
}
} else {
newfilename += "_01." + extension[extension.length - 1];
}
} else {
newfilename = fname + "_01." + extension[extension.length - 1];
}
// --------------------------------------------------------------------------------------------------------
// save document
var newfile = new File(newfilename);
doc.saveAs(newfile); // save as psd
}
}
autosave();
this is last version of incremental saveing script for ps cs2/cs3. in pas script cant create timer for autobackup, but i work on set of interesting tools for ps. who have interest for autobackup plugin and who have some ideas, pls write me :)
jan
berniebernie
02-01-2007, 09:42 AM
I'd be interested !
I've been working with VBscript to do it but it's not really the best way (the script is launched externally) but it does work the way I need it to.
CGTalk Moderation
02-01-2007, 09:42 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2009, Jelsoft Enterprises Ltd.