algorithmic modeling for Rhino
Hi everyone,
What i try to achieve is quite straightforward.
I want to compute the number of objects within a selected layer in Rhino.
The only way i found to do so is the following:
len(Rhino.RhinoDoc.ActiveDoc.Objects.FindByLayer("layerName"))
It is kind of stupid and not very elegant since it computes actually the objects themselves (which I don't need)
If my rhino file is very big, and for example, i want to find out what is the max number of objects contained in one of the layers of my layer table, I would have to do the following:
layers = Rhino.RhinoDoc.ActiveDoc.Layers
layerSizes = []
for l in layers:
layerSizes.append(len(Rhino.RhinoDoc.ActiveDoc.Objects.FindByLayer(l)))
print max(layerSizes)
Which is very expensive...
Did I miss something in the Layer class?
.ActiveCount only allows you to get the number of layers within the Rhino file.
Any help would be appreciated,
Thanks
Paul
Tags:
It'll probably be slightly faster to call ObjectCount, since you don't have to get the actual objects. Still pretty slow with a lot of objects though:
Also note the many ObjectEnumeratorSettings, they can be a bit confusing, certainly were for me :)
Thank you! Always here when it comes to python :)
It saves already quite some time indeed.
However if you open the smallest rhino file they have here at D2P, it will still take a few seconds to compute... I think I will post something on discourse then.
Hehe, I'd like to think it was more of a RhinoCommon thing, but yes ;)
Whoo, that sounds like a pretty terrifying file! Perhaps it makes sense to try out a compiled C# version first that calls the same method and see how that plays out. That said, I'm thinking that this might be inherently costly, since one will have to enumerate the objects at some point. It'll be interesting to hear what the Rhino devs say.
Thanks for your input Dimitrie!
I am not very familiar with VB and the Enumerable class but I think I got your approach, which i sort of replicated here (or maybe that's not even close from what you wrote).
Anyway it works quite well and it's much faster than the precedent versions!
@Anders, I realized that the result of your script differed a bit from the first version I posted because it dismissed the invisible/hidden objects, which I had to specify here with ObjectEnumeratorSettings.
@Dimitrie: oops I meant C#. Just tried it. works like a charm :)
Sorry for the late reply polpo, i don't get notifications on this one! But, yeah, it seems you got it.
try this, dunno if it's faster:
```cs
int[] layerCounts = Enumerable.Repeat(0, Rhino.RhinoDoc.ActiveDoc.Layers.Count - 1).ToArray();
foreach(var obj in Rhino.RhinoDoc.ActiveDoc.Objects)
layerCounts[obj.Attributes.LayerIndex]++;
A = layerCounts;
```
ffs, code formatting ftw: https://gist.github.com/didimitrie/456417eb838d6760458d79d76e9ad41f
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by