• Login
sketchucation logo sketchucation
  • Login
🔌 Quick Selection | Try Didier Bur's reworked classic extension that supercharges selections in SketchUp Download

Select all in layer

Scheduled Pinned Locked Moved Developers' Forum
4 Posts 3 Posters 607 Views 3 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.
  • T Offline
    T.M
    last edited by 27 Oct 2011, 13:30

    Hi everyone,

    I was wondering if it was possible to select all objects in a given layer in code, without having to pre-select an object in the same layer?

    I know it's possible through various plugins to add to the selection all the objects that are in the same layer as the selected one, but I would like to do it without having to make this pre-selection.

    Thanks for your help!

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 27 Oct 2011, 13:38

      All you need is a reference to the required layer - that's all you get from the preselected object with layer=object.layer in any case.
      So if you know its name (e.g. "MyLayer") then you can use xlayer=Sketchup.active_model.layers["MyLayer"].
      Now you can select all active entities that share that layer with
      Sketchup.active_model.selection.clear Sketchup.active_model.active_entities.each{|e|Sketchup.active_model.selection.add(e) if e.layer==xlayer}
      or alternatively do it by layer name directly [comparing strings is probably slower]
      Sketchup.active_model.selection.clear Sketchup.active_model.active_entities.each{|e|Sketchup.active_model.selection.add(e) if e.layer.name=="MyLayer"}
      etc etc...

      TIG

      1 Reply Last reply Reply Quote 0
      • T Offline
        T.M
        last edited by 31 Oct 2011, 10:28

        Thanks a lot that was helpful!

        1 Reply Last reply Reply Quote 0
        • T Offline
          thomthom
          last edited by 31 Oct 2011, 12:22

          @tig said:

          comparing strings is probably slower

          It is. Much slower! At all times avoid string comparisons if possible.

          Thomas Thomassen — SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

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

          Advertisement