PDA

View Full Version : Incremental Save Script LW style


preludian
08-30-2004, 02:32 AM
Hi there, I just made my very first JScript and it nearly works pretty well, but there are a few problems I can't get hold off. So maybe some pro could help me out :sad:

As a former LWer I really much like the new incremental save thingie, so I made a script for this.

1 Problem. Assigned to a key it only works once (New Custom Command and then asigned it to strg+s)

2. If I ommit the openscene command the files are created but have locked file added?? What's this.

Here comes the file:

The bold passages are the saving comand for a quick find.
Thanks for your help.

*************************

/*Adds or increments a version number on the scene name,
the format is <filename_vxxx.scn>
If you should have more than 999 versions it resaves at 001 again. A Loop ;)
Oh, take and use the script as it is, no responsability from my side :)

Philipp Smolka 2004/09/30


*/


var r3=0,sNewScriptingName,sScriptingName,sProjectsDir;


// Get complete Filename with Path

sRealName = ActiveProject.ActiveScene.Parameters("Filename").Value
//Application.LogMessage ("My real name is: " + sRealName);

// Get only Filename

sScriptingName = ActiveProject.ActiveScene.Parameters("Name").Value;
//Application.LogMessage ("My scripting name is: " + sScriptingName );

// Get only Path

//sProjectsDir = Application.InstallationPath( siProjectPath )
//Application.LogMessage ("My Project Directory name is: " + sProjectsDir );




// Match for version

var r;
MatchForVersion(r);
//Application.LogMessage ("Found: " + r);

/*
If No add _v001 to Filename and create new filename
*/


if (r == null)
{
//Application.LogMessage ("No Versions yet!");

var sVersion="_v001";
var sDigits,sDigits2;
sNewScriptingName = sScriptingName = ActiveProject.ActiveScene.Parameters("Name").Value+sVersion;

//Application.LogMessage ("My NEW scripting name is: " + sNewScriptingName );

sDigits=sScriptingName.length;
sNewScriptingName = sScriptingName.substr(0,sDigits-5)+sVersion;

// Truncate the filename out of the name

sDigits2=sRealName.length;
sRealName = sRealName .substr(0,sDigits2-sDigits);
//Application.LogMessage ("Result: "+ sRealName);

}



/*
If Yes then get version number and add plus one
*/

if (r != null)
{
//Application.LogMessage ("Version is there, will add 1");

var sVersion="_v001";
var nVersionLength,sDigits,sDigits2,r12,re;

// Go and get the new version number

GetDigits(r3);

// If more than 999 then restart at 001, else add 1
if (r3>=999)
{r3=1}
else
++r3;

// Convert digits to string and get number of digits

sDigits=r3.toString();
nVersionLength=sDigits.length;


// Define the regular expression pattern

if (nVersionLength==1){re = /(\S$)/g;}
if (nVersionLength==2){re = /(\S.$)/g;}
if (nVersionLength==3){re = /(\S..$)/g;}


// Application.LogMessage ("Result: " + re);

// Now fit the new version number into the actual one

sVersion = sVersion.replace(re, sDigits);

// Application.LogMessage ("Result: " + sVersion);

// Truncate the old version number of the actual file and add the new one

sDigits=sScriptingName.length;
sNewScriptingName = sScriptingName.substr(0,sDigits-5)+sVersion;

// Truncate the filename out of the name

sDigits2=sRealName.length;
sRealName = sRealName .substr(0,sDigits2-sDigits-5);
//Application.LogMessage ("Result: "+ sRealName);


}


// Save the new file version

SaveNewFilename();




// Save new Filename

function SaveNewFilename()
{
SaveSceneAs (sRealName+"\\"+sNewScriptingName+".scn (file:///)");
//Application.LogMessage ("New Save Name: " +sRealName+"\\"+sNewScriptingName+".scn (file:///)");
//OpenScene (sRealName+"<A href="file://\"+sNewScriptingName+".scn",null,null">\\"+sNewScriptingName+".scn",null,null);
}

// Match for Version Check if Version already exists

function MatchForVersion()
{
var re;
re = new RegExp("_v[0-9]{3}","ig"); //Create regular expression object.
r = sScriptingName.match(re);
return(r);
}


// Get Digits Get only the three version digits

function GetDigits()
{
var re3;
// var re2,r2;
// re2 = new RegExp("_v[0-9]{3}","ig"); //Get version syntax _vxxx
// r2 = sScriptingName.match(re2);

re3 = new RegExp("[0-9]{3}","ig"); //Get only version number
r3 = sScriptingName.match(re3);

// Application.LogMessage ("Old Version Number: " + r2);
return(r3);
}

preludian
08-30-2004, 04:34 PM
No coder has an idea??

Maybe someone could at least try the script out. I want to know if you are able to map the script to a key and start it several times. Funny is, that I'm able to run the script with no problems in the editor, as often as I want.

Oh and, what and about the *.scntoc files? They are always created, even with no script. Do I have to delete them once and a while??

Here the script:

http://www.smolka1.de/xsi/IncrementalSave.js

preludian
08-30-2004, 07:34 PM
Wow, much activity on this thread :)

Well it works now. The code was ok, it was the way I implemented it as a custom command, I had the wrong handler. I simply redid it with the custom command wizard and voilą, it works simply great, like in LW, fits my workflow :bounce:

Ok, feel free to use it, the link is the same, only updated the file. I changed my strg+s key to do a incremental save instead of a save as.

bye

Edit: I forgot to say, the script checks if a version is already added, if not it will make a *_v001 adding at the end, if yes it will count up from _v001 to _v999. If you should reach the _v999 then it will restart at _v001, thus overriding your oldest versions again. Normally 999 versions should soffice IMO.

Ablefish
08-30-2004, 09:14 PM
Um, maybe you missed my post in the first thread about this, but XSI does this automatically. The most recent save is in your Scenes folder, but the last N saves (determined in preferences - default 4) are stored in incrementally numbered folders in the Backup Folder for the project.

In my opinion this is preferable if you're doing any batch rendering or using a render manager because of the name of your scene isn't changing.

preludian
08-30-2004, 11:05 PM
Ablefish: No I didn't miss your reply, but I didn't realize that it works even when autoupdate is disabled. Maximum versions are 100 and maxdays are 31, that should be enough. I don't know if I would have written this script if I had realized this before, hmmm, oh man so much work for nothing :scream: , I can't imagine why I should use my script anymore, THANK YOU Ablefish ;)
Oh well it was good scripting practice. Maybe someone will be so kind and provide me with a reason why my script is usefull, PLEASE...

BTW I read several times that referencing was buggy in <4 has this been fixed now??

Oh I found one reason :) it's easier to reopen an old or most recent version with my script.

DougNicola
08-31-2004, 12:15 AM
Oh and, what and about the *.scntoc files? They are always created, even with no script. Do I have to delete them once and a while??
you can disable this in preferences->data management.

preludian
08-31-2004, 12:33 AM
thanks Doug!

chesterjoe
08-31-2004, 02:36 AM
Well problem solved it seems,hehe but anyway next time you can try to cross post in xsibase as well under programming. you multiply your chances of getting any answer by posting both places.
Cheers...

JDex
08-31-2004, 04:44 AM
Well problem solved it seems,hehe but anyway next time you can try to cross post in xsibase as well under programming. you multiply your chances of getting any answer by posting both places.
Cheers...
He did ;)

:D

francescaluce
08-31-2004, 04:47 AM
and he found only atyss...

:sad:




ciao
francesca

JDex
08-31-2004, 04:53 AM
I would have helped, but me and scripting languages are like me and italian... barely understood and mostly gibberish. :D

francescaluce
08-31-2004, 05:06 AM
looking at the answer probably is the same also for atyss... :scream:
nah.. c'mon is a good guy(edited).





ciao
francesca

withanar
08-31-2004, 06:53 AM
I was ready to help, but only found it tonight.

Next time I'll be ready. :)

Ablefish
08-31-2004, 05:53 PM
Yeah, scripting practice is never a bad thing. :thumbsup:

preludian
08-31-2004, 09:04 PM
one never knows when it can come handy, I think I'll do a new script which should provide me with a quickrender window inside a view, cool ey, I bet everyone will want this one...:deal:

JDex
11-06-2004, 12:44 PM
Any chance that this handy dandy little script can get a "Special Edition"?

I was wondering if two things can be easily added to a second version of this gem.

1: A ##min Autosave... basically where you edit the number of minutes and then run it... Perhaps a stop feature (somehow, I know little about how scripting is implemented at this point)

2: A popup that will notify you a few seconds before the save so that you can cancel it or just let it run. Also the popup should go away after the save.

Would this even be possible?

preludian
11-06-2004, 02:34 PM
Thanks for calling it a gem :beer:

I'll check if your wishes can be implemented, but I wouldn't have too much hope that this can be coded with JS.

You know that XSI has a autosave implemented don't you?

JDex
11-06-2004, 10:57 PM
Yeah I currently use it... but I think adding the incremental feature and the ability for it to warn you (say 3 seconds before) is good.

I have recently had a few crashes that happened right as Autosave kicked in while I was performing a complex command (such as translating several compenents locally). If it warned me before it would have saved the session.

Cheers for giving it a shot, even if JS can't accomodate it.

preludian
11-07-2004, 11:41 PM
Well, I didn't think it was possible to do some auto call in JS, but it is possible. Unfortunately it isn't possible to do a auto by time :( only by frame move, object select, scene load and so on.

I'm sorry to tell you that I miserably failed. :shrug: Maybe in some newer XSI version, they stated that 'at this time' only the above mentioned automazations were possible. So hope dies last .)

Ca

CGTalk Moderation
01-19-2006, 03:00 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.