示例#1
0
        private void Bake(List <SmSatellite> sats)
        {
            Rhino.DocObjects.Tables.ObjectTable ot = Rhino.RhinoDoc.ActiveDoc.Objects;

            // Bake Earth
            double scale = SpaceMonkeyCoreViewModel.Instance.ScaleFactor;
            Sphere earth = new Sphere(new Point3d(0, 0, 0), 6378.137 * scale);

            ot.AddSphere(earth);

            foreach (SmSatellite s in sats)
            {
                Point3d          pt   = SatToPoint(s);
                ObjectAttributes attr = new ObjectAttributes();
                attr.SetUserString(nameof(SmSatellite.SatId), s.SatId.ToString());
                attr.SetUserString(nameof(SmSatellite.SatName), s.SatName);
                attr.SetUserString(nameof(SmSatellite.IntDesignator), s.IntDesignator);
                attr.SetUserString(nameof(SmSatellite.LaunchDate), s.LaunchDate);
                attr.SetUserString(nameof(SmSatellite.SatLat), s.SatLat.ToString());
                attr.SetUserString(nameof(SmSatellite.SatLng), s.SatLng.ToString());
                attr.SetUserString(nameof(SmSatellite.SatAlt), s.SatAlt.ToString());
                ot.AddPoint(pt, attr);
            }

            foreach (var view in Rhino.RhinoDoc.ActiveDoc.Views)
            {
                view.Redraw();
            }
        }
        protected void ExportStl(Brep geom, string path)
        {
            List <Guid> guidList = new List <Guid>();

            Rhino.DocObjects.Tables.ObjectTable ot = Rhino.RhinoDoc.ActiveDoc.Objects;

            if (geom == null || !geom.IsValid)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No object to bake, or brep not valid, aborted.");
                return;
            }
            System.Guid guid = ot.AddBrep(geom);
            guidList.Add(guid);

            int nSelected = ot.Select(guidList);

            if (nSelected != guidList.Count)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Not all objects could be selected, aborted.");
                return;
            }

            string cmd = "-_Export " + "\"" + path + ".stl" + "\"" + " _Enter" + " _Enter";

            Rhino.RhinoApp.RunScript(cmd, false);

            ot.Delete(guidList, true);
        }
示例#3
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            bool delete = false;

            DA.GetData(0, ref delete);

            Rhino.DocObjects.Tables.ObjectTable ot = Rhino.RhinoDoc.ActiveDoc.Objects;
            if (delete)
            {
                List <Rhino.DocObjects.RhinoObject>       objects = new List <Rhino.DocObjects.RhinoObject>();
                Rhino.DocObjects.ObjectEnumeratorSettings s       = new Rhino.DocObjects.ObjectEnumeratorSettings
                {
                    HiddenObjects = true,
                    LockedObjects = true
                };

                foreach (Rhino.DocObjects.RhinoObject obj in RhinoDoc.ActiveDoc.Objects.GetObjectList(s))
                {
                    if (obj.Name.StartsWith("Y:") || obj.Name.StartsWith("X:") || obj.Name.StartsWith("Z:"))
                    {
                        ot.Delete(obj.Id, true);
                    }
                }
            }
        }
示例#4
0
        public Rhino.Commands.Result delete(Rhino.RhinoDoc doc)
        {
            // Input incomplate
            double _incomplate = 0.1;

            var input = new Rhino.Input.Custom.GetNumber();

            input.SetCommandPrompt("Input incomplate(0.0 ~ 1.0)<0.1>");
            Rhino.Input.GetResult res = input.Get();
            if (res == Rhino.Input.GetResult.Number)
            {
                _incomplate = input.Number();
            }
            if (_incomplate == 0.0)
            {
                _incomplate = 0.1;
            }

            // Select surface
            var go = new Rhino.Input.Custom.GetObject();

            go.SetCommandPrompt("Select elements");
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Point;
            res = go.GetMultiple(1, 1024 * 10);
            if (res == Rhino.Input.GetResult.Nothing)
            {
                return(Rhino.Commands.Result.Failure);
            }

            System.Collections.Generic.List <Guid> list = new System.Collections.Generic.List <Guid>();
            for (int i = 0; i < go.ObjectCount; i++)
            {
                Guid guid = go.Object(i).ObjectId;
                list.Add(guid);
            }

            int deleteCount = (int)((double)(list.Count) * _incomplate);

            Rhino.DocObjects.Tables.ObjectTable ot = Rhino.RhinoDoc.ActiveDoc.Objects;
            for (int i = 0; i < deleteCount; i++)
            {
                Guid guid = list[i];
                ot.Delete(guid, true);
            }

            return(Rhino.Commands.Result.Success);
        }
示例#5
0
        public static void BakeFacades(IEnumerable <Facade> faces, bool bake = false, Curve crv = null)
        {
            Rhino.DocObjects.Tables.ObjectTable ot = Rhino.RhinoDoc.ActiveDoc.Objects;

            foreach (Facade face in faces)
            {
                Rhino.DocObjects.ObjectAttributes att = new Rhino.DocObjects.ObjectAttributes {
                    Name = face.Id
                };
                if (crv != null)
                {
                    if (PointContainmentCheck(face.Centroid, crv))
                    {
                        ot.AddMesh(face.Geometry, att);
                    }
                }
                else
                {
                    ot.AddMesh(face.Geometry, att);
                }
            }
        }
示例#6
0
        public void SelectByParameter(RhinoDoc doc, ParametersSelectorForm form)
        {
            Rhino.DocObjects.Tables.ObjectTable rhobjs = doc.Objects;

            string paramName = form.GetParamName();

            if (paramName != "")
            {
                // List to store all the objects that match.
                List <Rhino.DocObjects.RhinoObject> matched = new List <Rhino.DocObjects.RhinoObject>();

                string paramValue = form.GetParamValue();

                // TODO Filter also by type of obj?
                // rhobjs = filter( lambda x: va.IsColumn(x.Id) , Rhino.RhinoDoc.ActiveDoc.Objects)

                if (paramValue != "") // Search by name and value.
                {
                    // If the input param value can be converted to num then compare as num and as text.
                    if (Double.TryParse(paramValue, out double numValue))
                    {
                        int comparison = form.GetComparisonType();
                        if (comparison == 0) // Equality comparison.
                        {
                            foreach (Rhino.DocObjects.RhinoObject o in rhobjs)
                            {
                                Guid paramId = GetObjectParameterId(paramName, o.Id, true);
                                if (paramId != Guid.Empty && GetParameterValue(paramId, o.Id) != null)
                                {
                                    ParameterType t = GetParameterType(paramId);
                                    // First type number comparison.
                                    if (IsDirectNumericalType(t) && numValue == Convert.ToDouble(GetParameterValue(paramId, o.Id)))
                                    {
                                        matched.Add(o);
                                    }
                                    // Type angle comparison.
                                    else if (t == ParameterType.Angle && DegreeToRadian(numValue) == Convert.ToDouble(GetParameterValue(paramId, o.Id)))
                                    {
                                        matched.Add(o);
                                    }
                                    // Type percentage comparison.
                                    else if (t == ParameterType.Percentage && (numValue / 100.0) == Convert.ToDouble(GetParameterValue(paramId, o.Id)))
                                    {
                                        matched.Add(o);
                                    }
                                    // If it is a number but as a string.
                                    else if (GetParameterValue(paramId, o.Id) != null && paramValue == GetParameterValue(paramId, o.Id).ToString())
                                    {
                                        matched.Add(o);
                                    }
                                }
                            }
                        }
                        else if (comparison == 1) // Less than comparison.
                        {
                            foreach (Rhino.DocObjects.RhinoObject o in rhobjs)
                            {
                                Guid paramId = GetObjectParameterId(paramName, o.Id, true);
                                if (paramId != Guid.Empty && GetParameterValue(paramId, o.Id) != null)
                                {
                                    ParameterType t = GetParameterType(paramId);
                                    // First type number comparison.
                                    if (IsDirectNumericalType(t) && numValue > Convert.ToDouble(GetParameterValue(paramId, o.Id)))
                                    {
                                        matched.Add(o);
                                    }
                                    // Type angle comparison.
                                    else if (t == ParameterType.Angle && DegreeToRadian(numValue) > Convert.ToDouble(GetParameterValue(paramId, o.Id)))
                                    {
                                        matched.Add(o);
                                    }
                                    // Type percentage comparison.
                                    else if (t == ParameterType.Percentage && (numValue / 100.0) > Convert.ToDouble(GetParameterValue(paramId, o.Id)))
                                    {
                                        matched.Add(o);
                                    }
                                }
                            }
                        }
                        else if (comparison == 2) // Greater than comparison.
                        {
                            foreach (Rhino.DocObjects.RhinoObject o in rhobjs)
                            {
                                Guid paramId = GetObjectParameterId(paramName, o.Id, true);
                                if (paramId != Guid.Empty && GetParameterValue(paramId, o.Id) != null)
                                {
                                    ParameterType t = GetParameterType(paramId);
                                    // First type number comparison.
                                    if (IsDirectNumericalType(t) && numValue < Convert.ToDouble(GetParameterValue(paramId, o.Id)))
                                    {
                                        matched.Add(o);
                                    }
                                    // Type angle comparison.
                                    else if (t == ParameterType.Angle && DegreeToRadian(numValue) < Convert.ToDouble(GetParameterValue(paramId, o.Id)))
                                    {
                                        matched.Add(o);
                                    }
                                    // Type percentage comparison.
                                    else if (t == ParameterType.Percentage && (numValue / 100.0) < Convert.ToDouble(GetParameterValue(paramId, o.Id)))
                                    {
                                        matched.Add(o);
                                    }
                                }
                            }
                        }
                    }
                    else // If it cannot be converted to num then only compare as bool and text.
                    {
                        int comparison = form.GetComparisonType();
                        if (comparison == 0) // Equality comparison.
                        {
                            foreach (Rhino.DocObjects.RhinoObject o in rhobjs)
                            {
                                Guid paramId = GetObjectParameterId(paramName, o.Id, true);
                                if (paramId != Guid.Empty && GetParameterValue(paramId, o.Id) != null)
                                {
                                    ParameterType t = GetParameterType(paramId);
                                    if (t == ParameterType.Boolean)
                                    {
                                        if ((string.Equals(paramValue, "yes", StringComparison.OrdinalIgnoreCase) ||
                                             string.Equals(paramValue, "true", StringComparison.OrdinalIgnoreCase)) &&
                                            "True" == GetParameterValue(paramId, o.Id).ToString())
                                        {
                                            matched.Add(o);
                                        }
                                        else if ((string.Equals(paramValue, "no", StringComparison.OrdinalIgnoreCase) ||
                                                  string.Equals(paramValue, "false", StringComparison.OrdinalIgnoreCase)) &&
                                                 "False" == GetParameterValue(paramId, o.Id).ToString())
                                        {
                                            matched.Add(o);
                                        }
                                    }
                                    else if (paramValue == GetParameterValue(paramId, o.Id).ToString())
                                    {
                                        matched.Add(o);
                                    }
                                }
                            }
                        }
                    }
                }
                else // Search only by parameter name.
                {
                    foreach (Rhino.DocObjects.RhinoObject o in rhobjs)
                    {
                        Guid paramId = GetObjectParameterId(paramName, o.Id, true);
                        if (paramId != Guid.Empty)
                        {
                            matched.Add(o);
                        }
                    }
                }

                if (form.GetAddToSelection() == null || form.GetAddToSelection() == false)
                {
                    rhobjs.UnselectAll();
                }

                // Select all the ones that matched.
                if (matched.Count > 0)
                {
                    foreach (Rhino.DocObjects.RhinoObject o in matched)
                    {
                        o.Select(true);
                    }
                    if (matched.Count == 1)
                    {
                        RhinoApp.WriteLine("1 object was selected.");
                    }
                    else
                    {
                        RhinoApp.WriteLine("{0} objects were selected.", matched.Count);
                    }
                }
                else
                {
                    RhinoApp.WriteLine("No objects were found.");
                }
            }
        }
示例#7
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // INPUT
            // declaration
            string inx = null;

            Rhino.DocObjects.Tables.ObjectTable ot = Rhino.RhinoDoc.ActiveDoc.Objects;
            List <Rhino.DocObjects.RhinoObject> selectedObjects = ot.GetSelectedObjects(false, false).ToList();

            //List<System.Guid> facades = new List<System.Guid>();
            string material = "000000";
            bool   greening = false;
            bool   runIt    = false;

            DA.GetData(0, ref inx);
            DA.GetData(1, ref material);
            DA.GetData(2, ref greening);
            DA.GetData(3, ref runIt);

            if (runIt)
            {
                // Handle invalid tags within INX
                string file = File.ReadAllText(inx);
                file = file.Replace("3Dplants", "threeDplants");

                // Parse XML
                XDocument doc = XDocument.Parse(file);

                XElement wall       = doc.Root.Element("WallDB").Element("ID_wallDB");
                XElement singleWall = doc.Root.Element("SingleWallDB").Element("ID_singlewallDB");
                XElement greenWall  = doc.Root.Element("GreeningDB").Element("ID_GreeningDB");
                XElement terrain    = doc.Root.Element("dem3D").Element("terrainflag");
                WorkaroundNewString(wall);
                WorkaroundNewString(singleWall);
                WorkaroundNewString(greenWall);
                WorkaroundNewString(terrain);

                List <PixelCoordinate> pixelSelection = Facade.GetPixelFromSelection(selectedObjects, material).ToList();

                List <string>          matrixInx = Facade.GetFacadeSparseMatrix(inx).ToList();
                List <PixelCoordinate> pixelsInx = Facade.GetPixelFromSparseMatrix(matrixInx).ToList();

                string sparseMatrix      = "\n" + String.Join("\n", matrixInx) + "\n";
                string greenSparseMatrix = null;

                if (greening)
                {
                    List <PixelCoordinate> pixels = Facade.GetUniqueSelectedPixels(pixelSelection).ToList();
                    greenSparseMatrix = Facade.GetFacadeSparseMatrixFromPixels(pixels);
                    greenWall.SetValue("\n" + greenSparseMatrix + "\n");
                }
                else
                {
                    IEnumerable <PixelCoordinate> pixels = Facade.UpdatePixelMaterial(pixelsInx, pixelSelection);
                    sparseMatrix = Facade.GetFacadeSparseMatrixFromPixels(pixels);
                    wall.SetValue("\n" + sparseMatrix + "\n");
                }

                string text = Facade.GetXmlWithWrongTag(doc.ToString());

                // write file in a new destination
                File.WriteAllText(inx, text);

                DA.SetData(0, inx);
            }
        }