preludian
08-30-2004, 01: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);
}
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);
}
