PDA

View Full Version : How can I get an array of all scene items



MetaNerd
08-06-2003, 11:45 AM
I have only seen get Selected objects.
Is there a way to get All objects in the scene (independent of their genus) so I can cycle through them.

Thanks,

Chris

Tom Speed
08-06-2003, 07:37 PM
Here ya go, this will gather just the names & IDs of all Objects, Bones, Lights, Cameras.

As you'll see the process for each item type is the same, except that as far as I know, Bones can only be accessed through the Mesh they belong to, as they can't exist by themselves.

If you're testing this on a large scene with LOTS of items in it, you might want to rem out the info() calls :)



@version 2.6
@warnings
@script generic
@name ListAllItems

generic
{
// Objects ..
objOA=Mesh(); // Object Agent for first Mesh in scene
while(objOA) // If there's a Mesh ..
{
ObjNameList += objOA.name; // Get its name
ObjIDList += objOA.id; // Get its id

// Bones can't exist by themselves, so you access them via their Parent Mesh.
// So after getting the Mesh info, check if it has any Bones e.t.c before
// moving to the next Mesh
boneOA=objOA.bone(); // First Bone of this Mesh..
while(boneOA)
{
BoneNameList += boneOA.name;
BoneIDList += boneOA.id;
boneOA=boneOA.next(); // Next bone
}
objOA=objOA.next(); // Next Object
}

// Lights ..
lightOA=Light();
while(lightOA)
{
LightNameList += lightOA.name;
LightIDList += lightOA.id;
lightOA=lightOA.next();
}

// Cameras ..
cameraOA=Camera();
while(cameraOA)
{
CameraNameList += cameraOA.name;
CameraIDList += cameraOA.id;
cameraOA=cameraOA.next();
}

// ACTION! (sorry, couldn't resist! :)
info(ObjNameList);
info(BoneNameList);
info(LightNameList);
info(CameraNameList);
}


Cya!
Tom