Lightwave : hos_incrementalSaveModeler.ls

fancy_worm_blackback_120Here’s a Lightwave Modeler version of the incremental save system we use (finally got some time to clean up the code for release), again, it mimics the way Autodesk Maya does incremental saving.

Just download or copy paste into a text editor and save as an .ls file in your Lightwave Plug-in / Lscript folder, bind to a key of your liking.

Again, if you find anything, let me know.

download : hos_incrementalSaveModeler

.

@script modeler
@version 2.2
@warnings
@name "hos_incrementalSave"

mySeperator = getsep();

main
{
    incrementalSave(Mesh(0));
}

incrementalSave:myObject
{
    myFile = myObject.filename;

    if(myFile) // start creating an incrementalSave
    {
        myFileinfo = split(myFile);

        checkDir(myFileinfo[1] + myFileinfo[2], myFileinfo[3]+myFileinfo[4]);
        incVersion = checkIncrements(myFileinfo[1] + myFileinfo[2] + "incrementalSave" + mySeperator + myFileinfo[3] + myFileinfo[4], myFileinfo[3], myFileinfo[4]);
        incFile = myFileinfo[1] + myFileinfo[2] + "incrementalSave" + mySeperator + myFileinfo[3] + myFileinfo[4] + mySeperator + myFileinfo[3] + "." + strright("000" + incVersion.asStr(), 4) + myFileinfo[4];
        filerename(myFile, incFile); // Using filerename() as move function;
        save(myFile);
    }
    else // The object has never been save before, don't screw this up or people might go Jay and Silent Bob on my ass.
    {
        myDir=getdir(OBJECTSDIR) + mySeperator;
        myFile = getfile("Save Object As", "*.lwo", myDir, 0);
        if(myFile)
        {
            myFileinfo = split(myFile);
            myFile = myFileinfo[1] + myFileinfo[2] + myFileinfo[3] + ".lwo"; // Basically makes sure there's ALWAYS an extension called .lwo
            save(myFile);
        }
    }
}

checkDir:myDir, myFile
{
    dirArray = matchdirs(myDir,"incrementalSave");
    if(!dirArray)
    {
        mkdir(myDir+"incrementalSave");
    }

    dirArray = matchdirs(myDir+"incrementalSave"+mySeperator, myFile);
    if(!dirArray)
    {
        mkdir(myDir+"incrementalSave"+mySeperator+myFile);
    }
}

checkIncrements:myDir, myFile, myExt
{
    incCount = 0;
    incArray = matchfiles(myDir, myFile + "*" + myExt);
    if(incArray != nil)
    {
        foreach(incFile, incArray)
        {
            // wanted to do this part with a more reliable regular expression, but LScript regex is bollocks.
            // So now we just do some string size math and pray that nothing weird is done with the filenames.
            incVersioning = strleft(incFile, size(incFile) - size(myExt));
            incVersioning = strright(incVersioning, 4);
            incCount = max(incCount, incVersioning.asNum());
        }
    }
    else
    {
        return 1;
    }
    return ++incCount;
}
Share

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.