A Python strategy to iterate through objects?

I seem to be stuck on what is probably a basic concept. I have attached a file that shows 5 items. There appears to be 3 because 2 of the items are “duplicates” of the others, although not in a strict enough sense to let the SelDup command find them.

Is there a strategy using Python to iterate through the details and find those that match, perhaps by volume in the case of a closed polysurface? It’s the iteration part that I need guidance on.

Thanks,

Dan

Objects.3dm (163.9 KB)

I trust that you mean you need guidance on the “find those that match” part rather than the “iterate through the details” part? The iteration part is pretty standard stuff, although I suppose there could be some discussion of the pros and cons of various data structures for your purpose.

(Just trying to clarify the question; I don’t think I’m smart enough to offer anything toward the answer.)

Yes, a process that checks which of the details matches. I find scenarios like this come up now and then, and I suspect there is a “proper” way to do this.

Hi Dan,

If you mean, what type of “loop” or algorithm to use here, for the volume property, one idea to efficiently search though that “list” might be to first order items by the property you want to control (volume), and then iterate the list while just checking the few items “afterwards”, till the tolerance rules them out. This method only works well in 1D.

Other, more involved, methods, going higher in dimensions, might include Space partitioning, like BSP trees, or assigning items to bounding trees. In some cases, Sweep and Prune might help, too.
Does it help?

Giulio

Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Hi Giulio,

Thanks for those links. I have some reading to do!

Dan

Good advice. I’m going to do the suggested reading too.

One thing to keep in mind is that the “ordering” then “searching” approach is two passes through the data. I suspect that there is probably an efficiency tradeoff based on how large the data set is, when compared with just brute-force search without the pre-ordering.