Page 1 of 2 12 LastLast
Results 1 to 15 of 21

Thread: Get Layer number from Layout

  1. #1
    Super Member nickdigital's Avatar
    Join Date
    Nov 2006
    Location
    Burbank, California USA
    Posts
    4,576

    Get Layer number from Layout

    ReplaceObjectLayer expects the layer number for the first argument. So how do I get that information from Layout?

    ReplaceObjectLayer(<layer number>,<filename>);
    Replace the current selected object layer with the layer chosen from the file.
    My opinions and comments do not represent those of my employer.
    Profile piece
    2010 Reel
    'The X's' Reel

  2. #2
    Super Member nickdigital's Avatar
    Join Date
    Nov 2006
    Location
    Burbank, California USA
    Posts
    4,576
    It looks like there's a solution in here:
    http://forums.newtek.com/showthread....l=1#post328292

    Seems inelegant but it works.
    My opinions and comments do not represent those of my employer.
    Profile piece
    2010 Reel
    'The X's' Reel

  3. #3
    Animator / Artist Sculley's Avatar
    Join Date
    Feb 2003
    Location
    England
    Posts
    159
    Welcome to try this...

    Code:
    getlayernumber: item
    {
        if(item.totallayers == 1){return(1);}
        sTokens = parse(":",item.name);
        iLayer = 0;
        if (strleft(sTokens[2],5)=="Layer")
          {
          iLayer = integer(sTokens[2]);
          }
        else
          {
          iTotal = item.totallayers;
          for(i = 1; i <= iTotal; i++)
            {
            if(item.layerVisible(i) == 1)
              {
              if(item.layerName(i) == sTokens[2])
                {
                iLayer = i;
                break;
                }
              }
            else
              {
              iTotal++;
              }
            }
          }
      return iLayer;
    I use it in many of my scripts. For an example see http://www.teximitation.com/blog/lsc...ric_StackIt.ls

  4. #4
    Super Member nickdigital's Avatar
    Join Date
    Nov 2006
    Location
    Burbank, California USA
    Posts
    4,576
    Thanks!
    My opinions and comments do not represent those of my employer.
    Profile piece
    2010 Reel
    'The X's' Reel

  5. #5
    Hi,

    Here is a script I've made for this purpose, its made to work in any case, accept when two layers have the same name, so you should avoid this case


    Code:
    @version 2.3
    @script generic
    @name GetLayerNumber
    
    generic
    {
    	curItem = Scene().getSelect(MESH);
    	if(curItem.count()>0){
    		info(getlayernum(curItem[1]));
    	}
    	
    }
    
    getlayernum: obj
    {
    	if(obj.isNil() || obj.null) return nil;
    	
    	layercount = obj.totallayers;
    
    	if(layercount>1){
    		layerindex = 1;
    		
    		tmp = split(obj.filename);
    		nom = tmp[3];
    		testedlayers = 1;
    		found = false;
    		
    		objCleanName = obj.name;
    		if(strright(objCleanName,1)==")"){
    			tmp = parse(" ",objCleanName);
    			tmp.pack();
    			tmp.trunc();
    			cloneNumberStr = tmp[sizeof(tmp)];
    			test = cloneNumberStr.indexOf('(');
    			cloneNumber = 0;
    			if(test){
    				cloneNumberStr = strsub(cloneNumberStr,test+1,sizeof(cloneNumber) - 2).asInt();
    			}
    			cloneNumber = cloneNumberStr.asInt();
    			if(cloneNumber.asStr()!=cloneNumberStr){
    				objCleanName = obj.name;
    			}else{
    				tmp[sizeof(tmp)]=nil;
    				tmp.pack();
    				tmp.trunc();
    				objCleanName = implode(" ",tmp);
    			}
    		}
    
    		while(testedlayers <= layercount)
    		{
    			if(obj.layerName(layerindex).isNil()){
    				layername = nom+":Layer"+layerindex.asStr();
    			}else{
    				layername = nom+":"+obj.layerName(layerindex);
    			}
    
    			if(layername == objCleanName){
    				found = true;
    				break;
    			}
    			layerindex++;
    			
    			if(obj.layerVisible(layerindex)) testedlayers++;
    		}
        
    		if(found){
    			return layerindex;
    		}else{
    			return nil;
    		}
    		
    	}else{
      		return nil;
    	}
    }
    
    implode: sep,lst
    {
    	txt="";
    	for(i=1;i<=sizeof(lst);i++){
    		txt = txt + lst[i].asStr();
    		if(i<sizeof(lst)) txt = txt + sep;
    	}
    	return txt;
    }

  6. #6
    These workarounds are no longer needed since 11.5, you can now use the layerloaded method to get the current select object layer's number in Layout.

    selected = Scene().getSelect();
    layernumber = selected[1].layerloaded;

  7. #7
    Super Member nickdigital's Avatar
    Join Date
    Nov 2006
    Location
    Burbank, California USA
    Posts
    4,576
    Ah very interesting, thanks.
    My opinions and comments do not represent those of my employer.
    Profile piece
    2010 Reel
    'The X's' Reel

  8. #8
    Super Member nickdigital's Avatar
    Join Date
    Nov 2006
    Location
    Burbank, California USA
    Posts
    4,576
    Quote Originally Posted by tajino View Post
    These workarounds are no longer needed since 11.5, you can now use the layerloaded method to get the current select object layer's number in Layout.

    selected = Scene().getSelect();
    layernumber = selected[1].layerloaded;
    Tajino,

    Where did you find this information?
    My opinions and comments do not represent those of my employer.
    Profile piece
    2010 Reel
    'The X's' Reel

  9. #9
    Axes grinder- Dongle #99
    Join Date
    Jul 2003
    Location
    Seattle
    Posts
    14,740
    YES, that's a very good question: Where did you find this information?
    They only call it 'class warfare' when we fight back.
    Praise to Buddha! #resist
    Chard's Credo-"Documentation is PART of the Interface"
    Film the cops. Always FILM THE COPS. Use this app.

  10. #10
    Heffalump
    Join Date
    Feb 2003
    Location
    Away
    Posts
    3,897
    It seems to be mentioned in sdk/html/globals/objinfo.html, but not in the context of LScript...
    Inactive.

  11. #11
    Super Member nickdigital's Avatar
    Join Date
    Nov 2006
    Location
    Burbank, California USA
    Posts
    4,576
    All I can say is thank jebus for the forum.
    My opinions and comments do not represent those of my employer.
    Profile piece
    2010 Reel
    'The X's' Reel

  12. #12
    Axes grinder- Dongle #99
    Join Date
    Jul 2003
    Location
    Seattle
    Posts
    14,740
    Amen.
    They only call it 'class warfare' when we fight back.
    Praise to Buddha! #resist
    Chard's Credo-"Documentation is PART of the Interface"
    Film the cops. Always FILM THE COPS. Use this app.

  13. #13
    - - - Updated - - -

    Quote Originally Posted by nickdigital View Post
    Tajino,

    Where did you find this information?
    I posted this as a feature request not knowing it already existed, got a quick reply from Area51 at newtek dot com about this has been implemented since 11.0.3 or 11.5 not quite sure.

  14. #14
    Animator / Artist Sculley's Avatar
    Join Date
    Feb 2003
    Location
    England
    Posts
    159
    We should put in a request just to have a full list of all functions on the document so everyone knows what there are! The documents have become far too fragmented.

  15. #15
    Valiant NewTeKnight Matt's Avatar
    Join Date
    Feb 2003
    Location
    San Antonio, Texas, USA
    Posts
    13,057
    Quote Originally Posted by nickdigital View Post
    Tajino,

    Where did you find this information?
    From me, on a bug report asking to be able to do this, below is the sample code I gave.

    Looks like this command was added in 11.5


    Code:
    @version 2.2
    @warnings
    @name "Get Layer Number"
    
    generic
    {
        // Get the first selected item
        (selectedItem) = Scene().getSelect();
    
        // Nothing selected?
        if(selectedItem == nil)
        {
            info("No item selected");
            return;
        }
    
        //  Get the ID of the selected item
        selectedItemID = selectedItem.id;
    
        // Get first object
        mesh = getfirstitem(MESH);
    
        // Scan through all valid objects
        while(mesh)
        {
            // Skip Null objects
            if( (!mesh.null) )
            {
                // Does it match what was selected?
                if( mesh.id == selectedItemID )
                {
                    // Yes, so get the layer number
                    selectedLayerNumber = mesh.layerloaded;
                }
            }
    
            // Get the next mesh
            mesh = mesh.next();
        }
    
        info("Selected Item Layer Number: ", selectedLayerNumber);
    
    }
    Last edited by Matt; 11-11-2013 at 01:24 PM.
    UI / UX Designer @ NewTek
    __________________________________________________
    www.pixsim.co.uk : LightWave Video Tutorials & Tools


Page 1 of 2 12 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
  •