sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Add all components with same name to new group

    Scheduled Pinned Locked Moved Newbie Forum
    sketchup
    5 Posts 2 Posters 576 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.
    • G Offline
      Gonvaz
      last edited by

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

        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

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

            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

              I was blind, now I can see.

              Thank you, TIG.

              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