sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    šŸ«› Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    Layer0 questions

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 2 Posters 3.5k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Al HartA Offline
      Al Hart
      last edited by

      1. Is Layer0 always the first layer,

      e.g. Sketchup.active_model.layers[0].name

      1. Is the name of the default layer always "Layer0" - even in foreign versions?

      I guess this could and would change with templates.

      1. Does anyone use a template where Layer0 has a different name?

      2. It looks like you cannot change the name of Layer 0

      Sketchup.active_model.layers[0].name = "Test"

      does not change the name.
      (It does for Layer1)

      Al Hart

      http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
      IRender nXt from Render Plus

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        1. Is Layer0 always the first layer,
          Layer0 is always listed in the Layer-Browser first even when they are ordered 'alphabetically' or 'reversed' - since it is preexisting logically it ought to be the first in model.layers
          e.g. Sketchup.active_model.layers[0].name

        2. Is the name of the default layer always "Layer0" - even in foreign versions?
          I guess this could and would change with templates.
          **Layer0** is the EN name for **layer==nil**. It has other names in different locales. To find its name set **model.active_layer=nil** and then use **model.active_layer.name**. You can't rename it in a 'template' - it is just based on locale naming for **layer==nil**. You can use the fact that the default-layer is 'nil' and get it's name without knowing the locale or anything else... just set a temp-variable to remember the current **tlay=model.active_layer**, change to 'nil' [**model.active_layer=nil**], then get the **deflayname=active_layer.name** [>>> "Layer0" e.g. depending on the locale], then just reset **model.active_layer=tlay**

        3. Does anyone use a template where Layer0 has a different name?
          You can't rename Layer0 in a 'template' - it is just based on locale naming for **layer==nil**. Every non-EN locale user will have their own name for the default-layer...

        4. It looks like you cannot change the name of Layer0
          OR its equivalent name in other locales

        Sketchup.active_model.layers[0].name = "Test"
        does not change the name.
        (It does for Layer1)
        Correct. Sketchup spots if the layer is 'nil' and assigns the locale's 'default-layer' name to it - in the case of EN-US it's 'Layer0' - it is immutable...

        TIG

        1 Reply Last reply Reply Quote 0
        • Al HartA Offline
          Al Hart
          last edited by

          Wonderful answer TIG.

          I was about to use this set of code to skip the default layer:

          
          			model.layers.each do |layer|
          				# do not process Layer0
          				next if layer.name == "Layer0"
          				...
          
          

          However I had better find a different way to skip the first layer,

          However in searching for Layer0 in my Ruby code I see a number of other items which sound like they may not work.

          
          				# remember layer name unless it is a pass through
          				if (entity.layer.name != "Layer0")
          					eparms2.parent_layer = entity.layer.name
          				end#if
          
          or
          
          				model.active_layer = model.layers["Layer0"]
          
          

          The second one can easily be replaced with:

          model.active_layer = nil
          

          But the first one seems more troublesome.

          This seems a bit cumbersome:

          
          tlay = model.active_layer
          model.active_layer = nil
          deflayname = active_layer.name
          model.active_layer = tlay
          if (entity.layer.name != "Layer0")
          	eparms2.parent_layer = entity.layer.name
          end#if
          
          

          Do you have a suggestion for seeing if an entity is in the 'nil' layer.

          Al Hart

          http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
          IRender nXt from Render Plus

          1 Reply Last reply Reply Quote 0
          • Al HartA Offline
            Al Hart
            last edited by

            Which layer does model.add("Layer0") return in a foreign language version?
            (A new layer or the nil layer?)

            I presume the foreign language versions cannot create new layers called Layer0, because that would get confusing if I tried to use the model in English.

            Can someone tell me what Layer0 is called in some other language where it is different, so I can see what happens if I try to create a new layer with that name.

            Al Hart

            http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
            IRender nXt from Render Plus

            1 Reply Last reply Reply Quote 0
            • TIGT Offline
              TIG Moderator
              last edited by

              layer=model.add("Layer0") does return a reference to a layer in any locale - including EN.
              It is the same layer as model.active_layer=nil
              Setting the active layer to nil and getting its name is the foolproof way of finding the default-layer's name in that locale.
              If you are sure that layers[0] is always the default layer then using that should work too.
              Then to process all layers except the default-layer you can use
              model.layers.to_a[1..-1].each{|layer|###do process###}
              as it misses off the first one...

              TIG

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Buy SketchPlus
              Buy SUbD
              Buy WrapR
              Buy eBook
              Buy Modelur
              Buy Vertex Tools
              Buy SketchCuisine
              Buy FormFonts

              Advertisement