Counting Components
-
There can be a problem with the entity info count. The count is correct, but you may have copies on invisible layers, or, duplicate coincident copies that look as only 1, which is very difficult to find.
So if the count seems wrong, start hunting.To correct coincident copies, you need to delete a suspect. If it disappears, hit [undo]. If it remains, it was a duplicate. Do it again. In my early drawings I have had as many as 7 instances coincident, due to my inexperience then.
One very difficult situation to fix is where you have multiple copies INSIDE the group or component envelope. The only way I know of fixing that is to open the group/comp and rebuild it line by line. Deleting co-incident lines does not always work, and this condition is a major cause of faces that do not form. You have endpoints that are very close together.
-
Another way is via Window>Model Info>Statistics. Selecting "Show nested components" will show the correct figure even if you have components nested within groups and other components. The report can even be copied from the window and pasted into Excel, for instance.
Anssi
-
If you insert a group with an instance of a component inside, count_instaces method and ComponentDefinition.instances["instance"].length fails.
http://www.youtube.com/watch?v=kLAAAK2_APc
You need to enter inside the groups, then the number of instances is corrected.
¿Is there another way? -
Select one instance of the component in your model.
Paste this 'one-liner' into the Ruby Console - it should return the number of its instances correctly - including any 'nested' ones. Use the ideas to make a short script...p Sketchup.active_model.selection[0].definition.instances.length
An instance inside a definition only gets counted the once - so that requires you to then find the number of the container-instances using a similar technique, and simply multiply the numbers together...
-
@tig said:
Paste this 'one-liner' into the Ruby Console - it should return the number of its instances correctly - including any 'nested' ones.
No - it doesn't account for nested instances.
-
@thomthom said:
@tig said:
Paste this 'one-liner' into the Ruby Console - it should return the number of its instances correctly - including any 'nested' ones.
No - it doesn't account for nested instances.
Well it does for me
Make a component and say 6 copies of it.
Make a component of say 2 of them - we now have 4 in the model and 2 inside a definition.
When I run the snippet - it returns 6... NOT 4 ?
If you copy the second component the reported figure is still 6 since there are 2 in its definition.
To get the total you need to count the number of instances which nest them...
I don't see what you are saying ? It does work ??
As I thought I explained the nested ones are only counted once and you need extra steps to count up their container instances too... -
@tig said:
If you copy the second component the reported figure is still 6 since there are 2 in its definition.
To get the total you need to count the number of instances which nest them...
I don't see what you are saying ? It does work ??That's what I meant - it doesn't return the total number of instance you can see in the model when one or more of its parents also have instances.
I guess it depends on what you expect. -
In the video you can see 3 rectangles, but count_instaces only returns 1. If you click all the groups to edit them and then exit, count_instances returns the
rigth number, 3 rectangles. I think count_instances method has a bug. ¿What do you think? -
@juantxo said:
In the video you can see 3 rectangles, but count_instaces only returns 1. If you click all the groups to edit them and then exit, count_instances returns the
rigth number, 3 rectangles. I think count_instances method has a bug. ¿What do you think?No - it's not bug. It's as expected. When you copy a group you create an instance of that same group. Inernally in SU groups are like Component Instances but with the exception that when you edit (or open one) they are made unique.
In order to get the correct count you need to also count the instances of all the parents for each instance of the group you count.
-
I understand. You are the best
Thanks very much!
Advertisement