Hello fellow grasshoppernians,
I come to you with a puzzling bug. I created a component for sorting my layers under parent layers when triggering a C# component. The first time you run it in a new document seem to make all your layers disappear, but if you “CTRL+Z” in rhino and run a second time the component, it seems to work. I do not understand what might be causing this and haven’t seen anything similar on the forums. If anyone knows something I don’t I would appreciate the input.
Here is a small video that shows what I am trying to describe.
And if you guys want to give it a try just open a new rhino with some layers and run the following component.
SortLayers.gh (3.9 KB)
If you guys don’t want to open the files and just want the code, here it is (the formatBool input is a trigger).
private void RunScript(bool formatBool)
{
//End Script if Input is False
if (formatBool == false){ return; }//Set and Declare Name for New Layer string layerDefault = "0| Default"; string layerABP = "1| ABP"; string layerProyecto = "2| Proyecto"; //Create Layers if Non-Existent if (RhinoDoc.ActiveDoc.Layers.FindName(layerProyecto) == null) { this.RhinoDocument.Layers.Add(layerProyecto, Color.Blue); } if (RhinoDoc.ActiveDoc.Layers.FindName(layerABP) == null) { this.RhinoDocument.Layers.Add(layerABP, Color.DarkBlue); } if (RhinoDoc.ActiveDoc.Layers.FindName(layerDefault) == null) { this.RhinoDocument.Layers.Add(layerDefault, Color.Blue); } //Get GUID of parent layer. Guid parentLayerGUIDparentLayerGUID = this.RhinoDocument.Layers.FindName(layerProyecto).Id; for (int i = 0; i < this.RhinoDocument.Layers.ActiveCount; i++) { //Declare and Set current layer in loop. Layer iLayer = this.RhinoDocument.Layers[i]; // Move previously created Layers to designated layer. if (iLayer.Name != layerDefault || iLayer.Name != layerABP || iLayer.Name != layerProyecto) { iLayer.ParentLayerId = parentLayerGUIDparentLayerGUID; } }