[Closed] Efficient coding
Hi everyone,
I am working on a script which works just fine but with a limited amount of objects.
They key command line is the following:
for obj in objects do ( if obj.pos.z > -200 do selectmore obj)
Since my scenes can have 10K+ objects as soon as execute this command line on such a huge scene this operation can easily take 1h+
Since the goal is simply to select all the object with z coordinate above a certain value does somebody know a way to achieve the same result in a different/more efficient way?
If I perform the same action manually with my mouse it doesn’t take more than a few sec…
Thank you very much in advance! :keenly:
- DGN
The manual equivalent of your code is to select the objects one by one with Ctrl pressed
we discussed why ‘selectmore’ is slow on this forum and what a workaround.
the right way is to collect all targets (objects that match the condition) and select them at once:
select (for obj in objects where obj.pos.z < 200 collect obj)
it will take almost nothing for any scene
@ DenisT:
thanks a lot for the prompt reply. I tested it and as you say it makes a world of difference!
@ lo:
you couldn’t be more clear with your example and I guess it will help me not to do it again
Thanks!
- DGN