How to add entities inside a group?
-
Well, title says all... I can't figure out how to add entities (component instances) inside a group that I already have created. It contains some entities, but I want to be able to add more things inside it, using a ruby script.
And one more thing that bothers me: when I initially made the group I did it like this:... group = model.active_entities.add_group entities_array group.name = nameBut, the problem is that I gave a name just to the group entity and since
group.definition.nameis not a valid method, I'm stuck. Why I need to give same name to the definition as the entity? Because when/if I use right-click -> Make Component, the new created component instance will take definition's name.Thank you.
-
You get a groups definition by
group.entities.parent
But, there's a bug in SU where that reference some times get mixed up with the wrong definition.I use this snippet to get groups definitions:
def self.get_real_group_parent(group) if group.entities.parent.instances.include?(group) return group.entities.parent else Sketchup.active_model.definitions.each { |definition| return definition if definition.instances.include?(group) } end return nil # error end -
To add entities to a group:
group.entities.add_face(...) -
@newone said:
Well, title says all... I can't figure out how to add entities (component instances) inside a group that I already have created. It contains some entities, but I want to be able to add more things inside it, using a ruby script.
And one more thing that bothers me: when I initially made the group I did it like this:> ... > group = model.active_entities.add_group entities_array > group.name = name >But, the problem is that I gave a name just to the group entity and since
group.definition.nameis not a valid method, I'm stuck. Why I need to give same name to the definition as the entity? Because when/if I use right-click -> Make Component, the new created component instance will take definition's name.Thank you.
Last things first...
name=group.name inst=group.to_component defn=inst.definition defn.name=name ### done !To add to ANY entities - including those of a group or definition...
ents=group.entities tr=Geom;;Transformation.new(point) ents.add_instance(defn,tr) -
thanks thomthom, can I borrow your snippet for what I need?
It shows very useful! -
Go ahead!
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