PDA

View Full Version : Incremental Saver (Modeler)



riki
06-13-2003, 07:59 PM
Does anyone know of an Lscripy that does incremental saves for objects in modeler??

ie

head_01.lwo
head_02.lwo etc

I use to have one from the dugosaurus site but it died with the 7.5c update.

Agni
07-12-2003, 03:58 AM
Hi riki,

I was going to write an incremental save for the LW users at work, but never got around to it yet. Down loaded yours but it is compiled so I can not view it or change it. I was going to change what was needed to make it work for 7.5c. If you have the uncompiled version, I can fix it and send you the fixed version. :)

I only do LScripting at work. The other users are the animators. Amoung some scripts I have written are: Move/Copy/Replace/Merge/Swap Layers, Poly Layer Info, Random Point/Poly Select, Layer Delete, Layer Insert and much more. These names do not explain all they do. If you have some interesting (useful) scripts, maybe we can swap. :cool:

Agni

papou
07-12-2003, 05:48 PM
Hi, try object incrementor from:
http://www.h2mw.com/main.htm
ciao-

riki
07-12-2003, 07:04 PM
Hi Agni thanks for taking the time to check that for me. Silly mistake by me, I know. I've downloaded a ton of lscripts/plugins from various sites but haven't had time to experiment with many. A couple of the ones I use are listed on this page http://www.suture.net/tutorials/modeling/page11.shtml

I'm going to add more in the not too distant future.

Thanks Papou for the link I'll give that a try. Looks like they have some other cool stuff on that site. ProxiMo looks interestiing re: http://www.h2mw.com/products/proximo.htm

riki
07-12-2003, 10:06 PM
Damn I just checked out object incrementor but it's for Layout not Modeler.

I also noticed in the comments section of Flay
http://www.flay.com/GetDetail.cfm?ID=1551
that someone else was thinking the same thing. Damn Damn Damn :)

riki
07-12-2003, 10:23 PM
I imagine that this Lscript would be pretty easy to write. I don't know a thing about programming but my guess is that it would function as follows.

1. The user starts by saving the file with a two digit extension. ie myfile_01.lwo

2. Then when you run the script (which I use to have mapped to my Toolbar). It starts by getting the main variable, which of course would be the title of the current object. So the first variable would be

current_object = "myfile_01.lwo"

3. It would then have to parse that value, ie break it down into workable parts. So you would end up with something like

title = "myfile_"
current number = "01" + 1
extension = ".lwo"

and finally somehow "myfile_02.lwo"

4. Last of course 'Save AS' with the new name

PS excuse my lack of knowledge regarding syntax

papou
07-13-2003, 07:01 AM
it's pretty easy to do that.. i will try. But i'm not a speedy programmer so if u are hurry, it's maybe better to ask to the dugosaurus man a new compatible one. Or ask to Lscript community, they don't like to make scripts when ask but it's really easy to make.
time to trip another time in Lscript chaos....

riki
07-13-2003, 07:15 AM
Thanks Papou I think the dugosaurus site doesn't exist anymore. Not sure what happened to the original creator.

papou
07-13-2003, 07:48 AM
ok i got it,
i hope it work for you.
save first with 2 digit or it will save as NoName_01.lwo.
If you forget to write digit, it will add _01.lwo at the first use of IncSaveObj2.

Have fun.

riki
07-13-2003, 08:19 AM
Wow thanks papou, that was quick :)

Ar first it seems to be working, I save the intial object manually as

myfile_01.lwo

then make some changes, run the plugin and it changes to

myfile_02.lwo
myfile_03.lwo
myfile_04.lwo etc

But when I check to Object Directory it only contains the original file. So it's not actually saving the new files.

faulknermano
07-13-2003, 09:24 AM
here's my incremental saver. it's naming convention is different from what you guys are talking about. what this saver does is create a new folder that has the same name as your object and saves the object in date and time format. at the moment the number of files before it starts replacing the oldest object is 15 files. you can change that value on line 115.

anyway, i'm using a UDF copyfile() because 2.5.1 had a broken copyFile(). you can simply replace all instnaces of copyfile() as copyFile() and delete the UDF.

i'm sure you guys can find your way to customize the script to your liking.




@warnings
copyfile: in, out
{
in = File(in,"rb");
if(!in)
return(-1);

out = File(out,"wb");
if(!out)
{
in.close();
return(-1);
}

while(1)
{
b = in.readByte();
last if in.eof();
out.writeByte(b);
}

in.close();
out.close();

return(0);
}
main // incremental saver
{
selmode(GLOBAL);
md[1] = nil;
objectDir = getdir(OBJECTSDIR);
meshFilename = Mesh(0).filename; // fullpath

mesh = Mesh() || error("No mesh.");
m = 0;
while(mesh)
{
m++;
if(mesh.name == "Unnamed")
error("<br>Object number ",m," is unnamed.");
mesh = mesh.next();
}


if(meshFilename == nil)
{
if(pointcount())
{
f = getfile("Save Object As...","*.lwo",objectDir);
if(f)
save(f);
}
return;
}

save(meshFilename);
(d,p,f,e) = split(meshFilename);

s = string("backup_",f);
md = matchdirs(objectDir,s);
if(md.size() > 1)
error("More than one matching directories were found. Aborting.");

if(!md) // no folders exist
{
// create a folder
str = string(d,p,"backup_",f);
mkdir(str);
backupDir = str;
}
else
backupDir = string(d,p,"backup_",f);

// scan the backupdir

dd = date();
d1 = dd[1];
mon = dd[2];
year = dd[3];
tt = time();
h = tt[1];
m = tt[2];
s = tt[3];
day = string(d1);
mon = string(mon);
year = string(year);

if(day.size() < 2)
day = string("0",day);
if(mon.size() < 2)
mon = string("0",mon);


hs = string(h);
ms = string(m);
ss = string(s);



if(hs.size() < 2)
hs = string("0",hs);
if(ms.size() < 2)
ms = string("0",ms);
if(ss.size() < 2)
ss = string("0",ss);

finalName = string(year,"_",mon,"_",day,"_",hs,".",ms,".",ss); // finalName is the incremented save

mf = matchfiles(backupDir,"*.lwo");
if(mf.size() >= 15) // start replacing
{
mf.sortA();
str = string(backupDir,"\\",mf[1]);
a = filedelete(str);
}

newFile = string(backupDir,"\\",finalName,".lwo");
a = copyfile(meshFilename,newFile);

}

papou
07-13-2003, 09:59 AM
ah that strange, work fine here... maybe it's a problem of path, i think it saving them somewhere....not in the object directory...sorry..
better to use faulknermano's one, or try to modify the path.
ciao-

papou
07-13-2003, 12:27 PM
work for you Cim?

riki
07-13-2003, 06:06 PM
Cim's version didn't work for me either. I'm on a mac, not sure if that buys into the equation??

faulknermano
07-14-2003, 05:44 AM
Originally posted by riki
Cim's version didn't work for me either. I'm on a mac, not sure if that buys into the equation??

hmm.. it could be... there are path syntax differences between the two...

riki
07-15-2003, 02:08 AM
Thanks anyway I think I'll file it in the too hard basket for now.

faulknermano
07-15-2003, 08:30 AM
Originally posted by riki
Thanks anyway I think I'll file it in the too hard basket for now.

zats funny.

NEVER GIVE UP! NEVER SURRENDER!:)

riki
07-15-2003, 08:45 AM
Do you think it's possible?? Surely technology isn't that advanced yet??

I mean we must first find a cure for the common cold, then put men on mars before we can hope to begin to contemplate the 'Incremental saver' :)

faulknermano
07-15-2003, 09:10 PM
Originally posted by riki
Do you think it's possible?? Surely technology isn't that advanced yet??


probably not for the mac, it isnt.

:D

faulknermano
07-15-2003, 09:14 PM
no, but seriously...

mac paths are different. i think it is just a matter of discovering how they are written in lscript, if there are differences in the PC version. i've had problems in the past (but i cant remember specifics) and there have been lscript issues back then. i know that bob was supposed to have fixed some, but because i am not running a mac, i forgot exactly what those fixes involved in relation to file paths.

at any rate, i'm sure it will work if you just experiment more on it. my gut feel is that it is file path problem, and it is fairly easy to troubleshoot.

NO PAIN, NO GAIN! :D

riki
07-15-2003, 09:28 PM
what part of Dug script should I be looking at?? ie relating to the file path??



//-----------------------------------------
// IncSaveObj2: Incremental_Save_for_modeler
// modified version from IncSaveLay: Incremental_Save_for_Layout
// (c) Dug Stanat 2002 // www.dugosaurus.com
// modified by TAIS [C] 2003

@version 2.2.2 //version of LScript required
@warnings

main
{

scene_info = Mesh(0);
filename = scene_info.filename;

if (filename == nil)
{
objDir = getdir("Objects");
nofilename = string(objDir+"/NoName_01.lwo");
save(nofilename);
return;
}


if(filename == s~.+([0-9][0-9]\.lwo$)~)
{
numbers = strright(filename,6);
numbers = strleft(numbers,2);
numbers = integer(numbers);

if (numbers > 98)
{
error("increment too high");
return;
}

incremented_number = numbers + 1;

num_characters = size(filename);
num_characters = num_characters - 6;

if(incremented_number < 10) filename = (strleft(filename,num_characters) + "0" + incremented_number + ".lwo");
else filename = (strleft(filename,num_characters) + incremented_number + ".lwo");

if(fileexists(filename))
{
error("increment already exists!!!");
return;
}

save(filename);

}

else
{
num_characters = size(filename);
num_characters = num_characters - 4;
filename = strleft(filename,num_characters);
newfilename = string(filename +"_01.lwo");

save(newfilename);
}

}

riki
07-15-2003, 10:41 PM
When I run the above script it creates a file with the same name as my hard drive. The file is simply called 'HD'.

It's being saved in the content folder, not the actual object directory.

Also if I open this file in simple text , this is what it looks like (see attached image)

riki
07-15-2003, 10:45 PM
That piece of code is the same as the object file. So it is being saved.

But

1. It's not being saved in the 'Objects' directory.

2. And it's not being saving the file name correctly.

Any bells ringing ?? :)

faulknermano
07-16-2003, 01:19 AM
the variable newfilename is the one you should be looking at. i cant test the script right now, but watch out for that variable. before it tries to save() with that variable, test it first by using the info() function.

if the resulting info is wrong, go back down the line where it came from.

you should also be able to monitor the file and its paths from the info box. if there is anything wrong within that line of "passing variables" you will be able to detect where the script (or lscript) screws up the path, and where you can probably interject the correct code.

i can probably check out dug's script later tonight.

faulknermano
07-16-2003, 01:43 AM
okay, here, do a check:

insert the following code (in italics) in the code snippets:



scene_info = Mesh(0);
filename = scene_info.filename;

info(filename);
return;



(the return command below is just to cut the script short so we can focus on the info box)

if the info displays your proper path name then that is good. the script bases everything else on this filename. however, if there is no filename then it will run the if() block just below it. determine if the getdir("Objects") command is assigning the correct path to the objDir variable. do this only if the first info() box did not display the correct path and filename of your currently opened object.

it would help if you could post the actual path it outputs. i'm not familiar with mac paths, as you may already know. :)

and another thing: what version of lscript are you running?

riki
07-16-2003, 02:00 AM
I just tested

info(filename);
return;

as you mentioned and it's returning the full correct path

riki
07-16-2003, 02:07 AM
The full path is


HD:Desktop Folder:untitled folder:Objects:test_01.lwo

riki
07-16-2003, 02:18 AM
How do I check which version of Lscript?? I'm using Modeler 7.5c so assuming that it's the latest version??

faulknermano
07-16-2003, 07:34 AM
you can find out the version by running the lscript 'front end' of any architecture. for example, go to the master class plugins panel and from the pulldown select LScript. the version number will appear on the dialog box.


since the variable is returning the correct path, you have no problems at that point of the lscript. try finding out what the variable newfilename contains. that is the one at the bottom of the script that's also saving.


man, i wish i had a mac to test this one out.... :)

riki
07-16-2003, 08:11 AM
Okay I got v2.6.1

I tried:

-------------------

else
{
num_characters = size(filename);
num_characters = num_characters - 4;
filename = strleft(filename,num_characters);
newfilename = string(filename +"_01.lwo");

info(newfilename);
return;

save(newfilename);
}

}

-------------------

But no value was returned, and no show on the popup front.

Then I tried:

-------------------

if(fileexists(filename))
{
error("increment already exists!!!");
return;
}

info(filename);
return;

save(filename);

}

else
{
num_characters = size(filename);
num_characters = num_characters - 4;
filename = strleft(filename,num_characters);
newfilename = string(filename +"_01.lwo");

save(newfilename);
}

}

-------------------

And here's the strange bit, it returned the correct file path, to the Objects Directory with the correct file name test_02.lwo

How bizzare is that??

faulknermano
07-16-2003, 09:53 AM
the variable newfilename is probably getting screwed up along the way when the script is trying to rename it.

take a look at the code below:



else
{
num_characters = size(filename);
num_characters = num_characters - 4;
filename = strleft(filename,num_characters);
newfilename = string(filename +"_01.lwo");

save(newfilename);
}


try to verify each of those variables, if they indeed contain the correct values: num_characters, filename, and newfilename. check it from within the else block and see what comes up.

we're getting there. :)

riki
07-16-2003, 10:18 AM
I went through and tried to varify each variableon each line (one at a time) but wasn't getting anything back from any of them. Could it be that this section of the code isn't firing?




else
{
num_characters = size(filename);

info(num_characters);
return;

num_characters = num_characters - 4;
filename = strleft(filename,num_characters);
newfilename = string(filename +"_01.lwo");

save(newfilename);
}
}

faulknermano
07-16-2003, 10:31 AM
when you say nothing is being 'given back' you are saying that the info() box says absolutely NOTHING? not even a "(nil)"? if so, it is likely that some functions like size() is returning a data type that info() cannot display.

try:




info(filename); // to make sure that filename is not nil
num_characters = filename.size(); // use the size variable message method instead of the size func

info(num_characters); // what does this read?



EDIT: the else block runs on the first item. for example, if you have an object saved as test.lwo, the else block saves it as test_01.lwo. that's the only thing it does.

so now i'm stumped. okay here: make a box, save it as test.lwo. run the script below:




//-----------------------------------------
// IncSaveObj2: Incremental_Save_for_modeler
// modified version from IncSaveLay: Incremental_Save_for_Layout
// (c) Dug Stanat 2002 // www.dugosaurus.com
// modified by TAIS [C] 2003

@version 2.2.2 //version of LScript required
@warnings

main
{

scene_info = Mesh(0);
filename = scene_info.filename;

if (filename == nil)
{
objDir = getdir("Objects");
nofilename = string(objDir+"/NoName_01.lwo");
save(nofilename);
return;
}


if(filename == s~.+([0-9][0-9]\.lwo$)~)
{
numbers = strright(filename,6);
numbers = strleft(numbers,2);
numbers = integer(numbers);

if (numbers > 98)
{
error("increment too high");
return;
}

incremented_number = numbers + 1;

num_characters = size(filename);
num_characters = num_characters - 6;

if(incremented_number < 10) filename = (strleft(filename,num_characters) + "0" + incremented_number + ".lwo");
else filename = (strleft(filename,num_characters) + incremented_number + ".lwo");

if(fileexists(filename))
{
error("increment already exists!!!");
return;
}
info("old"," ",filename);
save(filename);

}

else
{
num_characters = size(filename);
num_characters = num_characters - 4;
filename = strleft(filename,num_characters);
newfilename = string(filename +"_01.lwo");
info("new"," ",newfilename);
save(newfilename);
}

}


go to alert level expert keep on running it, always watching that saved path. is it the correct one?

riki
07-16-2003, 10:53 AM
yeah no it's not giving me anything at all no info popup, no nil.

I just ried the version below and same result, no infomation at all.


else
{
info(filename); // to make sure that filename is not nil
num_characters = filename.size(); // use the size variable message method instead of the size func

info(num_characters); // what does this read?
filename = strleft(filename,num_characters);
newfilename = string(filename +"_01.lwo");

save(newfilename);
}

}

riki
07-16-2003, 10:58 AM
What I can't work out is that at this point it has the full correct file name with the incremented extension ie "test_02.lwo"


all it needs to do is save the file. But "save(filename);" doesn't seem to be working.



if(fileexists(filename))
{
error("increment already exists!!!");
return;
}

info(filename);
return;

save(filename);

}

riki
07-16-2003, 11:01 AM
It doesn't really need this bit of code at the end does it?




else
{
num_characters = size(filename);
num_characters = num_characters - 4;
filename = strleft(filename,num_characters);
newfilename = string(filename +"_01.lwo");

save(newfilename);
}

}




The original file that this was created from had this at the end instead




else
error("This LScript increments files that end in ##.lws");

}

riki
07-16-2003, 11:14 AM
I just ran your complete version of the script with a box object called 'test.lwo'. I ran it in expert mode and noticed something strange.

the first time I run it I get

new HD:Desktop Folder:Test:Objects:test_01.lwo

the second time I run it I get

old :HD:Desktop Folder:Test:Objects:test_02.lwo

the third time I run it I get

old ::HD:Desktop Folder:Test:Objects:test_03.lwo

notice the :::: building up in front of "HD"

Thanks for your help, must be time to hit the sack, uugh almost 3am :).

papou
07-16-2003, 04:21 PM
is it possible that the problem come from?
if(filename == s~.+([0-9][0-9]\.lwo$)~)


maybe this one will work.?...


//-----------------------------------------
// IncSaveObj2: Incremental_Save_for_modeler
// modified version from IncSaveLay: Incremental_Save_for_Layout
// (c) Dug Stanat 2002 // www.dugosaurus.com
// modified by TAIS [C] 2003

@version 2.2.2 //version of LScript required
@warnings

main
{

scene_info = Mesh(0);
filename = scene_info.filename;

if (filename == nil)
{
objDir = getdir("Content");
info(objDir);
nofilename = string(objDir+"/NoName_01.lwo");
save(nofilename);
return;
}

numbers = strright(filename,6);
numbers = strleft(numbers,2);
check = integer (numbers);


if (check != nil) {


if (numbers > 98)
{
error("increment too high");
return;
}

incremented_number = numbers + 1;

num_characters = size(filename);
num_characters = num_characters - 6;

if(incremented_number < 10) filename = (strleft(filename,num_characters) + "0" + incremented_number + ".lwo");
else filename = (strleft(filename,num_characters) + incremented_number + ".lwo");

if(fileexists(filename))
{
error("increment already exists!!!");
return;
}

save(filename);

}

else
{
num_characters = size(filename);
num_characters = num_characters - 4;
filename = strleft(filename,num_characters);
newfilename = string(filename +"_01.lwo");


save(newfilename);
}

}

riki
07-16-2003, 06:26 PM
Hi papou, I gave it a burl, but it returned the error message 'Increment Too High' even though the file was only 'test_01.lwo'.

faulknermano
07-16-2003, 07:03 PM
Originally posted by riki
I just ran your complete version of the script with a box object called 'test.lwo'. I ran it in expert mode and noticed something strange.

the first time I run it I get

new HD:Desktop Folder:Test:Objects:test_01.lwo

the second time I run it I get

old :HD:Desktop Folder:Test:Objects:test_02.lwo

the third time I run it I get

old ::HD:Desktop Folder:Test:Objects:test_03.lwo

notice the :::: building up in front of "HD"

Thanks for your help, must be time to hit the sack, uugh almost 3am :).

indeed very strange. i cannot see anything in dug's code that will, in any way, create those characters at the beginning of the path.

i'd like to ask if new HD:Desktop Folder:Test:Objects:test_01.lwo, the first one you ran, and the first one with the correct path, saved and named properly? if it saved properly, at least now we know that lscript will save an object properly as long as we give it the PROPER mac paths.

now for the progressing :::, i cannot attribute to any line of code (dug uses strleft() which simply gathers all specified characters from the LEFT of the string. there SHOULDNT be a colon to begin with. it would be somewhat understandable if he used strright(), but he doesnt, when he reassigns the variable filename.

okay here. the filename variable will get changed along the course of the script. let's monitor that file name as the increments are getting made. it's the only question, it seems.

could you insert the follow code (bold letters):



scene_info = Mesh(0);
filename = scene_info.filename;
ofilename = filename;


and



info("old"," ",ofilename);
save(filename);



you see, again, dug's code does not change the LEFT part of the string. it just appends the new increments into place. now i'm suspecting that scene_info.filename is doing all that screwy stuff.

if ofilename DOES NOT exhibit the increasing :::, then, jeez, you're going to have to do some string manipulation (not hard) to get rid of it. it all depends.


What I can't work out is that at this point it has the full correct file name with the incremented extension ie "test_02.lwo"


all it needs to do is save the file. But "save(filename);" doesn't seem to be working.

when you said this, are you sure there werent any of those excess colons?


It doesn't really need this bit of code at the end does it?


actually, it's there only when you first save your object that doesnt have an increment. you dont really need it, but i doubt that is the problem (in fact i think that's the only piece of code that works at the moment).

riki
07-16-2003, 07:23 PM
Thanks Faulknermano


i'd like to ask if new HD:Desktop Folder:Test:Objects:test_01.lwo, the first one you ran, and the first one with the correct path, saved and named properly? if it saved properly, at least now we know that lscript will save an object properly as long as we give it the PROPER mac paths.

No in all the time I've been testing the script it has never saved the file with the correct name, or in the 'Objects' directory. Something has obviously changed with the Lscript update becuase the original 'Incremental Saver' from the dugosaurus site use to work fine on my system before the 7.5b upgrade.

When I run the script the first time it saves in the main 'Content Directory', if I run it again with the same object it saves on the Desktop, if I run it again it save inside my 'HD' Directory. Each time the file is simply called 'HD'. I've even found 1 copies of this file in the Lightwave Programs folder.

So it's possible that the 'save' function isn't working?? Or that the increments are making it go up one directory level each time, which would explain the :::

riki
07-16-2003, 07:41 PM
I just did the other test, and I'm getting the same result (see pix), it seems that it can only go up to test_04.lwo, it won't go any higher than that. I'm guessing that's becuase it can't go up another directory.

re ::: seems to be the max.

faulknermano
07-16-2003, 07:44 PM
well, if it doesnt save the correct file despite a correct path then there's no way we can make this work at all.

wow. okay. i suppose that settles it. are you subscribed to the lscript mailing list (e.g. yahoogroups)? if so, do report the bug over there (since you have the mac lscript plug).. if you cant, i'll do it myself and ask for a bug confirmation at any rate. if it isnt a bug, maybe a mac user can help out.

riki
07-16-2003, 08:01 PM
Hi faulknermano, damn you were right the first time, "we don't have the technology on the mac" :)

Yeah I suspect it's got to be a bug. I'll check to see if bob mentions anything in his notes.

I'm not a member of that Yahoo group. If you get a chance, could you mention it for me.

Thanks again for your help, much appreciated.

faulknermano
07-18-2003, 05:45 AM
pazur replied over in the lscript mailing list:




LW7.5c LScript on OSX has broken file managment and this is confirmed.
The only situation that seems to work is when You try to open/save
file without adding path (saving to main content dir), just filename.


so it is confirmed. you can, optionally, revert back to lscript 2.5.1 i think it will work. michael linde mentioned that he was still using 2.5.1 and the script works for him. unless you need to use 2.6.1, i suggest going back.

faulknermano
07-18-2003, 05:54 AM
riki, have you tried the saver posted? i use save() once, and it is to save the object as it is, but save the actual increment using copyfile(). i think that's a good bypass.

if you have my saver, go to the line (somewhere at line 56):



save(meshFilename);


change that to:



sp = split(meshFilename);
newmesh = string(sp[3],[sp4]);

save(newmesh);



see if that works.

riki
07-18-2003, 06:21 AM
Oh thanks for that, nice to know I wasn't going crazy :)

yep yep I'll give your work around ago, just hitting the pisss at the moment :) Thank god the weekend is here.

riki
07-18-2003, 09:32 AM
Hi faulknermano, I tried your original script and I was getting the same sort of problem.

I just tried the suggested changes and got an error message

"In main, Line 57, found '[' parse error.



@warnings
copyfile: in, out
{
in = File(in,"rb");
if(!in)
return(-1);

out = File(out,"wb");
if(!out)
{
in.close();
return(-1);
}

while(1)
{
b = in.readByte();
last if in.eof();
out.writeByte(b);
}

in.close();
out.close();

return(0);
}
main // incremental saver
{
selmode(GLOBAL);
md[1] = nil;
objectDir = getdir(OBJECTSDIR);
meshFilename = Mesh(0).filename; // fullpath

mesh = Mesh() || error("No mesh.");
m = 0;
while(mesh)
{
m++;
if(mesh.name == "Unnamed")
error("<br>Object number ",m," is unnamed.");
mesh = mesh.next();
}


if(meshFilename == nil)
{
if(pointcount())
{
f = getfile("Save Object As...","*.lwo",objectDir);
if(f)
save(f);
}
return;
}

sp = split(meshFilename);
newmesh = string(sp[3],[sp4]);

save(newmesh);

(d,p,f,e) = split(meshFilename);

s = string("backup_",f);
md = matchdirs(objectDir,s);
if(md.size() > 1)
error("More than one matching directories were found. Aborting.");

if(!md) // no folders exist
{
// create a folder
str = string(d,p,"backup_",f);
mkdir(str);
backupDir = str;
}
else
backupDir = string(d,p,"backup_",f);

// scan the backupdir

dd = date();
d1 = dd[1];
mon = dd[2];
year = dd[3];
tt = time();
h = tt[1];
m = tt[2];
s = tt[3];
day = string(d1);
mon = string(mon);
year = string(year);

if(day.size() < 2)
day = string("0",day);
if(mon.size() < 2)
mon = string("0",mon);


hs = string(h);
ms = string(m);
ss = string(s);



if(hs.size() < 2)
hs = string("0",hs);
if(ms.size() < 2)
ms = string("0",ms);
if(ss.size() < 2)
ss = string("0",ss);

finalName = string(year,"_",mon,"_",day,"_",hs,".",ms,".",ss); // finalName is the incremented save

mf = matchfiles(backupDir,"*.lwo");
if(mf.size() >= 15) // start replacing
{
mf.sortA();
str = string(backupDir,"\\",mf[1]);
a = filedelete(str);
}

newFile = string(backupDir,"\\",finalName,".lwo");
a = copyfile(meshFilename,newFile);

}

faulknermano
07-18-2003, 06:51 PM
whoops!

the code below you see:




newmesh = string(sp[3],[sp4]);


should be:



newmesh = string(sp[3],sp[4]);



when you say "same problem", are you saying about the paths problem? that the files are still not being saved? (stretching this issue just a little bit more... :D)

riki
07-18-2003, 08:03 PM
Hi faulknermano, okay we made some progress :)

It's saving the file, but a few problems.

I started out with an object called 'test.lwo' and this file is keep of course in the 'Objects' directory.

When I run the script it saves the file in the 'Content Directory' and the file is being saved with the same name 'test.lwo'.

If I run it again it gets saved on my Desktop and then if I run it again it causes my system to freeze up.

Also I noticed a text file was created called 'backup_'

faulknermano
07-18-2003, 08:30 PM
okay.. well i think lscript is screwed up big-time now. i think all file management stuff has gone nuts in mac lscript.

the text file you mentioned is actually supposed to be a folder. the idea of the saver is to create a folder for every object you save and then the script saves it on its own folder; the names will be the data and time of the save.

in your case, it doesnt seem that the 'manual' way of saving a file (e.g. using copyfile() to copy the original saved file to another place) isnt even working.

here, i most vote to go back to 2.5.1 (you wont miss that much), unless you dont really need an increment saver. :)

riki
07-18-2003, 08:50 PM
Thanks for all your help faulknermano. I'll probably just do without for the time being, hopefully they'll get it sorted with the next update. Bloody frustrating though :)

richpr
07-19-2003, 06:39 AM
Try this version of the previous script in this thread, here all the files just end up in the objects directory, but you could change that in the last couple of lines.... It does not create a directory or anything... your object and copes with the date tacked on all end up in objects/ or objects/project/ if you would change it...

Hope this one works, tried it here (PC) and it works...


// Incremental Saver uses ObjectName_v_YYYYMMDDHHMMSS.lwo
@version 2.0
@name IncSaveD
@warnings

main
{
selmode(GLOBAL);
md[1] = nil;
objectDir = getdir(OBJECTSDIR);
meshFilename = Mesh(0).filename; // fullpath

mesh = Mesh() || error("No mesh.");
m = 0;
while(mesh)
{
m++;
if(mesh.name == "Unnamed") error("<br>Object number ",m," is unnamed.");
mesh = mesh.next();
}

if(meshFilename == nil)
{
if(pointcount())
{
f = getfile("Save Object As...","*.lwo",objectDir);
if(f) save(f);
}
return;
}
sp = split(meshFilename);
newMesh = string(sp[3],sp[4]);
save(newMesh);

finalName = parse("_v_",sp[3]);
if (!finalName)
{
finalName[1]=sp[3];
}
finalName[1] += "_v_";

dd = date();
d1 = dd[1];
month = dd[2];
year = dd[3];
tt = time();
h = tt[1];
m = tt[2];
s = tt[3];
day = string(d1);
month = string(month);
year = string(year);

if(day.size() < 2) day = string("0",day);
if(month.size() < 2) month = string("0",month);

hs = string(h);
ms = string(m);
ss = string(s);

if(hs.size() < 2) hs = string("0",hs);
if(ms.size() < 2) ms = string("0",ms);
if(ss.size() < 2) ss = string("0",ss);

finalName[1] = string(finalName[1],year,month,day,hs,ms,ss);
newFile = string("objects/",finalName[1],".lwo");
save(newFile);
newFile = string("objects/",newMesh);
save(newFile);
}

richpr
07-19-2003, 06:42 AM
The formatting turned out pretty horrible, so here's the ls file attached as a zip

richpr
07-19-2003, 07:22 AM
Here's a variation that is path aware... at least folder + filename and adds a number at the end... real increment... no 0 padding though... so you get Object_v_1.lwo, Object_v_2.lwo, etc.

Tried it six times, no problem...

A box was saved in <content>/objects/project/test.lwo

and after 6 clicks it was at test_v_6.lwo...

Both versions of the scripts also keep the test.lwo around... which would be better if you were working in Layout at the same time...
Not sure if the temporary save with the number or the date has an effect on the scene in Layout... needs to be tested

[Edit] I added padded versions to the zip as well... these are called incsaven2, incsaven3 and incsaven4.ls... they increment and pad with zeroes (for nicely sorted folders!) ;) , like object_v_0001.lwo for incsaven4.... [Edit]

riki
07-19-2003, 09:59 AM
Thanks richpr

I think I have to give up on this one. I tried the scripts but still no luck. I guess the save function for Lscript on the mac is pretty much messed up. I'll hold onto them though, hopefully with the next update they'll get it sorted.

Thanks again everyone for your help.

richpr
07-19-2003, 10:09 AM
That's a shame... either wait or play around with an older LScript version...

riki
07-19-2003, 10:18 AM
Yeah hopefully they'll pick this up. I've mentioned it in the Sticky Mac Bug thread.

I like the idea of saving the date.

It seems to be working on my system, I run the script and I can see the time stamp, but when I check in the objects folder, there's nothing there. Just the original test.lwo

It's strange becuase even when I'm quiting out of modeler, after running the script, it asks me if I want to save. I press yes, it quits, but still no file. Very frustrating.

richpr
07-19-2003, 06:52 PM
Not in the content folder either?

riki
07-19-2003, 08:17 PM
No not saving it at all, anywhere.

When I tryed the second script it was saving a file called 'Desktop Folder'. The first time it saved it in the Content folder and then the 2nd time I ran the script it saved it on the Desktop.

Red_Oddity
11-12-2003, 09:31 AM
So, did anyone test this on the Mac by replacing the '/' with a ':'?

there's a command for this aswell in 2.6


A getsep() function has been added that will return the platform-specific path separator character.

...
info(getsep()); // displays "\", "/" or ":" depending on the operating system
...

Red_Oddity
11-12-2003, 09:35 AM
Also, does LScript on OSX use Unix pathing ('/Volumes/drivename/path/etc) ?

riki
11-12-2003, 04:25 PM
Thanks Red I'll give it a try.

riki
01-28-2006, 10:20 PM
Coming back to an old thread. First I just wanted to mention that the current Incremental Saver that ships with LW8.5 seems to work fine on the Mac, now using OS10.4

Though I've just tested petterms new script and I seem to be having problems with that (see link below). Specifically Modeler crash and not saving out the file.

http://www.spinquad.com/forums/showthread.php?p=116261#post116261