Пример #1
0
        //레이어 검정 => 하양
        public static void LayerColorChange(RhinoDoc doc, Color layercolor)
        {
            Color defaultcolor = Color.Gold;
            Color tempcolor    = Color.Black;

            if (layercolor == Color.Black)
            {
                tempcolor = Color.White;
            }


            var matching_layers = (from layer in doc.Layers
                                   where layer.Color == layercolor
                                   select layer).ToList <Rhino.DocObjects.Layer>();

            Rhino.DocObjects.Layer layer_to_change = null;
            if (matching_layers.Count == 0)
            {
                RhinoApp.WriteLine("Layer" + layercolor.ToKnownColor() + "does not exist.");
            }


            else if (matching_layers.Count > 0)
            {
                for (int i = 0; i < matching_layers.Count; i++)
                {
                    if (matching_layers[i].Name == "Default")
                    {
                        matching_layers[i].Color = Color.Gold;
                        matching_layers[i].CommitChanges();
                        continue;
                    }



                    layer_to_change = matching_layers[i];

                    var obj = doc.Objects.FindByLayer(layer_to_change);

                    foreach (Rhino.DocObjects.RhinoObject c in obj)
                    {
                        if (c.Attributes.ColorSource == Rhino.DocObjects.ObjectColorSource.ColorFromLayer)
                        {
                            continue;
                        }
                        c.Attributes.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromLayer;
                        c.CommitChanges();
                    }


                    layer_to_change.Color = tempcolor;
                    layer_to_change.CommitChanges();
                }
            }
        }
Пример #2
0
        public static void CreateLayers()
        {
            #region Root Layer
            Rhino.DocObjects.Layer RNN_Layer;
            int root_index = doc.Layers.Find("RhinoNatNet", false);
            if (root_index < 0)
            {
                //Rhino.RhinoApp.WriteLine("Couldn't find RhinoNatNet layer.");
                RNN_Layer       = new Rhino.DocObjects.Layer();
                RNN_Layer.Name  = "RhinoNatNet";
                RNN_Layer.Color = System.Drawing.Color.DarkRed;

                root_index = doc.Layers.Add(RNN_Layer);
                RNN_Layer.CommitChanges();
            }
            //RNN_Layer = doc.Layers[root_index];
            #endregion

            #region Marker Layer
            Rhino.DocObjects.Layer RNN_Markers_Layer;

            int index = doc.Layers.Find("RNN_Markers", true);
            if (index < 0)
            {
                RNN_Markers_Layer               = new Rhino.DocObjects.Layer();
                RNN_Markers_Layer.Name          = "RNN_Markers";
                RNN_Markers_Layer.ParentLayerId = doc.Layers[root_index].Id;
                RNN_Markers_Layer.Color         = System.Drawing.Color.Lime;

                index = doc.Layers.Add(RNN_Markers_Layer);
            }
            doc.Layers[index].ParentLayerId = doc.Layers[root_index].Id;
            doc.Layers[index].CommitChanges();

            //RNN_Markers_Layer = doc.Layers[index];
            #endregion

            #region Geometry Layer
            Rhino.DocObjects.Layer RNN_Geo_Layer;

            index = doc.Layers.Find("RNN_Geometry", true);
            if (index < 0)
            {
                RNN_Geo_Layer               = new Rhino.DocObjects.Layer();
                RNN_Geo_Layer.Name          = "RNN_Geometry";
                RNN_Geo_Layer.ParentLayerId = doc.Layers[root_index].Id;
                RNN_Geo_Layer.Color         = System.Drawing.Color.DarkRed;

                index = doc.Layers.Add(RNN_Geo_Layer);
            }
            //RNN_Geo_Layer = doc.Layers[index];
            #endregion
        }
        /*
         * public static int[] getLayerCounts()
         * {
         *  Rhino.DocObjects.ObjectEnumeratorSettings objEnum = new Rhino.DocObjects.ObjectEnumeratorSettings
         *  {
         *      VisibleFilter = false,
         *      IncludeLights = true,
         *      IncludeGrips = true,
         *      NormalObjects = true,
         *      LockedObjects = true,
         *      HiddenObjects = true
         *  };
         *  var allObjectsInDoc = Rhino.RhinoDoc.ActiveDoc.Objects.GetObjectList(objEnum);
         *  int[] layerCounts = Enumerable.Repeat(0, Rhino.RhinoDoc.ActiveDoc.Layers.Count).ToArray();
         *  foreach (var obj in allObjectsInDoc)
         *  {
         *      layerCounts[obj.Attributes.LayerIndex]++;
         *  }
         *  return layerCounts;
         * }*/


        private void makeLayerVisible(Rhino.DocObjects.Layer lay)
        {
            Rhino.DocObjects.Layer layer1   = lay;
            List <Guid>            guidList = new List <Guid>();

            while (true)
            {
                guidList.Add(layer1.Id);
                if (!(layer1.ParentLayerId == Guid.Empty))
                {
                    layer1 = Rhino.RhinoDoc.ActiveDoc.Layers[(Rhino.RhinoDoc.ActiveDoc.Layers.Find(layer1.ParentLayerId, true))];
                }
                else
                {
                    break;
                }
            }
            for (int index = guidList.Count - 1; index >= 0; --index)
            {
                Rhino.DocObjects.Layer layer2 = Rhino.RhinoDoc.ActiveDoc.Layers[Rhino.RhinoDoc.ActiveDoc.Layers.Find(guidList[index], true)];
                layer2.IsVisible = true;
                layer2.CommitChanges();
            }
        }
Пример #4
0
    public static Result LockLayer(RhinoDoc doc)
    {
        string layer_name = "";
        var    rc         = RhinoGet.GetString("Name of layer to lock", true, ref layer_name);

        if (rc != Result.Success)
        {
            return(rc);
        }
        if (String.IsNullOrWhiteSpace(layer_name))
        {
            return(Result.Nothing);
        }

        // because of sublayers it's possible that mone than one layer has the same name
        // so simply calling doc.Layers.Find(layerName) isn't good enough.  If "layerName" returns
        // more than one layer then present them to the user and let him decide.
        var matching_layers = (from layer in doc.Layers
                               where layer.Name == layer_name
                               select layer).ToList <Rhino.DocObjects.Layer>();

        Rhino.DocObjects.Layer layer_to_lock = null;
        if (matching_layers.Count == 0)
        {
            RhinoApp.WriteLine("Layer \"{0}\" does not exist.", layer_name);
            return(Result.Nothing);
        }
        else if (matching_layers.Count == 1)
        {
            layer_to_lock = matching_layers[0];
        }
        else if (matching_layers.Count > 1)
        {
            for (int i = 0; i < matching_layers.Count; i++)
            {
                RhinoApp.WriteLine("({0}) {1}", i + 1, matching_layers[i].FullPath.Replace("::", "->"));
            }
            int selected_layer = -1;
            rc = RhinoGet.GetInteger("which layer?", true, ref selected_layer);
            if (rc != Result.Success)
            {
                return(rc);
            }
            if (selected_layer > 0 && selected_layer <= matching_layers.Count)
            {
                layer_to_lock = matching_layers[selected_layer - 1];
            }
            else
            {
                return(Result.Nothing);
            }
        }

        if (layer_to_lock == null)
        {
            return(Result.Nothing);
        }

        if (!layer_to_lock.IsLocked)
        {
            layer_to_lock.IsLocked = true;
            layer_to_lock.CommitChanges();
            return(Result.Success);
        }
        else
        {
            RhinoApp.WriteLine("layer {0} is already locked.", layer_to_lock.FullPath);
            return(Result.Nothing);
        }
    }