Page 1 of 3 123 LastLast
Results 1 to 15 of 44

Thread: Request: Item replacement LScript for Layout

  1. #1
    Not to scale BlueApple's Avatar
    Join Date
    Nov 2005
    Location
    Los Estados Unidos
    Posts
    1,026

    Request: Item replacement LScript for Layout

    We have scene files containing lots of objects that need to be replaced with similarly named objects. Specifically, objects named my:Object in the scene editor need to be replaced with .lwos named my_Object.

    Here is the pseudo code for what I'm looking for.

    1. Start with first object in Scene Editor.
    2. Save object name as a string.
    3. Replace any colon ( in the name's string with an underscore (_), and add .lwo to the end.
    Ex: my:Object becomes my_Object.lwo.
    4. Use the new object name string to search for a replacement object in the same directory.
    Ex: If my_Object.lwo exists in the directory, then use it to replace the object named my:Object in the scene.
    5. If more unchecked objects remain in the scene, repeat steps 1-4 on the next object.
    Otherwise, stop.

    I am just starting to work on this, but have never written an LScript before. If anyone has already written an object replacement script that I can cannibalize, or wants to point me in the right direction I'd appreciate it. Attached is a .zip containing sample objects and a scene that will show you what I am working with.

    Thanks.
    Adam Martin
    my portfolio
    Mac Pro 2x3Ghz Dual-Core Intel | 8 Gb RAM | OS 10.6.8 | ATI Radeon X1900 XT

  2. #2
    Not to scale BlueApple's Avatar
    Join Date
    Nov 2005
    Location
    Los Estados Unidos
    Posts
    1,026
    Below is where I'm at with the script. I am trying to figure out the syntax for all of this still. I am familiar with ActionScript, but LScript is different in enough places that I am doing a little digging.

    Also, I forgot to upload the files last time.

    //BEGIN CODE

    @version 2.3
    @warnings
    @script generic

    generic
    {
    objList = curScene.getSelect(MESH);

    //Creates a variable containing the object directory.
    sObjectDirectory = getdir(OBJECTSDIR);

    //Creates an array that will contain all of the objects in the scene.
    aObjectsInScene = [];

    //Go through all of the objects in the scene.
    for(i=0; i<size(aObjectsInScene); i++){

    //Create a variable for the object name as a string.
    sCurrentObject = aObjectsInScene[i];

    //Look at the object name and see if there are any colons (.
    for(k=0; k<size(sCurrentObject); k++){
    //Creates a variable for the current character.
    sCurrentCharacter = strsub(sCurrentObject, 1, k);
    //If the current character is a colon, replace it with an underscore.
    if(sCurrentCharacter == {
    //Replace any colon with an underscore (_).
    strsub(sCurrentObject, 1, k) = "_";
    }

    //Add ".lwo" to the end of the string.
    sCurrentObject += sCurrentObject+".lwo";

    //Use the new object name string to search for a replacement object in the same directory.
    //Ex: If my_Object.lwo exists in the directory, then use it to replace the object named my:Object in the scene.

    }

    }

    //END CODE

    If anyone might be able to assist, it'd be appreciated.
    Attached Files Attached Files
    Adam Martin
    my portfolio
    Mac Pro 2x3Ghz Dual-Core Intel | 8 Gb RAM | OS 10.6.8 | ATI Radeon X1900 XT

  3. #3
    Not to scale BlueApple's Avatar
    Join Date
    Nov 2005
    Location
    Los Estados Unidos
    Posts
    1,026
    To clarify what I would like to do:

    I have a scene containing many, multi-layered objects. Each individual object needs to be replaced by a new single layered object.

    So if there is a scene with a multi-layered object called Cube, and the layers are RedCube and BlueCube, the scene editor displays Cube:RedCube and Cube:BlueCube.

    In my objects directory I have single-layered objects named Cube_RedCube and Cube_BlueCube. The layers are unnamed.

    I would like a script that will swap out the individual objects from the multi-layered files with their single layer counterparts.
    Adam Martin
    my portfolio
    Mac Pro 2x3Ghz Dual-Core Intel | 8 Gb RAM | OS 10.6.8 | ATI Radeon X1900 XT

  4. #4
    obfuscated SDK hacker Lightwolf's Avatar
    Join Date
    Feb 2003
    Location
    Stuttgart, Germany
    Posts
    13,659
    Quote Originally Posted by BlueApple View Post
    To clarify what I would like to do:

    I have a scene containing many, multi-layered objects. Each individual object needs to be replaced by a new single layered object.

    So if there is a scene with a multi-layered object called Cube, and the layers are RedCube and BlueCube, the scene editor displays Cube:RedCube and Cube:BlueCube.

    In my objects directory I have single-layered objects named Cube_RedCube and Cube_BlueCube. The layers are unnamed.

    I would like a script that will swap out the individual objects from the multi-layered files with their single layer counterparts.
    You should be able to load the scene into a text editor and replace all occurances of ":" with "_", that should do the trick. (A colon shouldn't really show up anywhere else in a scene file... unless you are using the OSX CFM version, since HFS+ uses a colon to separate directories in a file path).

    Cheers,
    Mike

  5. #5
    Not to scale BlueApple's Avatar
    Join Date
    Nov 2005
    Location
    Los Estados Unidos
    Posts
    1,026
    I cracked open the attached (above) test scene and here is what the object load appears to be.

    LoadObjectLayer 1 10000000 C:Documents and Settings/AMARTIN/Desktop/ObjectReplacementTest/Objects/Spheres.lwo

    This looks like it loads layer 1 from Spheres.lwo. What I would like it to load instead is layer 1 from myYellowSphere.lwo. I don't think that this can be be accomplished by doing a search and replace for the ":" with "_".
    Last edited by BlueApple; 07-17-2008 at 02:39 PM. Reason: These emoticons are killing me...
    Adam Martin
    my portfolio
    Mac Pro 2x3Ghz Dual-Core Intel | 8 Gb RAM | OS 10.6.8 | ATI Radeon X1900 XT

  6. #6
    Registered User adamredwoods's Avatar
    Join Date
    Jul 2006
    Location
    San Francisco, CA
    Posts
    2,030
    Hi. Got your PM so here's what I can add. I'm not near a copy of Lightwave, so there will be mistakes.

    First, use Mike Green's awesome Lscript HTML lookup table for help on specific commands:
    http://www.mikegreen.name/Lscript/Lscript%20Index.html


    My outstanding questions are:
    1. how to acquire all objects in a scene.
    2. how to replace an object with another.
    1. How to acquire all objects in the scene:
    Code:
    obj = Mesh(); //get first object agent
    
    // go through entire object mesh list
    while(obj) {
       ///check for valid obj mesh
      if(isMesh(obj.id))
      ...
      do stuff
      ...
      obj = obj.next();
    }
    The second one is difficult. Do we use obj replace or generic for the whole scene. Let me think...
    // To draw is to think and discover.

  7. #7
    Registered User adamredwoods's Avatar
    Join Date
    Jul 2006
    Location
    San Francisco, CA
    Posts
    2,030
    Ok I re-read the problem. My brain is reaaaal rusty today. (beer)

    in above, where there is "do stuff", we need to add code. Basically, we need to unparent if there's a parent.

    Code:
    if(obj.parent) {
       ParentItem();
    }
    It may also be ParenItem(null); but I cant checkit right now.

    Does that fulfill your requirements?
    // To draw is to think and discover.

  8. #8
    Not to scale BlueApple's Avatar
    Join Date
    Nov 2005
    Location
    Los Estados Unidos
    Posts
    1,026
    Adam and Mike:
    Thanks to both of you for your assistance. I'm working through what Adam has supplied and will update with success or failure.
    Adam Martin
    my portfolio
    Mac Pro 2x3Ghz Dual-Core Intel | 8 Gb RAM | OS 10.6.8 | ATI Radeon X1900 XT

  9. #9
    Registered User adamredwoods's Avatar
    Join Date
    Jul 2006
    Location
    San Francisco, CA
    Posts
    2,030
    I re-read again. Not so simple!

    In my objects directory I have single-layered objects named Cube_RedCube and Cube_BlueCube. The layers are unnamed.
    Well, when we unparent, we can add the name to our final filename:
    if(obj.parent) {
    finalName = obj.parent.name +"_" + obj.name;
    ParentItem();
    }
    So now clarify, do we need to swap out just the name of the object (ie, rename object) or do we need to do an actual "load and replace object"?
    Code:
    ReplaceWithObject("folder/"+finalName);
    // To draw is to think and discover.

  10. #10
    obfuscated SDK hacker Lightwolf's Avatar
    Join Date
    Feb 2003
    Location
    Stuttgart, Germany
    Posts
    13,659
    Quote Originally Posted by BlueApple View Post
    I cracked open the attached (above) test scene and here is what the object load appears to be.

    LoadObjectLayer 1 10000000 Cocuments and Settings/AMARTIN/Desktop/ObjectReplacementTest/Objects/Spheres.lwo

    This looks like it loads layer 1 from Spheres.lwo. What I would like it to load instead is layer 1 from myYellowSphere.lwo. I don't think that this can be be accomplished by doing a search and replace for the ":" with "_".
    Ah, darn it, the new scene file format.

    Allright, I had a quick look at the LScript reference, LScript Reference, Chapters 4, 5 and 6 seem to be appropriate.

    Something like this:
    mesh = Mesh(); // get first mesh
    while (mesh)
    {
    // check if the name contains a colon
    objName = mesh.name;
    // if it needs to be replaced
    SelectItem mesh.id
    ReplaceObjectLayer 1 newfilename
    mesh = mesh.next();
    }
    This is just a rough skeleton, I'm not fluent in LScript to go into any more detail, sorry.

    Cheers,
    Mike

  11. #11
    Not to scale BlueApple's Avatar
    Join Date
    Nov 2005
    Location
    Los Estados Unidos
    Posts
    1,026
    We need to actually replace objects. If you look at the assets in the above ObjectReplacementTest.zip you may see what I'm trying to do.

    My third post details what needs to happen. Basically, every object in a scene needs to be replaced. They must be replaced with single layer objects that are already residing inside of the Objects folder in the content directory.
    Adam Martin
    my portfolio
    Mac Pro 2x3Ghz Dual-Core Intel | 8 Gb RAM | OS 10.6.8 | ATI Radeon X1900 XT

  12. #12
    obfuscated SDK hacker Lightwolf's Avatar
    Join Date
    Feb 2003
    Location
    Stuttgart, Germany
    Posts
    13,659
    Quote Originally Posted by BlueApple View Post
    My third post details what needs to happen. Basically, every object in a scene needs to be replaced. They must be replaced with single layer objects that are already residing inside of the Objects folder in the content directory.
    You can use either the ReplaceObjectLayer or ReplaceWithObject command.
    I'm not sure which is better in this case.

    Cheer,s
    Mike

  13. #13
    Not to scale BlueApple's Avatar
    Join Date
    Nov 2005
    Location
    Los Estados Unidos
    Posts
    1,026
    Mike,

    True, ReplaceObjectLayer could work, it's just that this is something we need to do a lot with scenes containing hundreds of assets from different multi-layered objects. If this can be automated it'd be a big help. But I've already eaten up plenty of your time so if you want to move on to other things I won't be offended

    Time to dig deeper into the documents...
    Adam Martin
    my portfolio
    Mac Pro 2x3Ghz Dual-Core Intel | 8 Gb RAM | OS 10.6.8 | ATI Radeon X1900 XT

  14. #14
    Registered User adamredwoods's Avatar
    Join Date
    Jul 2006
    Location
    San Francisco, CA
    Posts
    2,030
    Code:
    @version 2.3
    @warnings
    @script generic
    
    generic
    {
    obj = Mesh(); //get first object agent
    
    // go through entire object mesh list
    while(obj) {
       ///check for valid obj mesh
      if(isMesh(obj.id)) {
        if(obj.parent) {
          finalName = obj.parent.name +"_" + obj.name;
           ParentItem(); //de-parent to remove the colon
           ReplaceWithObject(finalName); //replace object
         }
       }
      obj = obj.next();
    }
    }
    If replace with object isn't finding the filename, you may need to add the directory structure before it.
    // To draw is to think and discover.

  15. #15
    obfuscated SDK hacker Lightwolf's Avatar
    Join Date
    Feb 2003
    Location
    Stuttgart, Germany
    Posts
    13,659
    Quote Originally Posted by adamredwoods View Post
    Code:
          finalName = obj.parent.name +"_" + obj.name;
    *puzzled* What are you getting the name of the parent item in the Layout hierarchy for?

    Cheers,
    Mike

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •