New layer random color

what do you guys think about having this as a toggle in V6?

4 Likes

You could do this yourself today in a plugin!
First, set up an event handler to listen to the LayerTableEvent:

Rhino.RhinoDoc.LayerTableEvent += OnLayerEvent;

Then define this method:

public void OnLayerEvent(object sender, Rhino.DocObjects.Tables.LayerTableEventArgs e)
{
    if(e.EventType == Rhino.DocObjects.Tables.LayerTableEventType.Added)
    {
        Random randomGen = new Random();
        KnownColor[] names = (KnownColor[]) Enum.GetValues(typeof(KnownColor));
        KnownColor randomColorName = names[randomGen.Next(names.Length)];
        Color randomColor = Color.FromKnownColor(randomColorName);

        e.Document.Layers[e.LayerIndex].Color = randomColor;
    }
}

Attached is a GH definition which does this. As long as you have the definition open, you’ll get random colored new layers. The ‘known color’ way of getting a new random color came from so: http://stackoverflow.com/a/5805844/2179399, but there could be many ways of calculating a random color.

randomLayerColor.gh (1.8 KB)

There are many scripts and such available as it is. To have it available in plain vanilla Rhino makes it one thing less to keep track of yourself. The wish has been a popular one for a longer time and is in YT as RH-29129.

In the meanwhile, of course, there always is TestRandColor :fireworks:

Besides having a command toggle, where in the options dialog would you expect see something like this?

Here?

2 Likes

I was thinking the same…

2 Likes

I have no idea how to do what your suggesting. I might be a power user but I never got past aliases.

If you are using the Rhino WIP, just add this macro to a toolbar button:

_-RunScript (
Call Rhino.AddLayer(, Int(16777216 * Rhino.Rnd))
)

Is his sufficient?

to me adding a new button is not a great solution. My motor memory is pretty set at this point.

For the record, I now see that RH-29129 is closed and tagged as a duplicate.
I cannot find the duplicate, though. @pascal?

RH-33592 is close but will assign random colors to individual surfaces of a polysurface as well.

[off-topic - I’m searching for a YT issue where curves flip direction when zoomed into. I’m still seeing that in a file in the current WIP but cannot find the entry. I remember sending a model to McNeel (@stevebaer perhaps?) but find no trace… :flashlight:]

This is the original: RH-4978 (was hidden from public view)

1 Like

I said:

Attached is a GH definition which does this. As long as you have the definition open, you’ll get random colored new layers.

Grasshopper comes with the WIP, so run _Grasshopper, and then in Grasshopper open the file I attached.

While it is obvious that this is a long standing wish which hopefully will get some more attention soon, there are two solutions provided that will do what you ask in the short term. I’ll continue to investigate the parts necessary to do this correctly.

I just did a bunch of work in this area this week. Hopefully the curve flipping bug will go away in next week’s WIP

1 Like

there was a great plugin that no longer seems to work. That was the best alternative that I’ve seen to incorporating the functionality into native rhino. It no longer works with V6. do you have a sense of why?NewLayerRandomColor.rhp (8.5 KB)

Also, I have made many attempts to use grasshopper (it was all the rage during grad school) but for my style of work it is irrelevant. Are you guys expecting this kind of use as a regular scenario in the future? Just running it in the background to effect typical commands?

Nothing (well…) that is made to run inside RH5 will run in the WIP. As in the other thread, you’ll have to wait for Guido to update that one. Of course, then it will only run a week at a time because each time a new WIP comes out, it will have to be recompiled (unless, of course, it’s built on top of the RhinoCommon SDK).

Having a bad day at the office this morning? He’s just trying to help you out in the short run (give or take a year :stuck_out_tongue_closed_eyes: ).

what does that question have to do with my day? I don’t have an understanding of how grasshopper will incorporate in to the future product. I’m curious, not complaining.

The GH definition is working well, BTW.

Strange, this appears to be working in my version of the WIP. What kind of error message are you getting?

It will be a factory-default integrated part of Rhino. You won’t need to download and install it. Other than that it will be just like today - only to be used if you want.to. There is no intention of having it running behind the scenes to run regular commands. [I’m sure @DavidRutten et al. will be able to phrase this in a better way].