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

    Select instances in the selection

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 2 Posters 1.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.
    • TNTDAVIDT Offline
      TNTDAVID
      last edited by

      **Hello everybody, ☀

      With the code below, it is possible to select an instance in SketchUp by ca definition.

      m=Sketchup.active_model;s=m.selection;m.definitions.each{|d|s.add d.instances if d.name=~/#{"Handle"}/}
      

      Is it possible to select the instances "Handle # 1", "Handle # 2", "Handle # 3" etc. which are only in the furniture being selected?

      If so how do I do it?

      Thank you in advance for your help.

      David**

      [b:8wt9py2i]* Nouveau !!![/b:8wt9py2i] Découvrez notre nouveau Plugin [url=http://www.composant-dynamique.com/:8wt9py2i][color=#40FF00:8wt9py2i]C[/color:8wt9py2i][color=#77FF00:8wt9py2i]l[/color:8wt9py2i][color=#ADFF00:8wt9py2i]i[/color:8wt9py2i][color=#E4FF00:8wt9py2i]c[/color:8wt9py2i][color=#FFDB09:8wt9py2i]k[/color:8wt9py2i][color=#FF921B:8wt9py2i]-[/color:8wt9py2i][color=#FF492E:8wt9py2i]C[/color:8wt9py2i][color=#FF0040:8wt9py2i]u[/color:8wt9py2i][color=#ED2577:8wt9py2i]i[/color:8wt9py2i][color=#DA49AD:8wt9py2i]s[/color:8wt9py2i][color=#C86EE4:8wt9py2i]i[/color:8wt9py2i][color=#AD77FF:8wt9py2i]n[/color:8wt9py2i][color=#8965FF:8wt9py2i]e[/color:8wt9py2i] [color=#4040FF:8wt9py2i]2[/color:8wt9py2i][/url:8wt9py2i], pour créer vos cuisines 3D !

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        There are some code examples here:

        Link Preview Image
        Selecting Specific Entity, Group or Component (By Name)

        Not sure if it is on the ruby end or if can be done in c. Is there a way to find a specific component in a model by its definition? Also this is from the ruby api. If [0] assumes the first entity, is there a way to get …

        favicon

        SketchUp Community (forums.sketchup.com)

        These examples use the == but you can use regular expressions:
        http://ruby-doc.org/core-2.0.0/Regexp.html

        begins with: =~ /\A#{name}/

        Or the specific string "Handle" at start of string followed by: an optional whitespace character, underscore or dash; followed by a literal pound sign (which I escape just in case);
        followed by an optional whitespace character; followed by one or more digit characters; just before the end of the string:
        =~ /\AHandle(\s|-|_)?\#\s?\d+\z/
        ... and to make it non-case insensitive we can add a "i" switch at the end outside the slashes:
        =~ /\AHandle(\s|-|_)?\#\s?\d+\z/i


        If you are using Ruby 2.0 or higher you can also use the String#start_with?() method:
        http://ruby-doc.org/core-2.0.0/String.html#method-i-start_with-3F

        inst.name.start_with?('Handle')
        ... or for case insensitive convert to a title:
        inst.name.capitalize.start_with?('Handle')

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • TNTDAVIDT Offline
          TNTDAVID
          last edited by

          **Thank you for all these Dan examples.

          = ~ / # {"name"} /

          It's perfect because it works for all instances.

          Now, I only want to select the instances present in a selection of components.

          The problem is that the code below, selects all the instances in the SketchUp file.

          m=Sketchup.active_model;s=m.selection;m.definitions.each{|d|s.add d.instances if d.name=~/#{"Handle"}/}
          

          Thank you**

          [b:8wt9py2i]* Nouveau !!![/b:8wt9py2i] Découvrez notre nouveau Plugin [url=http://www.composant-dynamique.com/:8wt9py2i][color=#40FF00:8wt9py2i]C[/color:8wt9py2i][color=#77FF00:8wt9py2i]l[/color:8wt9py2i][color=#ADFF00:8wt9py2i]i[/color:8wt9py2i][color=#E4FF00:8wt9py2i]c[/color:8wt9py2i][color=#FFDB09:8wt9py2i]k[/color:8wt9py2i][color=#FF921B:8wt9py2i]-[/color:8wt9py2i][color=#FF492E:8wt9py2i]C[/color:8wt9py2i][color=#FF0040:8wt9py2i]u[/color:8wt9py2i][color=#ED2577:8wt9py2i]i[/color:8wt9py2i][color=#DA49AD:8wt9py2i]s[/color:8wt9py2i][color=#C86EE4:8wt9py2i]i[/color:8wt9py2i][color=#AD77FF:8wt9py2i]n[/color:8wt9py2i][color=#8965FF:8wt9py2i]e[/color:8wt9py2i] [color=#4040FF:8wt9py2i]2[/color:8wt9py2i][/url:8wt9py2i], pour créer vos cuisines 3D !

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            @tntdavid said:

            Now, I only want to select the instances present in a selection of components.

            Then use the grep method that TIG showed you to collect all instances in the selection set.
            http://sketchucation.com/forums/viewtopic.php?f=180&t=68172&p=626519#p626479

            Then build an array of definitions for those instances.

            Then unique the array so that each definition reference appears only once in the array. (Or use a set.)

            (And read the several examples in the SketchUp forum thread I pointed to above.)

            @dan rathbun said:

            There are some code examples here:
            https://forums.sketchup.com/t/selecting-specific-entity-group-or-component-by-name/11469

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • TNTDAVIDT Offline
              TNTDAVID
              last edited by

              Thank you Dan.
              I will analyze all your information in detail. 😉

              [b:8wt9py2i]* Nouveau !!![/b:8wt9py2i] Découvrez notre nouveau Plugin [url=http://www.composant-dynamique.com/:8wt9py2i][color=#40FF00:8wt9py2i]C[/color:8wt9py2i][color=#77FF00:8wt9py2i]l[/color:8wt9py2i][color=#ADFF00:8wt9py2i]i[/color:8wt9py2i][color=#E4FF00:8wt9py2i]c[/color:8wt9py2i][color=#FFDB09:8wt9py2i]k[/color:8wt9py2i][color=#FF921B:8wt9py2i]-[/color:8wt9py2i][color=#FF492E:8wt9py2i]C[/color:8wt9py2i][color=#FF0040:8wt9py2i]u[/color:8wt9py2i][color=#ED2577:8wt9py2i]i[/color:8wt9py2i][color=#DA49AD:8wt9py2i]s[/color:8wt9py2i][color=#C86EE4:8wt9py2i]i[/color:8wt9py2i][color=#AD77FF:8wt9py2i]n[/color:8wt9py2i][color=#8965FF:8wt9py2i]e[/color:8wt9py2i] [color=#4040FF:8wt9py2i]2[/color:8wt9py2i][/url:8wt9py2i], pour créer vos cuisines 3D !

              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