Making identical groups into a shared component.
-
I have a SpaceDesign client who would like a script to convert groups to components, but thinks it would be handy if copied groups all became the same component.
@unknownuser said:
Group Copies eg if 4 of same Group already exists, becomes 1 Component (with 4 Copies).
Any ideas how I am going to know that copies of a group are the same. This seems like a lot of work.
Or is this just a pipe dream?
-
If the group has not been edited after it's been copied then it's very easy as the group instances all share the same component definition. Selection Toys allow you to do this conversion.
When you select a group that's been copied you can see in the Entity Info window how many copies there are. If it reports more than one then you're in luck - things are easy to replace.
If the groups are considered unique then it's more trouble. I began on a script that compared groups and components based on their geometric appearance. http://forums.sketchucation.com/viewtopic.php?f=323&t=30143&p=264517
Unfortunately I've not had time to work on it and there's currently lots of bugs and limitations. (For instance, it doesn't deal with nesting.) -
Very interesting thomthom.
How to find the groups which can be made into the same component?
I do not see how to get to the "definition" of a group. (Much less how to find all the groups which use this same definition)
I see there is a .equals? operator on a group which will let me determine if two groups are identical.
So I suppose I just need to check all other top level groups to see which are identical, and then create the component, and then replace all the groups with the new component.
-
I see you have addressed the "Definition of a group" in another thread: http://forums.sketchucation.com/viewtopic.php?f=180&t=19765
It looks like I may have some luck using:
definition = group.entities.parent
to get the definition, and
definition.instances
to locate the groups which use the same definition.
My client mentioned there was already a ruby to convert groups to components. Did you write it, or do you, (or anyone), know where it is?
[Edit: It looks like I am looking for: Selection Toys. I will try to find it]
Advertisement