Grasshopper

algorithmic modeling for Rhino

Hi everyone,

does anyone around here happen to know of a way to disable the preview of (all) components that are currently not (or won't ever be) outputting geometry?
The question first arose when I disabled the preview of a ListLength component for the Nth time (where N is quite a large number...), but I think it would be handy for other components too.
 
I meant to: try to GH_Convert.ToGeometricGoo() all data (as a first attempt), and disable the preview for components where the conversion fails (for example because it's just integers, or some doubles, booleans, colors, ID's, matrices a.s.o.),
but I got stuck before getting to that: I don't know how to access the output of the components on the canvas.
I can get the type of the outputs, but that's not sufficient to decide what components' preview to disable (i.e. what to do when output type is Param_GenericObject is ambiguous).

Could someone help me, or point me in the right direction please (if this is at all possible)?

Kind regards, Pieter

Views: 1009

Replies to This Discussion

what does this accomplish, though? the list length component isn't going to slow you down if its preview is enabled, is it?

Thanks for your response Andrew, it's not about speeding up calculations, it's about easier 'readability' and neatness (my ocd, you may have noticed). I never understood why some components have the isPreviewCapable property set to True when there is nothing (ever) to preview, like for instance the mentioned ListLength.
My personal preference is to disable the components that don't output (or take in for that matter) geometry, that's all, and I'm trying to have that behaviour automated somehow. Because of Human and Metahopper I guess you're the man to ask:) Do you think/know my goal is achievable?

Kind regards, Pieter

I personally think that's silly! BUT here you go anyway :-p

GrasshopperDocument.ActiveObjects()
.OfType<IGH_Component>()
.Where(
comp => comp.Params.Output
.SelectMany(p => p.VolatileData.AllData(true))
.All(d => !(d is IGH_PreviewData))
).ToList()
.ForEach(comp => comp.Hidden = true);

apologies if my long linq statement isn't super readable. To break it down:

1. get all the active objects in the document

2. get all the active objects that are components

3. get all the components where all the volatile data in all their outputs is not preview-capable

3. for each such component, set it to hidden.

I'm really greatful for that really cool code and your explanation Andrew! Yay!
n.m.: Did you mean my intended approach is silly, or did you mean that my goal is?

The goal :D :D :D Just my opinion. Everyone is entitled to their own OCD!

Ah, I thought you were going to say "both" :)

No really: thank you! Have a great weekend Andrew.

I never did understand how anyone with even the mildest form of OCD could possibly stomach LINQ statements...

:) I'm just happy that the code is working right out of the box, of coarse I'm going to see what I can learn from it and how I can vanillafy it.

vanillified:

var activeObjects = GrasshopperDocument.ActiveObjects();

foreach(IGH_ActiveObject ao in activeObjects){
var comp = ao as IGH_Component;
if(comp != null){
var outputs = comp.Params.Output;
bool hasAnyPreviewData = false;
foreach(var param in outputs){
foreach(var data in param.VolatileData.AllData(true)){
if(data is IGH_PreviewData) {
hasAnyPreviewData = true;
break;
}
}
if(hasAnyPreviewData) break;
}
if(!hasAnyPreviewData){
comp.Hidden = true;
}
}
}

personally I think the first one is conceptually much clearer! There also may well be a prettier vanilla ¯\_(ツ)_/¯

Yeah tastes definitely differ. Lots of people seem to like Linq and unfortunately many, many algorithms online seem to use it.

Yours is at least relatively readable, often times the legibility of a Linq statement seems to approach Regex levels of nope.

I may come around though, I've started liking careful use of lambdas and anonymous statements over the past few months.

List Length has a Generic input, which, if it contains previewable data that didn't come from elsewhere will preview. Any component which could potentially draw a preview has preview enabled by default.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service