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

Add all components with same name to new group

Scheduled Pinned Locked Moved Newbie Forum
sketchup
5 Posts 2 Posters 576 Views
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.
  • G Offline
    Gonvaz
    last edited by 29 Nov 2016, 13:43

    I've created some components that have the same name and I'd like to group them.

    I tried this:

    **mod = Sketchup.active_model
    @ent = mod.active_entities
    ...

    comps = Sketchup.active_model.definitions[@C_name]
    new_group = @ent.add_group comps
    new_group.name = "Layout**"

    But I'm doing something wrong (the group isn't created). Could you help me?

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 29 Nov 2016, 15:26

      set up a pattern match:
      name=/^xxx/
      That matches everything starting with 'xxx'
      Then find all matching definition:
      comps = mod.definitions.find_all{|d| d.name=~name }
      Now you have an array of matching definitions by name-match.
      Process the active_entities to find all matching instances
      ins = mod.active_entities.find_all{|e| compos.include?(e.definition) }
      You now have an array of all matching instances.
      new_group = mod.active_entities.add_group(ins) new_group.name = "Layout"
      You now have a new group made from the instances.
      Note the instances must all be in the active_context...

      TIG

      1 Reply Last reply Reply Quote 0
      • G Offline
        Gonvaz
        last edited by 29 Nov 2016, 16:11

        Thanks, TIG but...

           name=/^20x/
           comps = mod.definitions.find_all{|d| d.name=~name} 			
        

        74 ins = mod.active_entities.find_all{|e| comps.include?(e.definition)}
        new_group = mod.active_entities.add_group(ins)
        new_group.name = "Layout"

        Returns:

        Error: #<NoMethodError: undefined method definition' for #<Sketchup::Edge:0x0000000f893280>> C:/Users/jgv/AppData/Roaming/SketchUp/SketchUp 2016/SketchUp/Plugins/Fill Surface.rb:74:in block in fill_surface'
        C:/Users/jgv/AppData/Roaming/SketchUp/SketchUp 2016/SketchUp/Plugins/Fill Surface.rb:74:in each' C:/Users/jgv/AppData/Roaming/SketchUp/SketchUp 2016/SketchUp/Plugins/Fill Surface.rb:74:in find_all'
        C:/Users/jgv/AppData/Roaming/SketchUp/SketchUp 2016/SketchUp/Plugins/Fill Surface.rb:74:in fill_surface' C:/Users/jgv/AppData/Roaming/SketchUp/SketchUp 2016/SketchUp/Plugins/Fill Surface.rb:12:in block in <top (required)>'
        SketchUp:1:in `call'

        1 Reply Last reply Reply Quote 0
        • T Offline
          TIG Moderator
          last edited by 29 Nov 2016, 17:11

          Sorry, I assumed the active_entities only contained instances.
          Here's a way to filter for just instances...
          ins = mod.active_entities**.grep(Sketchup::ComponentInstance)**.find_all{|e| comps.include?(e.definition)}
          Substitute this line for the similar line in the code...

          TIG

          1 Reply Last reply Reply Quote 0
          • G Offline
            Gonvaz
            last edited by 30 Nov 2016, 07:36

            I was blind, now I can see.

            Thank you, TIG.

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

            Advertisement