Exemplo n.º 1
0
        public string getLayersAndObjectsInfo(bool ignoreSelection = false)
        {
            List <RhinoObject>    SelectedObjects;
            List <LayerSelection> layerInfoList = new List <LayerSelection>();

            if (!ignoreSelection)
            {
                SelectedObjects = RhinoDoc.ActiveDoc.Objects.GetSelectedObjects(false, false).ToList();
                if (SelectedObjects.Count == 0 || SelectedObjects[0] == null)
                {
                    return(JsonConvert.SerializeObject(layerInfoList, camelCaseSettings));
                }
            }
            else
            {
                SelectedObjects = RhinoDoc.ActiveDoc.Objects.ToList();
                if (SelectedObjects.Count == 0 || SelectedObjects[0] == null)
                {
                    return(JsonConvert.SerializeObject(layerInfoList, camelCaseSettings));
                }

                foreach (Rhino.DocObjects.Layer ll in RhinoDoc.ActiveDoc.Layers)
                {
                    layerInfoList.Add(new LayerSelection()
                    {
                        objectCount = 0,
                        layerName   = ll.FullPath,
                        color       = System.Drawing.ColorTranslator.ToHtml(ll.Color),
                        ObjectGuids = new List <string>(),
                        ObjectTypes = new List <string>()
                    });
                }
            }

            SelectedObjects = SelectedObjects.OrderBy(o => o.Attributes.LayerIndex).ToList();

            foreach (var obj in SelectedObjects)
            {
                var layer   = RhinoDoc.ActiveDoc.Layers[obj.Attributes.LayerIndex];
                var myLInfo = layerInfoList.FirstOrDefault(l => l.layerName == layer.FullPath);

                if (myLInfo != null)
                {
                    myLInfo.objectCount++;
                    myLInfo.ObjectGuids.Add(obj.Id.ToString());
                    myLInfo.ObjectTypes.Add(obj.Geometry.GetType().ToString());
                }
                else
                {
                    var myNewLinfo = new LayerSelection()
                    {
                        objectCount = 1,
                        layerName   = layer.FullPath,
                        color       = System.Drawing.ColorTranslator.ToHtml(layer.Color),
                        ObjectGuids = new List <string>(new string[] { obj.Id.ToString() }),
                        ObjectTypes = new List <string>(new string[] { obj.Geometry.GetType().ToString() })
                    };
                    layerInfoList.Add(myNewLinfo);
                }
            }

            return(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(layerInfoList, camelCaseSettings))));
        }