Esempio n. 1
0
    public static Result ObjectIterator(RhinoDoc doc)
    {
        var object_enumerator_settings = new ObjectEnumeratorSettings();

        object_enumerator_settings.IncludeLights = true;
        object_enumerator_settings.IncludeGrips  = false;
        var rhino_objects = doc.Objects.GetObjectList(object_enumerator_settings);

        int count = 0;

        foreach (var rhino_object in rhino_objects)
        {
            if (rhino_object.IsSelectable() && rhino_object.IsSelected(false) == 0)
            {
                rhino_object.Select(true);
                count++;
            }
        }
        if (count > 0)
        {
            doc.Views.Redraw();
            RhinoApp.WriteLine("{0} object{1} selected", count,
                               count == 1 ? "" : "s");
        }
        return(Result.Success);
    }
Esempio n. 2
0
        protected override WriteFileResult WriteFile(string filename, int index, RhinoDoc doc, FileWriteOptions options)
        {
            try
            {
                var filter = new ObjectEnumeratorSettings();

                if (options.WriteSelectedObjectsOnly)
                {
                    filter.SelectedObjectsFilter = options.WriteSelectedObjectsOnly;
                }

                var objs = doc.Objects.FindByFilter(filter);

                var model = new Model();
                model.Add(objs);

                using (var writer = new StreamWriter(filename))
                    model.Save(writer);

                return(WriteFileResult.Success);
            }
            catch (Exception ex) when(!System.Diagnostics.Debugger.IsAttached)
            {
                Dialogs.ShowMessage(ex.Message, "Error", ShowMessageButton.OK, ShowMessageIcon.Error);

                return(WriteFileResult.Failure);
            }
        }
Esempio n. 3
0
        private static HashSet <RhinoObject> CollectExportedRhinoObjects(RhinoDoc RhinoDocument, IEnumerable <RhinoSceneHierarchyNode> InstancesHierarchies)
        {
            ObjectEnumeratorSettings Settings = new ObjectEnumeratorSettings();

            Settings.HiddenObjects = false;
            //First get all non-instance directly in the scene
            Settings.ObjectTypeFilter = ObjectType.AnyObject ^ (ObjectType.InstanceDefinition | ObjectType.InstanceReference);
            Settings.ReferenceObjects = true;

            //Calling GetObjectList instead of directly iterating through RhinoDocument.Objects as it seems that the ObjectTable may sometimes contain uninitialized RhinoObjects.
            HashSet <RhinoObject> ExportedObjects = new HashSet <RhinoObject>(RhinoDocument.Objects.GetObjectList(Settings));

            // Collect objects that are referenced inside instance definitions(blocks).
            // We do this because if we were to call RhinoObject.MeshObjects() on an Instance object it would create a single mesh merging all the instance's children.
            foreach (var CurrentInstanceHierarchy in InstancesHierarchies)
            {
                foreach (RhinoSceneHierarchyNode HierarchyNode in CurrentInstanceHierarchy)
                {
                    if (!HierarchyNode.bIsRoot && HierarchyNode.Info.bHasRhinoObject && !(HierarchyNode.Info.RhinoModelComponent is InstanceObject))
                    {
                        ExportedObjects.Add(HierarchyNode.Info.RhinoModelComponent as RhinoObject);
                    }
                }
            }

            return(ExportedObjects);
        }
Esempio n. 4
0
        public static int _GetObjsCount(this Layer layer, RhinoDoc doc, bool includeChildsLayers = false, ObjectType objectTypeFilter = ObjectType.AnyObject)
        {
            var settings = new ObjectEnumeratorSettings
            {
                LayerIndexFilter = layer.LayerIndex,
                HiddenObjects    = true,
            };

            if (objectTypeFilter != ObjectType.AnyObject)
            {
                settings.ObjectTypeFilter = objectTypeFilter;
            }
            var res = doc.Objects.ObjectCount(settings);

            //var res2 = doc.Objects.FindByLayer(layer).Count();
            //if (res != res2)
            //{
            //    res = res2;
            //}
            if (includeChildsLayers)
            {
                var childs = layer.GetChildren();
                if (childs != null)
                {
                    res += childs.Sum(childLayer => childLayer._GetObjsCount(doc, includeChildsLayers, objectTypeFilter));
                }
            }

            return(res);
        }
Esempio n. 5
0
        public static List <ObjRef> getVisibleObjects()
        {
            List <ObjRef>            objRefList = new List <ObjRef>();
            RhinoDoc                 doc        = RhinoDoc.ActiveDoc;
            ObjectEnumeratorSettings settings   = new ObjectEnumeratorSettings();

            settings.VisibleFilter = true;
            settings.HiddenObjects = false;

            foreach (RhinoObject rhObj in doc.Objects.GetObjectList(settings))
            {
                objRefList.Add(new ObjRef(rhObj));
            }

            return(objRefList);
        }
Esempio n. 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="file">3dm file to write to disk.</param>
        /// <param name="path">Path of the file to write.</param>
        /// <returns></returns>
        public static bool Write3dm(RhinoDoc doc, FileWriteOptions options, string path)
        {
            var file3dm = new File3dm();

            var objectEnumeratorSettings = new ObjectEnumeratorSettings
            {
                HiddenObjects = true,
                IncludeLights = true
            };

            foreach (var rhinoObject in doc.Objects.GetObjectList(objectEnumeratorSettings))
            {
                if ((options.WriteSelectedObjectsOnly && rhinoObject.IsSelected(true) == 1) || (!options.WriteSelectedObjectsOnly) || (rhinoObject.IsSelected(true) == 2))
                {
                    file3dm.AllMaterials.Add(doc.Materials[rhinoObject.Attributes.MaterialIndex]);
                    var matId = file3dm.AllMaterials.Count - 1;
                    var att   = rhinoObject.Attributes;
                    att.MaterialIndex = matId;

                    switch (rhinoObject.ObjectType)
                    {
                    case ObjectType.Mesh:
                        file3dm.Objects.AddMesh(rhinoObject.Geometry as Rhino.Geometry.Mesh, att);
                        break;

                    case ObjectType.Brep:
                    case ObjectType.Extrusion:
                    case ObjectType.Surface:
                    case ObjectType.SubD:
                        var meshes = rhinoObject.GetMeshes(Rhino.Geometry.MeshType.Default);
                        var mesh   = new Rhino.Geometry.Mesh();
                        foreach (var m in meshes)
                        {
                            mesh.Append(m);
                        }

                        file3dm.Objects.AddMesh(mesh, att);
                        break;
                    }
                }
            }

            return(file3dm.Write(path, 0));
        }
    public static Result MoveObjectsToCurrentLayer(RhinoDoc doc)
    {
        // all non-light objects that are selected
        var object_enumerator_settings = new ObjectEnumeratorSettings();
        object_enumerator_settings.IncludeLights = false;
        object_enumerator_settings.IncludeGrips = true;
        object_enumerator_settings.NormalObjects = true;
        object_enumerator_settings.LockedObjects = true;
        object_enumerator_settings.HiddenObjects = true;
        object_enumerator_settings.ReferenceObjects = true;
        object_enumerator_settings.SelectedObjectsFilter = true;
        var selected_objects = doc.Objects.GetObjectList(object_enumerator_settings);

        var current_layer_index = doc.Layers.CurrentLayerIndex;
        foreach (var selected_object in selected_objects)
        {
          selected_object.Attributes.LayerIndex = current_layer_index;
          selected_object.CommitChanges();
        }
        doc.Views.Redraw();
        return Result.Success;
    }
Esempio n. 8
0
        public void JSONToUD(string JSON)
        {
            dynamic obj = JsonConvert.DeserializeObject <ExpandoObject>(JSON);

            //Rhino.DocObjects.Custom.UserDictionary UD = new Rhino.DocObjects.Custom.UserDictionary();
            Rhino.Collections.ArchivableDictionary initDict = new Rhino.Collections.ArchivableDictionary();
            //Rhino.Collections.ArchivableDictionary dict = SelectedObject.Attributes.UserDictionary;
            //Rhino.RhinoApp.WriteLine(obj)

            IterateThroughJSON(obj, initDict);
            //dict.Set(obj.Key, initDict);


            ///////// Find selected Object(s) /////////
            var oes = new ObjectEnumeratorSettings
            {
                SelectedObjectsFilter = true,
                IncludeLights         = false,
                IncludeGrips          = false,
                IncludePhantoms       = false
            };

            List <RhinoObject> objs = RhinoDoc.ActiveDoc.Objects.GetObjectList(oes).ToList();

            foreach (RhinoObject rhObj in objs)
            {
                Rhino.Collections.ArchivableDictionary dict = rhObj.Attributes.UserDictionary;
                dict.Set(obj.Key, initDict);
                rhObj.Geometry.UserDictionary.Set("sxbuilder", dict);
                rhObj.Geometry.SetUserString("sxbuilder", "true");
            }



            //SelectedObject.Geometry.UserData.

            //SelectedObject.Geometry.UserDictionary.
        }
Esempio n. 9
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var filter = new ObjectEnumeratorSettings
            {
                NormalObjects    = true,
                LockedObjects    = false,
                HiddenObjects    = false,
                ActiveObjects    = true,
                ReferenceObjects = true
            };

            var rh_objects = doc.Objects.FindByFilter(filter);

            foreach (var rh_obj in rh_objects)
            {
                var select = 0 == rh_obj.IsSelected(false) && rh_obj.IsSelectable();
                rh_obj.Select(select);
            }

            doc.Views.Redraw();

            return(Result.Success);
        }
Esempio n. 10
0
        public void CheckIfSomethingIsSelected()
        {
            Rhino.RhinoApp.WriteLine("izMe");
            var oes = new ObjectEnumeratorSettings
            {
                SelectedObjectsFilter = true,
                IncludeLights         = false,
                IncludeGrips          = false,
                IncludePhantoms       = false
            };

            var objs      = RhinoDoc.ActiveDoc.Objects.GetObjectList(oes).ToArray();
            int numObjSel = objs.Length;

            if (numObjSel == 0)
            {
                //Rhino.RhinoApp.WriteLine("no object is selected");
                var script = string.Format("window.bus.$emit('{0}')", "no-object-selected");
                Browser.GetMainFrame().EvaluateScriptAsync(script);
                //RhinoObject selectedObject = objs[0];
            }
            else if (numObjSel == 1)
            {
                SelectedObject = objs[0];
                //Rhino.RhinoApp.WriteLine("one object is selected");
                var script = string.Format("window.bus.$emit('{0}')", "one-object-selected");
                Browser.GetMainFrame().EvaluateScriptAsync(script);
            }
            else
            {
                //Rhino.RhinoApp.WriteLine("more than one object are selected");
                var script = string.Format("window.bus.$emit('{0}')", "multiple-objects-selected");
                Browser.GetMainFrame().EvaluateScriptAsync(script);
            }
            //Rhino.RhinoApp.WriteLine(objs.Length.ToString());
        }
Esempio n. 11
0
        public static int _HiddenCount(this ObjectTable objects)
        {
            var filter_all_breps = new ObjectEnumeratorSettings()
            {
                IncludePhantoms  = true,
                HiddenObjects    = true,
                ReferenceObjects = true,
                ObjectTypeFilter = ObjectType.Brep
            };
            var filter_only_visible_breps = new ObjectEnumeratorSettings()
            {
                IncludePhantoms  = true,
                HiddenObjects    = true,
                ReferenceObjects = true,
                VisibleFilter    = true,
                ObjectTypeFilter = ObjectType.Brep
            };
            var count = objects.ObjectCount(filter_all_breps) - objects.ObjectCount(filter_only_visible_breps);

            //var obs1 = objects.GetObjectList(filter_all_breps);
            //var obs2 = objects.GetObjectList(filter_only_visible_breps);
            //var obs = objects.GetObjectList(_HiddenFilter);
            return(count);
        }
Esempio n. 12
0
    public static Result MoveObjectsToCurrentLayer(RhinoDoc doc)
    {
        // all non-light objects that are selected
        var object_enumerator_settings = new ObjectEnumeratorSettings();

        object_enumerator_settings.IncludeLights         = false;
        object_enumerator_settings.IncludeGrips          = true;
        object_enumerator_settings.NormalObjects         = true;
        object_enumerator_settings.LockedObjects         = true;
        object_enumerator_settings.HiddenObjects         = true;
        object_enumerator_settings.ReferenceObjects      = true;
        object_enumerator_settings.SelectedObjectsFilter = true;
        var selected_objects = doc.Objects.GetObjectList(object_enumerator_settings);

        var current_layer_index = doc.Layers.CurrentLayerIndex;

        foreach (var selected_object in selected_objects)
        {
            selected_object.Attributes.LayerIndex = current_layer_index;
            selected_object.CommitChanges();
        }
        doc.Views.Redraw();
        return(Result.Success);
    }
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      var object_enumerator_settings = new ObjectEnumeratorSettings();
      object_enumerator_settings.IncludeLights = true;
      object_enumerator_settings.IncludeGrips = false;
      var rhino_objects = doc.Objects.GetObjectList(object_enumerator_settings);

      int count = 0;
      foreach (var rhino_object in rhino_objects)
      {
        if (rhino_object.IsSelectable() && rhino_object.IsSelected(false) == 0)
        {
          rhino_object.Select(true);
          count++;
        }
      }
      if (count > 0)
      {
        doc.Views.Redraw();
        RhinoApp.WriteLine("{0} object{1} selected", count,
          count == 1 ? "" : "s");
      }
      return Result.Success;
    }
        /// <summary>
        /// Creates the layout.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="panel">The panel.</param>
        /// <param name="panelParas">The panel paras.</param>
        /// <returns></returns>
        public Result createLayout(RhinoDoc doc, FoldedPerforationPanel panel, PanelParameters panelParas)
        {
            if (panelParas == null)
            {
                panelParas = new PanelParameters();
            }

            if (panel == null)
            {
                panel = new FoldedPerforationPanel();
            }

            // Get all selected Objects
            GetObject go = new GetObject();

            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.EnableSelPrevious(true);
            go.EnablePreSelect(true, false);
            go.EnablePressEnterWhenDonePrompt(false);

            go.SetCommandPrompt("Select items for the new layout:");

            // Disable the scaling
            RhinoApp.RunScript("_-DocumentProperties AnnotationStyles ModelSpaceScaling=Disabled LayoutSpaceScaling=Disabled _Enter _Enter", true);

            GetResult result = go.GetMultiple(1, -1);

            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }

            RhinoApp.WriteLine("Total Objects Selected: {0}", go.ObjectCount);

            string  labelName = panel.PartName;
            string  area      = string.Format("{0:0.00}", panel.Area);
            Point2d minPoint  = new Point2d(0, 0);
            Point2d maxPoint  = new Point2d(0, 0);

            // Loop through all the objects to find Text
            for (int i = 0; i < go.ObjectCount; i++)
            {
                BoundingBox bBox = go.Object(i).Object().Geometry.GetBoundingBox(true);

                if (bBox.Min.X < minPoint.X)
                {
                    minPoint.X = bBox.Min.X;
                }

                if (bBox.Min.Y < minPoint.Y)
                {
                    minPoint.Y = bBox.Min.Y;
                }

                if (bBox.Max.X > maxPoint.X)
                {
                    maxPoint.X = bBox.Max.X;
                }

                if (bBox.Max.Y > maxPoint.Y)
                {
                    maxPoint.Y = bBox.Max.Y;
                }
            }

            // If the selected items has no label, return failure
            if (labelName == null)
            {
                return(Rhino.Commands.Result.Failure);
            }

            // Hide all the non selected objects
            foreach (var obj in doc.Objects)
            {
                if (obj.IsSelected(true) == 0)
                {
                    doc.Objects.Hide(obj, false);
                }
            }

            // Add layout
            doc.PageUnitSystem = Rhino.UnitSystem.Millimeters;


            RhinoView currentView = doc.Views.ActiveView;
            var       pageview    = doc.Views.AddPageView(string.Format("{0}", labelName), 210, 297);
            Point2d   bottomLeft  = new Point2d(10, 70);
            Point2d   topRight    = new Point2d(200, 287);

            if (pageview != null)
            {
                pageview.SetPageAsActive();

                var detail = pageview.AddDetailView("Panel", bottomLeft, topRight, Rhino.Display.DefinedViewportProjection.Top);

                // Show all objects
                RhinoApp.RunScript("_-Show _Enter", true);

                if (detail != null)
                {
                    pageview.SetActiveDetail(detail.Id);

                    doc.Views.ActiveView = pageview;

                    //doc.Views.Redraw();
                    // Select all the objects
                    for (int i = 0; i < go.ObjectCount; i++)
                    {
                        RhinoObject rhinoObject = go.Object(i).Object();

                        rhinoObject.Select(true);
                    }

                    // Hide all the non selected objects
                    var filter = new ObjectEnumeratorSettings
                    {
                        NormalObjects    = true,
                        LockedObjects    = false,
                        HiddenObjects    = false,
                        ActiveObjects    = true,
                        ReferenceObjects = true
                    };

                    var rh_objects = doc.Objects.FindByFilter(filter);

                    pageview.SetPageAsActive();

                    //doc.Views.Redraw();

                    foreach (var rh_obj in rh_objects)
                    {
                        var select = 0 == rh_obj.IsSelected(false) && rh_obj.IsSelectable();
                        rh_obj.Select(select);
                    }

                    RhinoApp.RunScript("_-HideInDetail Enter", true);

                    detail.IsActive = false;
                }

                bottomLeft = new Point2d(10, 40);
                topRight   = new Point2d(135, 70);

                detail = pageview.AddDetailView("Sample", bottomLeft, topRight, Rhino.Display.DefinedViewportProjection.Top);

                //  doc.Views.Redraw();
                pageview.SetActiveDetail(detail.Id);

                detail.Viewport.SetCameraLocation(new Point3d(50, 160, 0), true);
                detail.CommitViewportChanges();
                //  doc.Views.Redraw();

                detail.DetailGeometry.IsProjectionLocked = true;
                detail.DetailGeometry.SetScale(4.5, doc.ModelUnitSystem, 1, doc.PageUnitSystem);
                detail.CommitChanges();

                //  doc.Views.Redraw();


                detail.IsActive = true;
                pageview.SetActiveDetail(detail.Id);

                RhinoApp.WriteLine("Name = {0}: Width = {1}, Height = {2}",
                                   detail.Viewport.Name, detail.Viewport.Size.Width, detail.Viewport.Size.Height);
                detail.CommitViewportChanges();
                //  doc.Views.Redraw();

                detail.IsActive = false;

                bottomLeft = new Point2d(5, 5);
                topRight   = new Point2d(205, 35);
                detail     = pageview.AddDetailView("Block", bottomLeft, topRight, Rhino.Display.DefinedViewportProjection.Top);

                //  doc.Views.Redraw();

                detail.IsActive = true;
                pageview.SetActiveDetail(detail.Id);

                detail.Viewport.SetCameraLocation(new Point3d(105, 520, 0), true);
                detail.CommitViewportChanges();

                //  doc.Views.Redraw();

                detail.DetailGeometry.IsProjectionLocked = true;
                detail.DetailGeometry.SetScale(1, doc.ModelUnitSystem, 1, doc.PageUnitSystem);
                detail.CommitChanges();

                detail.IsActive = false;
                //  doc.Views.Redraw();

                drawBlock(doc, labelName, area, panel.PanelNumber, panelParas);

                //  doc.Views.Redraw();
            }

            // Show all objects
            RhinoApp.RunScript("_-Show _Enter", true);

            doc.Views.DefaultViewLayout();

            doc.Views.ActiveView = currentView;

            return(Result.Success);
        }
Esempio n. 15
0
        //public bool ModifyAttributes(ObjRef objref, ObjectAttributes newAttributes, bool quiet)
        //{
        //    throw new NotImplementedException();
        //}

        //public bool ModifyAttributes(AttributedGeometry obj, ObjectAttributes newAttributes, bool quiet)
        //{
        //    throw new NotImplementedException();
        //}

        public int ObjectCount(ObjectEnumeratorSettings filter)
        {
            throw new NotImplementedException();
        }
Esempio n. 16
0
        private static void ExportToJson(List <string> guids)
        {
            var doc = Rhino.RhinoDoc.ActiveDoc;
            ObjectEnumeratorSettings settings = new ObjectEnumeratorSettings();

            settings.ActiveObjects = true;
            List <Guid> ids     = new List <Guid>();
            var         objrefs = doc.Objects.GetObjectList(settings);


            List <Element> allElements = new List <Element>();


            foreach (var rhinoobj in objrefs)
            {
                var  obj            = new ObjRef(rhinoobj.Id);
                var  material       = rhinoobj.GetMaterial(true);
                var  mesh           = new va3c_Mesh();
                Mesh finalMesh      = new Mesh();
                var  parameterNames = new List <string> {
                    "objectId"
                };
                var parameterValues = new List <string> {
                    obj.ObjectId.ToString()
                };
                RCva3c.Material mat;
                if (material != null)
                {
                    mat = new va3c_MeshPhongMaterial().GeneratePhongMaterial(material.Id, material.DiffuseColor, material.AmbientColor, material.EmissionColor, material.SpecularColor, material.Shine, 1 - material.Transparency);
                }
                else
                {
                    mat = new va3c_MeshBasicMaterial().GenerateMaterial(System.Drawing.Color.White, 1);
                }

                switch (obj.Geometry().ObjectType)
                {
                case ObjectType.None:
                    break;

                case ObjectType.Point:
                    break;

                case ObjectType.PointSet:
                    break;

                case ObjectType.Curve:
                    break;

                case ObjectType.Surface:
                    var srf     = obj.Surface();
                    var meshSrf = Mesh.CreateFromBrep(srf.ToBrep());
                    if (meshSrf?.Length > 0)
                    {
                        foreach (var m in meshSrf)
                        {
                            finalMesh.Append(m);
                        }
                    }
                    allElements.Add(mesh.GenerateMeshElement(finalMesh, mat, obj.ObjectId, parameterNames, parameterValues));
                    break;

                case ObjectType.Brep:
                    var brep     = obj.Brep();
                    var meshBrep = Mesh.CreateFromBrep(brep);
                    if (meshBrep?.Length > 0)
                    {
                        foreach (var m in meshBrep)
                        {
                            finalMesh.Append(m);
                        }
                    }
                    allElements.Add(mesh.GenerateMeshElement(finalMesh, mat, obj.ObjectId, parameterNames, parameterValues));
                    break;

                case ObjectType.Mesh:
                    var msh = obj.Mesh();
                    allElements.Add(mesh.GenerateMeshElement(msh, mat, obj.ObjectId, parameterNames, parameterValues));
                    break;

                case ObjectType.Light:
                    break;

                case ObjectType.Annotation:
                    break;

                case ObjectType.InstanceDefinition:
                    break;

                case ObjectType.InstanceReference:
                    break;

                case ObjectType.TextDot:
                    break;

                case ObjectType.Grip:
                    break;

                case ObjectType.Detail:
                    break;

                case ObjectType.Hatch:
                    break;

                case ObjectType.MorphControl:
                    break;

                case ObjectType.BrepLoop:
                    break;

                case ObjectType.PolysrfFilter:
                    break;

                case ObjectType.EdgeFilter:
                    break;

                case ObjectType.PolyedgeFilter:
                    break;

                case ObjectType.MeshVertex:
                    break;

                case ObjectType.MeshEdge:
                    break;

                case ObjectType.MeshFace:
                    break;

                case ObjectType.Cage:
                    break;

                case ObjectType.Phantom:
                    break;

                case ObjectType.ClipPlane:
                    break;

                case ObjectType.Extrusion:

                    var extruction     = obj.Brep();
                    var meshExtruction = Mesh.CreateFromBrep(extruction);
                    if (meshExtruction?.Length > 0)
                    {
                        foreach (var m in meshExtruction)
                        {
                            finalMesh.Append(m);
                        }
                    }
                    allElements.Add(mesh.GenerateMeshElement(finalMesh, mat, obj.ObjectId, parameterNames, parameterValues));
                    break;

                case ObjectType.AnyObject:
                    break;

                default:
                    break;
                }
            }


            var         scenecompiler = new va3c_SceneCompiler();
            string      resultatas    = scenecompiler.GenerateSceneJson(doc.Name.Replace(".3dm", ""), allElements);
            FileManager writer        = new FileManager();

            writer.SaveFileTo(new List <string> {
                resultatas
            });
        }
Esempio n. 17
0
        //public void GetGroupList(){}

        public void PropertyObject()
        {
            var oes = new ObjectEnumeratorSettings
            {
                SelectedObjectsFilter = true,
                IncludeLights         = false,
                IncludeGrips          = false,
                IncludePhantoms       = false
            };

            var objs = RhinoDoc.ActiveDoc.Objects.GetObjectList(oes).ToArray();

            if (objs != null && objs.Count() > 0)
            {
                //have one or more objects
                if (objs.Count() == 1)
                {
                    var obj           = objs[0];
                    var propertyInfos = obj.GetType().GetProperties();
                    var propertyDict  = new Dictionary <string, Object>();
                    //propertyDict.Add("Guid", obj.Id.ToString());
                    foreach (var pi in propertyInfos)
                    {
                        object objVal;
                        if (pi.PropertyType == typeof(RhinoDoc))
                        {
                            objVal = RhinoDoc.ActiveDoc.Name;
                            if (objVal == null)
                            {
                                objVal = "Untitled";
                            }
                            if (string.IsNullOrEmpty(objVal.ToString()))
                            {
                                objVal = "Untitled";
                            }
                            propertyDict.Add(pi.Name, objVal);
                            //RhinoApp.WriteLine("SchemaBuilder: " + pi.Name + " : " + objVal);
                        }
                        else if (pi.PropertyType == typeof(Rhino.Geometry.GeometryBase) || pi.PropertyType.BaseType == typeof(Rhino.Geometry.GeometryBase) || pi.PropertyType.BaseType.BaseType == typeof(Rhino.Geometry.GeometryBase))
                        {
                        }
                        else if (pi.Name == "Id")
                        {
                        }
                        else if (pi.PropertyType == typeof(ObjectAttributes))
                        {
                            var objAttr = obj.Attributes.GetType().GetProperties();
                            foreach (var att in objAttr)
                            {
                                object objAtt = att.GetValue(obj.Attributes, null);
                                //RhinoApp.WriteLine("SchemaBuilder: " + "    " + att.Name + " : " + objAtt);
                                if (propertyDict.ContainsKey(att.Name) || objAtt == null || string.IsNullOrEmpty(objAtt.ToString()))
                                {
                                }
                                else
                                {
                                    propertyDict.Add(att.Name, objAtt);
                                    //RhinoApp.WriteLine("SchemaBuilder: " + att.Name + " : " + objAtt);
                                }
                            }
                        }
                        else
                        {
                            objVal = pi.GetValue(obj, null);
                            if (propertyDict.ContainsKey(pi.Name) || objVal == null || string.IsNullOrEmpty(objVal.ToString()))
                            {
                            }
                            else
                            {
                                propertyDict.Add(pi.Name, objVal);
                                //RhinoApp.WriteLine("SchemaBuilder: " + pi.Name + " : " + objVal);
                            }
                        }
                    }

                    //propertyDict.Add("attributes", obj.Attributes);

                    var script = string.Format("window.bus.$emit('{0}', '{1}')", "get-properties", JsonConvert.SerializeObject(propertyDict));
                    Browser.GetMainFrame().EvaluateScriptAsync(script);
                }
                else
                {
                    RhinoApp.WriteLine("SchemaBuilder: Too many objects selected. Select only one Object and try again.");
                    return;
                }
            }
            else
            {
                RhinoApp.WriteLine("SchemaBuilder: No object is selected. Select one Object and try again.");
            }
        }