View Full Version : Iterate through all objects in a scene.

06-26-2011, 10:38 PM
I would like to iterate through all the objects in a scene in layout and save their name, position, and orientations to a file. I am unsure how to iterate through the objects in a scene however. Could you please show me an example? Also, is there a way to get a reference to an object by its name? Finally, is it best to do these tasks in modeler or layout. I assume layout because it is more suited for object placement.

06-28-2011, 01:04 AM
You need to use the Mesh and File Object agents. See the Lscript docs for more info, I don't think anything you are asking for is not covered there, though it may not be 100% clear. (as usual with those docs 8~)

I'm in a bit of a rush at the moment, but try this Layout script for a start - it doesn't write anything out to a file, but will enumerate the objects in a scene: :)

@version 2.13


reqbegin("Layout Test Script - Enumerate Objects");

btn_GetObjects = ctlbutton("Get Object Names",120,"callback_btn_GetObjects");

return if !reqpost();


// this function is called when button is clicked


meshIndex = 1;
// have to start at 1 since 0 is actually the currently selected object
meshLoop = Mesh(meshIndex);

//clear the global array
myObjectNames = nil;

//enumerate the objects
//display the object
info("Object #" + meshIndex + " id: " + meshLoop.id + " name: " + meshLoop.name + " file: " +meshLoop.filename);
// save this object name into a global array
myObjectNames += meshLoop.name;
// get next object in scene
meshLoop = Mesh(meshIndex);

06-29-2011, 08:11 AM
Hey thanks a lot Sami! If I may, I have 1 more question. I am still pretty new to lightwave and I wanted to know if there is a way in layout that I could add an attribute to an object like a string. For example, lets say that I want to export the scene to a file format of my choice for my game. And let's say that certain objects in the level need to have a slippery surface so the player will slide on it. Is there a way that I could add a string attribute to an object in layout like "slippery" and then export that data out? Thanks!

06-29-2011, 08:23 AM
You can use the setTag() function. It's pretty naive and dirty imho. If you want something better it's easy to just create a motion modifier script to contain any value you'd like. Simple but remarkably powerful and comfortable.