Beispiel #1
0
        public static List <Curve> Curves()
        {
            GetObject go;

            while (true)
            {
                go = new GetObject();
                go.AcceptNothing(true);
                go.AcceptEnterWhenDone(true);
                go.SetCommandPrompt("请选择一条或多条曲线,之后回车或者右键确认");
                go.GeometryFilter = ObjectType.Curve | ObjectType.EdgeFilter;

                if (go.GetMultiple(1, 0) != GetResult.Object)
                {
                    return(null);
                }

                List <Curve> ghCurveList1 = new List <Curve>();
                Array.ForEach(go.Objects(), (ObjRef obj) => ghCurveList1.Add(obj.Curve()));
                if (ghCurveList1.Count == 0)
                {
                    return(null);
                }
                return(ghCurveList1);
            }
        }
Beispiel #2
0
        public static List <Guid> Guids(ObjectType filter)
        {
            GetObject go;

            while (true)
            {
                go = new GetObject();
                go.AcceptNothing(true);
                go.AcceptEnterWhenDone(true);
                go.SetCommandPrompt("请选择一个或多个,之后回车确认");
                go.GeometryFilter = filter;
                if (go.GetMultiple(1, 0) != GetResult.Object)
                {
                    return(null);
                }

                List <Guid> ghCurveList1 = new List <Guid>();
                Array.ForEach(go.Objects(), (ObjRef obj) => ghCurveList1.Add(obj.ObjectId));
                if (ghCurveList1.Count == 0)
                {
                    return(null);
                }
                return(ghCurveList1);
            }
        }
Beispiel #3
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // select curves to loft
            var gs = new GetObject();

            gs.SetCommandPrompt("select curves to loft");
            gs.GeometryFilter = ObjectType.Curve;
            gs.DisablePreSelect();
            gs.SubObjectSelect = false;
            gs.GetMultiple(2, 0);
            if (gs.CommandResult() != Result.Success)
            {
                return(gs.CommandResult());
            }

            var curves = gs.Objects().Select(obj => obj.Curve()).ToList();

            var breps = Brep.CreateFromLoft(curves, Point3d.Unset, Point3d.Unset, LoftType.Tight, false);

            foreach (var brep in breps)
            {
                doc.Objects.AddBrep(brep);
            }

            doc.Views.Redraw();
            return(Result.Success);
        }
Beispiel #4
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            GetObject go = new GetObject();

            go.SetCommandPrompt("Select surfaces, polysurfaces, or meshes");
            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            bool bHavePreselectedObjects = false;

            for (; ;)
            {
                GetResult res = go.GetMultiple(1, 0);

                if (res == GetResult.Option)
                {
                    go.EnablePreSelect(false, true);
                    continue;
                }

                else if (res != GetResult.Object)
                {
                    return(Result.Cancel);
                }

                if (go.ObjectsWerePreselected)
                {
                    bHavePreselectedObjects = true;
                    go.EnablePreSelect(false, true);
                    continue;
                }

                break;
            }


            BoundingBox box = BoundingBox.Empty;

            for (int i = 0; i < go.ObjectCount; i++)
            {
                RhinoObject rhinoObject = go.Object(i).Object();
                if (null != rhinoObject)
                {
                    box.Union(rhinoObject.Geometry.GetBoundingBox(true));
                }
                rhinoObject.Select(false);
            }

            if (box.IsValid)
            {
                RFContext.ClippingBox = new Box(box);
                //RFContext.Clip = true;

                return(Result.Success);
            }

            return(Result.Nothing);
        }
Beispiel #5
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var go = new GetObject();

            go.SetCommandPrompt("Select polygon meshes to unweld");
            go.GeometryFilter = ObjectType.Mesh;
            go.GetMultiple(1, 0);
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            foreach (var obj_ref in go.Objects())
            {
                var old_mesh = obj_ref.Mesh();
                if (null != old_mesh)
                {
                    var new_mesh = UnweldMesh(old_mesh);
                    if (null != new_mesh && new_mesh.IsValid)
                    {
                        doc.Objects.Replace(go.Object(0), new_mesh);
                    }
                }
            }

            doc.Views.Redraw();

            return(Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var go = new GetObject();

            go.SetCommandPrompt("Select curves to extract min/max radius points");
            go.GeometryFilter = ObjectType.Curve;
            go.GetMultiple(1, 0);
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            for (var i = 0; i < go.ObjectCount; i++)
            {
                var curve = go.Object(i).Curve();
                if (null != curve)
                {
                    var points = new List <Point3d>();
                    if (GetMinMaxRadiusPoints(curve, points))
                    {
                        doc.Objects.AddPoints(points);
                    }
                }
            }

            doc.Views.Redraw();

            return(Result.Success);
        }
Beispiel #7
0
        /// <summary>
        /// This function selects breps
        /// </summary>
        ///
        ///
        public static bool XSelectBreps(string message, out RhinoList <Brep> breps)
        {
            breps = new RhinoList <Brep>();

            int i;

            var gc = new GetObject();


            gc.SetCommandPrompt("Select some Breps");
            gc.EnablePreSelect(true, true);
            gc.GeometryFilter = Rhino.DocObjects.ObjectType.Brep;
            gc.GetMultiple(1, 0);

            //we do our double check to make sure the user selected something

            if (gc.CommandResult() != Result.Success)
            {
                return(false);
            }


            for (i = 0; i < gc.ObjectCount; i++)
            {
                var brep = gc.Object(i).Brep();
                if (null != brep)
                {
                    breps.Add(brep);
                }
            }

            return(true);
        }
Beispiel #8
0
        public static List <GH_Point> PickPoint()
        {
            GetObject go;

            while (true)
            {
                go = new GetObject();
                go.AcceptNothing(true);
                go.AcceptEnterWhenDone(true);
                go.SetCommandPrompt("请选择一个或多个,之后回车确认");
                go.GeometryFilter = ObjectType.Point;

                if (go.GetMultiple(1, 0) != GetResult.Object)
                {
                    return(null);
                }

                List <GH_Point> ghCurveList1 = new List <GH_Point>();
                Array.ForEach(go.Objects(), (ObjRef obj) => ghCurveList1.Add(new GH_Point(obj.Point().Location)));
                if (ghCurveList1.Count == 0)
                {
                    return(null);
                }
                return(ghCurveList1);
            }
        }
Beispiel #9
0
        public override NodeCollection EnterNodes(string prompt = "Enter nodes")
        {
            GetObject gO = new GetObject();

            gO.SetCustomGeometryFilter(new GetObjectGeometryFilter(FilterHandles));
            gO.GeometryFilter = ObjectType.Point;
            gO.SetCommandPrompt(prompt);
            if (gO.GetMultiple(1, 0) == GetResult.Cancel)
            {
                throw new OperationCanceledException("Operation cancelled by user");
            }
            var result = new NodeCollection();

            foreach (ObjRef rObj in gO.Objects())
            {
                if (Host.Instance.Handles.Links.ContainsSecond(rObj.ObjectId))
                {
                    Guid guid = Host.Instance.Handles.Links.GetFirst(rObj.ObjectId);
                    Node node = Core.Instance.ActiveDocument?.Model?.Nodes[guid];
                    if (node != null && node is Node)
                    {
                        result.Add(node);
                    }
                }
            }
            return(result);
        }
Beispiel #10
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var go = new GetObject();

            go.SetCommandPrompt("Select closed, planar curves for containment test");
            go.GeometryFilter          = ObjectType.Curve;
            go.GeometryAttributeFilter = GeometryAttributeFilter.ClosedCurve;
            go.GetMultiple(2, 2);
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            var plane = go.View().ActiveViewport.ConstructionPlane();
            var tol   = doc.ModelAbsoluteTolerance;

            var crvs = new Curve[2];

            for (var i = 0; i < 2; i++)
            {
                var rh_ref = go.Object(i);
                var rh_obj = rh_ref.Object();
                crvs[i] = rh_ref.Curve();
                if (null == rh_obj || null == crvs[i])
                {
                    return(Result.Failure);
                }

                if (!crvs[i].IsPlanar(tol))
                {
                    RhinoApp.WriteLine("Curve is not planar");
                    rh_obj.Select(true);
                    doc.Views.Redraw();
                    return(Result.Failure);
                }
            }

            var result = Curve.PlanarClosedCurveRelationship(crvs[0], crvs[1], plane, tol);

            switch (result)
            {
            case RegionContainment.Disjoint:
                RhinoApp.WriteLine("There is no common area between the two regions.");
                break;

            case RegionContainment.MutualIntersection:
                RhinoApp.WriteLine("The two curves intersect. There is therefore no full containment relationship either way.");
                break;

            case RegionContainment.AInsideB:
                RhinoApp.WriteLine("The region bounded by the first curve is inside of the second curve.");
                break;

            case RegionContainment.BInsideA:
                RhinoApp.WriteLine("The region bounded by the second curve is inside of the second first.");
                break;
            }

            return(Result.Success);
        }
        public GH_GetterResult LoadFromSelection(out PointCloud pc)
        {
            var go = new GetObject();

            go.GeometryFilter = Rhino.DocObjects.ObjectType.Point | Rhino.DocObjects.ObjectType.PointSet;
            if (go.GetMultiple(1, 0) == Rhino.Input.GetResult.Cancel)
            {
                pc = null;
                return(GH_GetterResult.cancel);
            }
            pc = new PointCloud();

            for (int i = 0; i < go.ObjectCount; i++)
            {
                var obj   = go.Object(i);
                var rhObj = obj.Object();
                if (rhObj.ObjectType == ObjectType.Point)
                {
                    var pt  = obj.Point().Location;
                    var col = rhObj.Attributes.ObjectColor;
                    pc.Add(pt, col);
                }
                else if (rhObj.ObjectType == ObjectType.PointSet)
                {
                    using (PointCloud cloud = obj.PointCloud())
                    {
                        foreach (var item in cloud.AsEnumerable())
                        {
                            pc.Add(item.Location, item.Normal, item.Color);
                        }
                    }
                }
            }
            return(GH_GetterResult.success);
        }
Beispiel #12
0
        public override PanelElementCollection EnterPanelElements(string prompt = "Enter panel elements")
        {
            GetObject gO = new GetObject();

            gO.SetCustomGeometryFilter(new GetObjectGeometryFilter(FilterHandles));
            gO.GeometryFilter = ObjectType.Surface | ObjectType.Mesh;
            gO.SetCommandPrompt(prompt);
            if (gO.GetMultiple(1, 0) == GetResult.Cancel)
            {
                throw new OperationCanceledException("Operation cancelled by user");
            }
            foreach (ObjRef rObj in gO.Objects())
            {
                var result = new PanelElementCollection();
                if (Host.Instance.Handles.Links.ContainsSecond(rObj.ObjectId))
                {
                    Guid    guid    = Host.Instance.Handles.Links.GetFirst(rObj.ObjectId);
                    Element element = Core.Instance.ActiveDocument?.Model?.Elements[guid];
                    if (element != null && element is PanelElement)
                    {
                        result.Add((PanelElement)element);
                    }
                }
                return(result);
            }
            return(null);
        }
Beispiel #13
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var go = new GetObject();

            //GetObject is more general, and allows you to select any type of object.

            go.GeometryFilter = Rhino.DocObjects.ObjectType.Point;

            //user can only select points

            go.GetMultiple(1, 0);

            if (go.CommandResult() ! = Result.Success)
            {
                return(go.CommandResult());
            }
            // if statement above is just a check to tell us what to do if the command is a success/failure

            var points = new List <Point>(go.ObjectCount);

            // now we have a list, we just have to save them.  Let's use a different type of array using
            // the System.Collections namespace.  The size of the array will be the size of the ObjectCount list.

            for (var i = 0; i < go.ObjectCount; i++)
            {
                var point = go.Object(i).Point();
                if (null != point)
                {
                }
            }

            RhinoApp.WriteLine("The user selected {0} points successfully", points.Count.ToString());

            return(Result.Success);
        }
Beispiel #14
0
        /// <summary>
        /// This function selects points
        /// </summary>
        /// <param name="message"></param>
        /// <param name="pointer"></param>
        public static void XSelectPoints(string message, out Point3dList pointer)
        {
            // variables are:
            // string message
            // out Point3dList points - the out won't be recognized unless you have Rhino.Collections and the 'out parameters
            // have to be filled in the function.
            // don't need a doc because we won't write anything to the document table, only reading.


            pointer = new Point3dList();

            var go = new GetObject();

            go.GeometryFilter = Rhino.DocObjects.ObjectType.Point;
            go.SetCommandPrompt(message);
            go.GetMultiple(1, 0);

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

            for (var i = 0; i < go.ObjectCount; i++)
            {
                var point = go.Object(i).Point();
                if (null != point)
                {
                    pointer.Add(point.Location);
                }
            }
        }
Beispiel #15
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var go = new GetObject();

            go.SetCommandPrompt("Select grips to move");
            go.GeometryFilter = ObjectType.Grip;
            go.GetMultiple(1, 0);
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            using (var object_list = new TransformObjectList())
            {
                object_list.AddObjects(go, true);

                var dir   = new Vector3d(5, 0, 0); // 5 units in world x-axis direction
                var xform = Transform.Translation(dir);

                foreach (var grip in object_list.GripArray())
                {
                    grip.Move(xform);
                }

                foreach (var owner in object_list.GripOwnerArray())
                {
                    doc.Objects.GripUpdate(owner, true);
                }

                doc.Views.Redraw();
            }

            return(Result.Success);
        }
Beispiel #16
0
        /// <summary>
        /// This function selects some curves
        /// </summary>
        ///
        ///
        public static bool XSelectCurves(string message, out CurveList curves)
        {
            curves = new CurveList();

            var gc = new GetObject();

            gc.SetCommandPrompt(message);
            gc.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
            gc.GetMultiple(1, 0);

            if (gc.CommandResult() != Result.Success)
            {
                return(false);
            }

            for (var i = 0; i < gc.ObjectCount; i++)
            {
                var curve = gc.Object(i).Curve();
                if (null != curve)
                {
                    curves.Add(curve);
                }
            }

            return(true);
        }
Beispiel #17
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var go = new GetObject();

            go.SetCommandPrompt("Select objects");
            go.GroupSelect = true;
            go.GetMultiple(1, 0);
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            for (var i = 0; i < go.ObjectCount; i++)
            {
                var obj_ref = go.Object(i);
                var obj     = obj_ref.Object();
                if (null != obj)
                {
                    var value = obj.Attributes.GetUserString(SampleCsUserStringData.Key);
                    if (!string.IsNullOrEmpty(value))
                    {
                        RhinoApp.WriteLine(string.Format("<{0}> {1}", SampleCsUserStringData.Key, value));
                    }
                }
            }

            return(Result.Success);
        }
        protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode)
        {
            const ObjectType geometryFilter = ObjectType.Mesh;

            GetObject go = new GetObject();

            go.SetCommandPrompt("Select meshes to compute contacts");
            go.GeometryFilter  = geometryFilter;
            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;

            GetResult res = go.GetMultiple(1, 0);

            if (res != GetResult.Object)
            {
                return(Result.Cancel);
            }

            Rhino.RhinoApp.WriteLine(res.GetType().ToString())

            return(Result.Success);
        }
Beispiel #19
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            using (var go = new GetObject())
            {
                go.SetCommandPrompt("Please select planer shade surfaces");
                go.GeometryFilter  = ObjectType.Surface | ObjectType.Brep;
                go.GroupSelect     = false;
                go.SubObjectSelect = false;
                go.GetMultiple(1, 0);

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

                if (go.Objects().Count() == 0)
                {
                    return(Result.Failure);
                }

                var SelectedObjs = go.Objects();


                //prepare BrepObjects
                var shades = SelectedObjs.ToList();

                //add shades to model
                ConvertToShades(doc, shades);

                return(Result.Success);
            }
        }
Beispiel #20
0
    public static Result MeshVolume(RhinoDoc doc)
    {
        var gm = new GetObject();

        gm.SetCommandPrompt("Select solid meshes for volume calculation");
        gm.GeometryFilter          = ObjectType.Mesh;
        gm.GeometryAttributeFilter = GeometryAttributeFilter.ClosedMesh;
        gm.SubObjectSelect         = false;
        gm.GroupSelect             = true;
        gm.GetMultiple(1, 0);
        if (gm.CommandResult() != Result.Success)
        {
            return(gm.CommandResult());
        }

        double volume       = 0.0;
        double volume_error = 0.0;

        foreach (var obj_ref in gm.Objects())
        {
            if (obj_ref.Mesh() != null)
            {
                var mass_properties = VolumeMassProperties.Compute(obj_ref.Mesh());
                if (mass_properties != null)
                {
                    volume       += mass_properties.Volume;
                    volume_error += mass_properties.VolumeError;
                }
            }
        }

        RhinoApp.WriteLine("Total volume = {0:f} (+/- {1:f})", volume, volume_error);
        return(Result.Success);
    }
Beispiel #21
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var go = new GetObject();

            go.SetCommandPrompt("Select 2, 3, or 4 open curves");
            go.GeometryFilter          = ObjectType.Curve;
            go.GeometryAttributeFilter = GeometryAttributeFilter.OpenCurve;
            go.GetMultiple(2, 4);
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            var curves = go.Objects().Select(o => o.Curve());

            var brep = Brep.CreateEdgeSurface(curves);

            if (brep != null)
            {
                doc.Objects.AddBrep(brep);
                doc.Views.Redraw();
            }

            return(Result.Success);
        }
 protected override Result RunCommand(RhinoDoc doc, RunMode mode)
 {
     // TODO: start here modifying the behaviour of your command.
     //Select objects
     try
     {
         GetObject go = new GetObject();
         go.EnablePreSelect(true, true);
         go.EnablePostSelect(true);
         go.SetCommandPrompt("Super Intersection | Advanced Boolean Intersection:");
         go.GetMultiple(1, 0);
         if (go.ObjectCount > 0)
         {
             RhinoApp.RunScript("_BooleanIntersection", true);
             RhinoApp.RunScript("_SelLast", true);
             RhinoApp.RunScript("_MergeAllFaces", true);
             RhinoApp.RunScript("_ShrinkTrimmedSrf", true);
         }
         return(Result.Success);
     }
     catch
     {
         return(Result.Failure);
     }
 }
Beispiel #23
0
        public override ElementCollection EnterElements(string prompt = "Enter elements")
        {
            GetObject gO = new GetObject();

            gO.SetCustomGeometryFilter(new GetObjectGeometryFilter(FilterHandles));
            //gO.GeometryFilter = ObjectType.Curve;
            gO.SetCommandPrompt(prompt);
            if (gO.GetMultiple(1, 0) == GetResult.Cancel)
            {
                throw new OperationCanceledException("Operation cancelled by user");
            }
            var result = new ElementCollection();

            foreach (ObjRef rObj in gO.Objects())
            {
                if (Host.Instance.Handles.Links.ContainsSecond(rObj.ObjectId))
                {
                    Guid guid = Host.Instance.Handles.Links.GetFirst(rObj.ObjectId);

                    ElementTable elementTable = Core.Instance.ActiveDocument?.Model?.Elements;
                    if (elementTable != null && elementTable.Contains(guid))
                    {
                        Element element = Core.Instance.ActiveDocument?.Model?.Elements[guid];
                        if (element != null)
                        {
                            result.Add(element);
                        }
                    }
                }
            }
            return(result);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            GetObject go = new GetObject();

            go.SetCommandPrompt("Select two curves for planar curve containment test");
            go.GeometryFilter          = ObjectType.Curve;
            go.GeometryAttributeFilter = GeometryAttributeFilter.ClosedCurve;
            go.SubObjectSelect         = false;
            go.GetMultiple(2, 2);
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            Rhino.Geometry.Curve curveA = go.Object(0).Curve();
            Rhino.Geometry.Curve curveB = go.Object(1).Curve();
            if (null == curveA || null == curveB)
            {
                return(Result.Failure);
            }

            Plane planeA, planeB;

            if (!curveA.IsPlanar() || !curveA.TryGetPlane(out planeA))
            {
                RhinoApp.WriteLine("Curve A is not planar.");
                return(Result.Success);
            }

            if (!curveB.IsPlanar() || !curveB.TryGetPlane(out planeB))
            {
                RhinoApp.WriteLine("Curve B is not planar.");
                return(Result.Success);
            }

            double            tol = Rhino.RhinoMath.ZeroTolerance;
            RegionContainment rc  = Curve.PlanarClosedCurveRelationship(curveA, curveB, planeA, tol);

            switch (rc)
            {
            case RegionContainment.Disjoint:
                RhinoApp.WriteLine("There is no common area between the two regions.");
                break;

            case RegionContainment.MutualIntersection:
                RhinoApp.WriteLine("The two curves intersect. No full containment relationship exists.");
                break;

            case RegionContainment.AInsideB:
                RhinoApp.WriteLine("Region bounded by curveA (first curve) is inside of curveB (second curve).");
                break;

            case RegionContainment.BInsideA:
                RhinoApp.WriteLine("Region bounded by curveB (second curve) is inside of curveA (first curve).");
                break;
            }

            return(Result.Success);
        }
Beispiel #25
0
        public static GetObject GetRhinoObjects(string prompt, ObjectType geometryFilter)
        {
            GetObject go = new GetObject();

            go.SetCommandPrompt(prompt);
            go.GeometryFilter  = geometryFilter;
            go.GroupSelect     = false;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;

            bool bHavePreselectedObjects = true;

            for (; ;)
            {
                GetResult res = go.GetMultiple(1, 0);

                if (res == GetResult.Option)
                {
                    go.EnablePreSelect(false, true);
                    continue;
                }

                else if (res != GetResult.Object)
                {
                    return(go);
                }

                if (go.ObjectsWerePreselected)
                {
                    bHavePreselectedObjects = true;
                    go.EnablePreSelect(false, true);
                    continue;
                }

                break;
            }

            if (bHavePreselectedObjects)
            {
                // Normally, pre-selected objects will remain selected, when a
                // command finishes, and post-selected objects will be unselected.
                // This this way of picking, it is possible to have a combination
                // of pre-selected and post-selected. So, to make sure everything
                // "looks the same", lets unselect everything before finishing
                // the command.
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    RhinoObject rhinoObject = go.Object(i).Object();
                    if (null != rhinoObject)
                    {
                        rhinoObject.Select(false);
                    }
                }
            }

            return(go);
        }
Beispiel #26
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            RhinoApp.WriteLine("안녕하세요 방만드는기계 입니다.");

            //
            Polyline outline  = new Polyline();
            Polyline coreLine = new Polyline();
            Polyline landing  = new Polyline();

            GetObject getPolyline = new GetObject();

            getPolyline.SetCommandPrompt("외곽선,코어,랜딩 입력해주세요");
            getPolyline.GeometryFilter          = Rhino.DocObjects.ObjectType.Curve;
            getPolyline.GeometryAttributeFilter = GeometryAttributeFilter.ClosedCurve;
            getPolyline.SubObjectSelect         = false;

            getPolyline.GetMultiple(3, 0);

            if (getPolyline.CommandResult() != Result.Success)
            {
                RhinoApp.WriteLine("달라고!");
                return(getPolyline.CommandResult());
            }
            else
            {
                RhinoApp.WriteLine("입력받았습니다.");
            }

            if (null == getPolyline.Object(0).Curve())
            {
                RhinoApp.WriteLine("없잖아!");
                return(getPolyline.CommandResult());
            }

            List <Polyline> testPoly = new List <Polyline>();

            foreach (var i in getPolyline.Objects())
            {
                testPoly.Add(CurveTools.ToPolyline(i.Curve()));
            }

            outline  = testPoly[0];
            coreLine = testPoly[1];
            landing  = testPoly[2];


            List <Polyline> rooms = Debugger.DebugRoom(outline, coreLine, landing);

            foreach (Polyline i in rooms)
            {
                doc.Objects.AddCurve(i.ToNurbsCurve());
            }

            doc.Views.Redraw();

            RhinoApp.WriteLine("최선을 다했습니다만...");

            return(Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            OptionDouble  amountOption = new OptionDouble(amount, 0.001, 300);
            OptionInteger triesOption  = new OptionInteger(tries, 1, 1000);

            GetObject go = new GetObject();

            go.SetCommandPrompt("Select meshes to Randomize");
            go.AddOptionDouble("Amount", ref amountOption);
            go.AddOptionInteger("Tries", ref triesOption);
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Mesh;

            for (;;)
            {
                GetResult res = go.GetMultiple(1, 0);

                if (res == GetResult.Option)
                {
                    tries  = triesOption.CurrentValue;
                    amount = amountOption.CurrentValue;
                    continue;
                }

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

                break;
            }

            if (go.ObjectCount < 1)
            {
                return(Result.Failure);
            }

            foreach (var obj in go.Objects())
            {
                var rhinoMesh = obj.Mesh();

                if (rhinoMesh == null || !rhinoMesh.IsValid)
                {
                    continue;
                }

                var mesh = GopherUtil.ConvertToD3Mesh(obj.Mesh());

                g3.DMesh3 outputMeshRandom;
                GopherUtil.RandomizeMesh(mesh, out outputMeshRandom, amount, tries);

                var rhinoOutputMeshRandom = GopherUtil.ConvertToRhinoMesh(outputMeshRandom);
                doc.Objects.Replace(obj, rhinoOutputMeshRandom);
            }

            doc.Views.Redraw();

            return(Result.Success);
        }
Beispiel #28
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            int i;

            CurveList selectedcurves = new CurveList();
            int       divnr          = 10;

            Point3d[] divptarray;
            //declares variable as a standard array in .NET, for use with the out overload below.



            // step one, select curves --------------------------

            var gc = new GetObject();

            gc.SetCommandPrompt("Select curves to divide into 10 sections (start+end points added)");
            gc.GeometryFilter = ObjectType.Curve;
            gc.GetMultiple(1, 0);

            if (gc.CommandResult() != Result.Success)
            {
                return(gc.CommandResult());
            }


            //enter the loop

            for (i = 0; i < gc.ObjectCount; i++)
            {
                var curve = gc.Object(i).Curve();
                if (null != curve && !curve.IsShort(RhinoMath.ZeroTolerance))
                {
                    selectedcurves.Add(curve);
                }
                // ADD THE CURVE TO THE CURVES LIST, expanding dynamically through the loop
            }

            if (selectedcurves.Count < 1)
            {
                return(Result.Failure);
            }

            //step 2, divide curves ----------------------------------

            for (i = 0; i < selectedcurves.Count; i++)
            {
                double[] parameters = selectedcurves[i].DivideByCount(divnr, true, out divptarray);

                UsefulFunctions.XDrawPoints(divptarray, doc);

                UsefulFunctions.XDrawCurveTangents(parameters, selectedcurves[i], doc);
            }



            return(Result.Success);
        }
Beispiel #29
0
        public Result AddApertureBySurface(RhinoDoc doc, IEnumerable <ObjRef> rooms)
        {
            //Select window geometry.
            using (var go2 = new GetObject())
            {
                go2.SetCommandPrompt("Please select planer window surfaces");
                go2.GeometryFilter = ObjectType.Surface;
                go2.GroupSelect    = false;
                go2.DisablePreSelect();
                go2.EnableSelPrevious(false);
                go2.SubObjectSelect = false;
                go2.GetMultiple(1, 0);

                if (go2.CommandResult() != Result.Success)
                {
                    return(go2.CommandResult());
                }

                if (go2.Objects().Count() == 0)
                {
                    return(Result.Failure);
                }

                var SelectedObjs = go2.Objects();


                //prepare BrepObjects
                var WinObjs = SelectedObjs.ToList();
                //var room = rooms.First();
                //var roomBrep = room.Brep();

                //match window to room
                var matchedRoomDoors = rooms.AddDoors(WinObjs);

                foreach (var match in matchedRoomDoors)
                {
                    var doors = match.doors;

                    if (!doors.Any())
                    {
                        continue;
                    }

                    foreach (var door in doors)
                    {
                        doc.Objects.Replace(door.id, door.brep);
                    }

                    //Replace the rhino object in order to be able to undo/redo
                    doc.Objects.Replace(match.roomId, match.room);
                    RhinoApp.WriteLine($"{doors.Count} windows have been successfully added to room {match.roomId}");
                }


                return(Result.Success);
            }
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var go = new GetObject();

            go.SetCommandPrompt("Select holes");
            go.GeometryFilter          = ObjectType.BrepLoop;
            go.GeometryAttributeFilter = GeometryAttributeFilter.InnerLoop;
            go.GetMultiple(1, 0);
            if (go.CommandResult() == Result.Success)
            {
                for (var i = 0; i < go.ObjectCount; i++)
                {
                    var obj_ref = go.Object(i);
                    var ci      = obj_ref.GeometryComponentIndex;
                    if (ci.ComponentIndexType != ComponentIndexType.BrepLoop)
                    {
                        return(Result.Failure);
                    }

                    var brep = obj_ref.Brep();
                    if (null == brep)
                    {
                        return(Result.Failure);
                    }

                    var loop = brep.Loops[ci.Index];
                    if (null == loop)
                    {
                        return(Result.Failure);
                    }

                    for (var lti = 0; lti < loop.Trims.Count; lti++)
                    {
                        var ti   = loop.Trims[lti].TrimIndex;
                        var trim = brep.Trims[ti];
                        if (null != trim)
                        {
                            var edge = brep.Edges[trim.Edge.EdgeIndex];
                            if (null != edge)
                            {
                                // TODO: do somethign with edge curve.
                                // In this case, we'll just add a copy to the document.
                                var curve = edge.DuplicateCurve();
                                if (null != curve)
                                {
                                    doc.Objects.AddCurve(curve);
                                }
                            }
                        }
                    }
                }
            }

            doc.Views.Redraw();

            return(Result.Success);
        }