Remove empty items from lists

For a more Neanderthal perspective:

A mountain with 5 empty caves is still a mountain.

-Willem

4 Likes

< empty >

2 Likes

…and more Swiss cheese = more holes, but more holes = less Swiss cheese.

Go figure…

First I want to make it clear I agree with the original post…

… Second I want to show the hack I usually use: do a type check on the data. Feels more readable and self-documenting. Of course this doesn’t work if you’re working with text, unfortunately. And may be slower than the textlength one.

OK, but then why is a branch full of “Empty” items not considered as an empty branch by “Clean tree” ?

What happens is the component reads the strings . So the component just reads the branch as having data (strings saying empty or “”). Empty technically means there is nothing for the data you are looking for. But the string itself does count as data :smiley:

Grasshopper 2.0 has options on all parameters for removing null values and empty twigs*. A twig with only nulls will thus disappear if both these options are active.

This still won’t treat empty strings as null though. There is a significant difference in meaning between no data and empty data which I am not willing to plaster over. I can add components for replacing certain values with nulls, or even an extra option on just text parameters for removing empty strings.

40 seconds in:

* “branches” are called “twigs” in 2.0

4 Likes

Great work. BTW, it would be convenient if a test (=, <>, >, etc) and dispatch could be combined into a single component. Also BTW, that is great that ‘sort’ and 'randomize; are added to the component.

Like this?

18 Likes

I am awed by the beauty of the new components.

Did you actually go out of your way to take these pictures ?

Off topic, I noticed in all the gh2 teasers components have colored box icons with 2 letters. Is gh2 doing away with graphic icons and longer text names?

As the default style I’m switching to two-letter codes for input and output parameters, so that part of components will become somewhat bigger. Components also by default do not come with preset user-names. However as soon as you choose to enter one that text will be included somewhere visually, haven’t decided where or how yet, except that it won’t be vertical text.

If people want the names of components on screen, I think an approach akin to the bifocals plug-in makes more sense.

As for icons, I’m planning to provide only vector/algo icons for all native components, but I haven’t really finished the tools for easily making these. So out of necessity the icons so far are all either auto-generated or very simple. I mean… this is not exactly fun to type:

/// <summary>
/// Gets the standard lambda parameter icon.
/// </summary>
public static IIcon LambdaParameter()
{
  var shape = Que.FromVertices(
    (6, 19),
    (10.8, 7.5),
    (10.6, 6.8),
    250,
    (9.0, 5.8),
    (7, 6),
    (7, 4),
    (9.0, 3.5),
    350,
    (13, 6),
    (16.5, 16.0),
    65,
    (18, 17),
    (18, 19),
    165,
    (14, 17),
    (12, 11),
    (9, 19),
    (6, 19));

  return ParameterTemplate(shape);
}

Even if I can automate a lot of the process using GH1:

Hi!
I had the same problem today, however I did find the solution:

Did you try the good old ‘Replace members’? works perfectly!

1 Like

smart

To get rid of the entries entirely, you can use the same trick but then without supplying any value for replace.

1 Like

Hello, i followed your idea and created this cluster. It seems if always works but i’m not sure. Please take a look.
Regards


cull empty items from a list.gh (6.8 KB)

It seems you could do without Replace Memberprior to Member Index.
Using only Member Indexis probably sufficient…

4 Likes

Hello @HS_Kim yes, probably it’s better
Im trying to use this script here with metahopper, but i cant figure out.

from a script of Andrew Heumann to Hide/Show groups in a definition.
this is the situation


Hide-Show groups.gh (22.9 KB)

I want to get rid of groups without name and sort them from 1 to n
but i cant figure out a correct solution. you see here my attempt.


Hide-Show groups_pick only groups with name.gh (29.0 KB)

NOTE cull empty is a small cluster of your solution for cull empty items.

i cant understand how to pick same items (in this case 0,1,4 from the list) from the original list of groups. So i tried, writing them manually in a panel.
In any case it does not work well because, as can be seen in the element selector, no element is selected, whereas on rhino you can see the curve - group named ‘1.polyline’.

any ideas how to solve?

Something like this is what you’re trying to accomplish? I’m not sure…


Hide-Show groups_pick only groups with name_re.gh (27.9 KB)

1 Like

I’ll have a look, thank you! @HS_Kim I see some interesting components here… seems i didnt understand the potential of member index :sweat_smile:

EDIT:
I think it’s working perfectly now! although I still don’t understand the logic you used… could you explain the difference between item index and member index? maybe with an example… I’ve seen a few simple tutorials on how to use both components but maybe this is a special case