Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17

Thread: get layer number of selected object?

  1. #16
    Member
    Join Date
    May 2006
    Location
    France
    Posts
    4,172
    If you are sure never layers have the same name in an loaded object,
    there is a way to know the layer integer in both case (named or not):

    @version 2.6
    @warnings
    @script generic

    generic
    {

    scene = getfirstitem(SCENE);

    obj = scene.firstSelect();

    while(obj)
    {
    tokens = parse(":",obj.name);
    layint = 0;

    if (strleft(tokens[2],5)=="Layer")
    {
    ltokens = parse("r",tokens[2]);
    layint = integer(tokens[2]);
    info(obj.name," layer integer is ",layint);
    break;
    }
    else
    {
    for(i=1; i<=obj.totallayers;i++)
    {
    if(obj.layerVisible(i)==1)
    {

    if(obj.layerName(i)==tokens[2])
    {
    layint = i;
    info(obj.name," layer integer is",layint);
    break;
    }
    }
    }
    }


    obj = scene.nextSelect();
    }

    }

    Denis.

  2. #17
    Hi,

    Nice one, I managed to do something similar and got something way more complicated
    Anyway there is a little bug in this function (I had the same problem in mine) : if an object has some empty layers between the first and the last used, obj.totallayers will return the number of visible layers and not the numebr of the last visible layer, so if last layers have names, the function cannot return the the right layer num, here is a fix :

    @version 2.6
    @warnings
    @script generic

    generic
    {

    scene = getfirstitem(SCENE);

    obj = scene.firstSelect();

    while(obj){

    info(obj.name," layer integer is ",getLayerNum(obj));

    obj = scene.nextSelect();
    }
    }


    getLayerNum: obj
    {

    tokens = parse(":",obj.name);
    layint = 0;

    if (strleft(tokens[2],5)=="Layer"){
    ltokens = parse("r",tokens[2]);
    layint = integer(tokens[2]);
    }else{
    total = obj.totallayers;
    for(i=1; i<=total; i++){
    if(obj.layerVisible(i)==1){
    if(obj.layerName(i)==tokens[2]){
    layint = i;
    break;
    }
    }else{
    total++;
    }
    }
    }
    return layint;
    }

Page 2 of 2 FirstFirst 12

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
  •