Add all components with same name to new group
-
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?
-
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... -
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:inblock in fill_surface'
C:/Users/jgv/AppData/Roaming/SketchUp/SketchUp 2016/SketchUp/Plugins/Fill Surface.rb:74:ineach' C:/Users/jgv/AppData/Roaming/SketchUp/SketchUp 2016/SketchUp/Plugins/Fill Surface.rb:74:infind_all'
C:/Users/jgv/AppData/Roaming/SketchUp/SketchUp 2016/SketchUp/Plugins/Fill Surface.rb:74:infill_surface' C:/Users/jgv/AppData/Roaming/SketchUp/SketchUp 2016/SketchUp/Plugins/Fill Surface.rb:12:inblock in <top (required)>'
SketchUp:1:in `call' -
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... -
I was blind, now I can see.
Thank you, TIG.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement