[poss. BUG] Best-Fastest way to loop through all objects
-
Facts of our dev.
- In certain objects we store a generated ID in the data dictionary (Since the id from Sketchup changes each time you open the model)
- We have a list that contains some of those ID's
- We want to give all the objects that are in that list another color.
Now.
We have that working but it is slow, probabbly because:- We loop through all SU objects and see if their ID is listed in the list of ID's. So in some cases up to 99% of the loop is not necessary. Isn't it possible to make this faster? Instead of looping and checking each time, just like 'pick' them?
- To change the color we have a procedure:
check if the selected object is a group-entity-instance
- if entity: set material to red
- if group: go in the group and execute the procedureagain
- if instance; go in the instance and execute the procedureagain
So we like go into the element, go to it's smallest 'part' and change the color of that part.
It would off course be easy to just set the group material or instance material to red but that does not override the material of the elements in the group/instance.As you can imagine: if an instance contains a group and then another instance with 25 entities in that the loop tends to take a long time.
What is the fastest way to loop through all objects?Thx
-
from the previous procedure i think i have found a bug in SU:
setup:
- create a square and extrude it
- make a component of it
- bring another instance of the component in the model
- make a group of those two
- duplicate the group
Now when looping i have set a 'flag':
the loop- when it is a face show messagebox with 'face' in it
- when it is a group show messagebox with 'group' in it
for each entity in the group execute the loop again - when it is a instance show messagebox with 'instance' in it
for each entity in the instance definition execute the loop again
Now this give me this result:
messagebox group
messagebox instance
messagebox group (automatically goes away and immediately shows:)
messagebox instance
...Now this is not correct.
If, before i execute the loop, i just go into one of the two groups (just double click it and click next to it again) this is the result when executing the loop:
messagebox group
messagebox instance
messagebox face (6 times)
messagebox instance
...
This is correct.Is there any know bug about this? It seems SU threats the loop differtly just based upon a single 'not changing anything' action.
Can someone please verify? And maybe give some advise?
Thx!! -
There is a known bug in SU that copies of a group act like component instances unless the copies are individually edited manually, or you use group.make_unique in a script.
If you don't do one of those two things, any changes to one group will be applied to all copies of the group.
I suggest you first loop through the definitions and query each definition's instances to see if they are groups, and if so, call group.make_unique on each. This will make all groups unique and eliminate the problem.
-
Rick,
Thank you very much. Is it possible that when you just go into a group the group is also made unique?
As I understand i can do it like this:- when it is a group show messagebox with 'group' in it
execute the make_unique command
for each entity in the group execute the loop again
Correct?
Or should it be possible to handle groups and instances in one loop
like: if it is a group or instance do... - when it is a group show messagebox with 'group' in it
-
I would structure it like this:
1. loop through the definitions a. if a definition has multiple instances, i. if they are groups, make them all unique, then loop through the only remaining group's entities and paint everything that's not a group or component ii. if they are component instances, loop through the definition's entities and paint everything that's not a group or component b. if a definition has a single instance, loop through the entities (of the group if it's a group, or of the definition, if it is a component instance) and paint everything that's not a group or component 2. loop through the model.entities and paint everything that's not a group or component instance
Based on my experience with bomb.rb (which explodes all groups and components in a model), it is always faster to parse the definitions than it is to recursively parse groups and components from the entities list.
-
ah thx, will give that a try
see if it goes faster
Advertisement