PDA

View Full Version : looping through the meshes in a scene



stib
10-22-2007, 06:28 AM
why doesn't this work? Says that in the line:

meshlist[i] = obj.name()
that obj.name() is an invalid object method. In the docs name() is a perfectly valid method for meshes. What is the getfirstitem() returning, if it isn't meshes?

I'm trying to walk through the items in a scene. Eventually I want to get the filenames of all the objects.


@warnings
@name test
generic
{
scene = Scene();
obj = getfirstitem(MESH);
i=1;
while(i<10)
{
meshlist[i] = obj.name();
obj = NextItem(MESH);
i++;
}
info(meshlist.asStr());

}

Dodgy
10-22-2007, 06:54 AM
.name is a member, not a method, so you should use it like:

myname=myobj.name; // no brackets.

So the full script would be:

myobj=Mesh();
while(myobj)
{


myfile=myobj.filename; //filename is another member
myname=myobj.name;
myobj=myobj.next();

}

stib
10-22-2007, 07:50 AM
ripper! Thanks Dodgy.

so is calling Mesh() functionally the same as getfirstitem(MESH)? I also note the next() method you use there, what class is that a method of?

Confused.

Dodgy
10-22-2007, 08:25 AM
Mesh() returns the first mesh in the scene. the .next() method is a general for cycling through types of items. For example it can be used with Channels, channel groups, surfaces, whatever. You just call it on an object agent of a type, and it'll return the next object agent of that type.

You might want to have a look here:
http://www.dodgy.ghostoutpost.com/Lscript/Lscript%20Index.html

stib
10-22-2007, 05:31 PM
Don't worry, I've got your page bookmarked already - I wouldn't have made it this far without it. Thanks for the help.

stib
10-22-2007, 10:55 PM
okay, here's what I've been working on, for anyone who cares to download and test 'em. There are four lscripts: AutoArchiveObject, AutoArchiveScene, AutoArchiveAllObjects and AutoArchiveEverything.

What they do is save timestamped backups of old versions of your scene / object / everything as you work, and automagically compress the old versions using 7zip (a free compression tool available here (http://www.7-zip.org/)). You need to have 7-zip installed in c:\program files\7zip\ (the default install location) for this script to run as-is, if you want to change the compression utility, or the path to it, you'll have to edit the code (change one string and you're good to go). If I wasn't busy I'd make a configuration file so that the user could set this path themself..

This means that you can do incremental saves without your content directory filling up with zillions of files, and the object / scene name will always remain the same. But if you decide to go back to a previous version you can easily find a scene from a particular point in time, as the old files have a timestamp added to their names.

I'd love to hear any comments.