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

    Select all in layer

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 3 Posters 648 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

      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
      • TIGT Offline
        TIG Moderator
        last edited by

        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

          Thanks a lot that was helpful!

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            @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
            • First post
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement