sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Select all comps if contain name

    Scheduled Pinned Locked Moved Plugins
    5 Posts 2 Posters 222 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.
    • CadFatherC Offline
      CadFather
      last edited by

      if this code gets all comps named 'arete'

      Sketchup.active_model.selection.add( Sketchup.active_model.definitions['Arete'].instances )
      

      how can i select ALL the comps that may contain it as well? (like Arete_1, Arete_2 etc)

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

        m=Sketchup.active_model;e=m.active_entities;s=m.selection;s.clear;a=[]; m.definitions.to_a.select{|d|d.name=~/[Aa]rete/}.each{|d|d.instances.each{|i|a<<i if i.parent.entities==e}};s.add(a)if a[0]
        

        It clears the selection first, then because it could select instances across context boundaries, thereby causing splatting issues, I use the array ' a' to select only those instances in the model.active_entities !
        The pattern-matching =~/[Aa]rete/ matches upper and lower case A, to limit it to just what's at the start use =~/^[Aa]rete/, to the end =~/[Aa]rete$/, to allow for ê or one other letter, use =~/[Aa]r.te/, or perhaps =~/[Aa]r[eê]te/

        TIG

        1 Reply Last reply Reply Quote 0
        • CadFatherC Offline
          CadFather
          last edited by

          Wow, super comprehensive, TIG - thank you.

          are you also saying that i should not be selecting comps inside other groups etc?

          suppose you wanted to swap an instance with another, across the whole model. are you risking bugsplats?

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

            Don't select anything unless you want to do something like Move/Copy...
            You could make a transient selection to swap definitions etc, but it is a spalt-danger...
            BUT if you want to simply get a 'collection' of all instances - e.g. to swap them - use this:

            m=Sketchup.active_model;a=[];m.definitions.to_a.select{|d|d.name=~/[Aa]rete/}.each{|d|a<<d.instances};a.flatten!;a.compact!;a
            

            The variable ' a' is an array containing all of the matching instances, irrespective of their context.
            Note how you need to flatten to merge the instances arrays, and on the safe-side compact to remove any nil values...

            TIG

            1 Reply Last reply Reply Quote 0
            • CadFatherC Offline
              CadFather
              last edited by

              brilliant, does more than i asked! need to study it a bit now (tax return can wait...)

              Thanks 👍

              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