protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Point3d basePt;
            Result  rc = RhinoGet.GetPoint("Start of line", false, out basePt);

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

            GetPoint gp = new GetPoint();

            gp.SetCommandPrompt("End of line");
            gp.SetBasePoint(basePt, true);
            gp.DrawLineFromPoint(basePt, true);
            gp.DynamicDraw += new EventHandler <GetPointDrawEventArgs>(gp_DynamicDraw);
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            Point3d endPt = gp.Point();

            Rhino.Geometry.Vector3d vector = endPt - basePt;
            if (vector.Length > doc.ModelAbsoluteTolerance)
            {
                Line line = new Line(basePt, endPt);
                doc.Objects.AddLine(line);
                doc.Views.Redraw();
            }

            return(Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Pick a mesh
            ObjRef obj_ref;
            Result rc = RhinoGet.GetOneObject("Select mesh", false, ObjectType.Mesh, out obj_ref);

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

            Rhino.Geometry.Mesh mesh = obj_ref.Mesh();
            if (null == mesh)
            {
                return(Result.Failure);
            }

            // Pick a point that is contrained to the mesh
            GetPoint gp = new GetPoint();

            gp.SetCommandPrompt("Pick point on mesh");
            gp.Constrain(mesh, false);
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            Point3d point = gp.Point();

            doc.Objects.AddPoint(point);
            doc.Views.Redraw();

            return(Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Point3d base_pt;
            var     rc = RhinoGet.GetPoint("Start of line", false, out base_pt);

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

            var gp = new GetPoint();

            gp.SetCommandPrompt("End of line");
            gp.SetBasePoint(base_pt, true);
            gp.DrawLineFromPoint(base_pt, true);
            gp.DynamicDraw += gp_DynamicDraw;
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            var end_pt = gp.Point();
            var vector = end_pt - base_pt;

            if (vector.Length > doc.ModelAbsoluteTolerance)
            {
                var line = new Line(base_pt, end_pt);
                doc.Objects.AddLine(line);
                doc.Views.Redraw();
            }

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

            gp.SetCommandPrompt("Point to draw from");
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            var pt = gp.Point();

            var gd = new GetDirection();

            gd.SetCommandPrompt("Point to draw to");
            gd.SetBasePoint(pt, true);
            gd.DrawArrowFromPoint(pt, true, true);
            gd.Get();
            if (gd.CommandResult() != Result.Success)
            {
                return(gd.CommandResult());
            }

            // TODO...

            return(Result.Success);
        }
Пример #5
0
    public static Result GetAngle(RhinoDoc doc)
    {
        var gp = new GetPoint();

        gp.SetCommandPrompt("Base point");
        gp.Get();
        if (gp.CommandResult() != Result.Success)
        {
            return(gp.CommandResult());
        }
        var base_point = gp.Point();

        gp.SetCommandPrompt("First reference point");
        gp.DrawLineFromPoint(base_point, true);
        gp.Get();
        if (gp.CommandResult() != Result.Success)
        {
            return(gp.CommandResult());
        }
        var first_point = gp.Point();

        double angle_radians;
        var    rc = RhinoGet.GetAngle("Second reference point", base_point, first_point, 0, out angle_radians);

        if (rc == Result.Success)
        {
            RhinoApp.WriteLine("Angle = {0} degrees", RhinoMath.ToDegrees(angle_radians));
        }

        return(rc);
    }
Пример #6
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var gp = new GetPoint();

            gp.SetCommandPrompt("Location of point object");
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            var point = gp.Point();

            var point_id = MooseCommon.Utility.AddPoint(point);

            if (!Equals(point_id, Guid.Empty))
            {
                doc.Views.Redraw();

                var uuid_str = point_id.ToString();
                var str      = $"Identifier of point object is \"{uuid_str}\"";
                MooseCommon.Utility.Print(str);
            }


            var       sphere = new Sphere(Point3d.Origin, 5);
            var       brep   = sphere.ToBrep();
            const int x      = 1;
            const int y      = 2;
            var       rc     = MooseCommon.Utility.ExampleFunction(brep, x, y, out var points, out var lines);

            if (rc > 0)
            {
                foreach (var p in points)
                {
                    doc.Objects.AddPoint(p);
                }
                foreach (var l in lines)
                {
                    doc.Objects.AddLine(l);
                }
                doc.Views.Redraw();
            }


            var polylines = MooseCommon.Utility.ExampleGetPolylines();

            foreach (var pline in polylines)
            {
                doc.Objects.AddPolyline(pline);
            }
            doc.Views.Redraw();

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

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

            var gp = new GetPoint();

            gp.SetCommandPrompt("Point to move from");
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            var from = gp.Point();

            gp.SetCommandPrompt("Point to move to");
            gp.SetBasePoint(from, true);
            gp.DrawLineFromPoint(from, true);
            gp.Get();
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            var to = gp.Point();

            var dir = to - from;

            if (dir.IsTiny(doc.ModelAbsoluteTolerance))
            {
                return(Result.Nothing);
            }

            var xform = Transform.Translation(dir);

            var helper = new SampleCsGripHelper(doc);

            helper.AddGripObjects(go);
            helper.TransformAndUpdate(xform);

            doc.Views.Redraw();

            return(Result.Success);
        }
    public static Result DetermineNormalDirectionOfBrepFace(RhinoDoc doc)
    {
        // select a surface
        var gs = new GetObject();

        gs.SetCommandPrompt("select surface");
        gs.GeometryFilter = ObjectType.Surface;
        gs.DisablePreSelect();
        gs.SubObjectSelect = false;
        gs.Get();
        if (gs.CommandResult() != Result.Success)
        {
            return(gs.CommandResult());
        }
        // get the selected face
        var face = gs.Object(0).Face();

        if (face == null)
        {
            return(Result.Failure);
        }

        // pick a point on the surface.  Constain
        // picking to the face.
        var gp = new GetPoint();

        gp.SetCommandPrompt("select point on surface");
        gp.Constrain(face, false);
        gp.Get();
        if (gp.CommandResult() != Result.Success)
        {
            return(gp.CommandResult());
        }

        // get the parameters of the point on the
        // surface that is clesest to gp.Point()
        double u, v;

        if (face.ClosestPoint(gp.Point(), out u, out v))
        {
            var direction = face.NormalAt(u, v);
            if (face.OrientationIsReversed)
            {
                direction.Reverse();
            }
            RhinoApp.WriteLine(
                string.Format(
                    "Surface normal at uv({0:f},{1:f}) = ({2:f},{3:f},{4:f})",
                    u, v, direction.X, direction.Y, direction.Z));
        }
        return(Result.Success);
    }
Пример #9
0
        public static Result GetSpawn()
        {
            Point3d pt1;

            // string spawn = "0,0,0";

            using (GetPoint getPointAction = new GetPoint())
            {
                getPointAction.SetCommandPrompt("Please select your character's spawn point");
                if (getPointAction.Get() != GetResult.Point)
                {
                    RhinoApp.WriteLine("No spawn point selected");
                    return(getPointAction.CommandResult());
                }
                pt1 = getPointAction.Point();
                //spawn = pt1.ToString();
                string username  = Environment.UserName;
                string directory = String.Format(@"C:\Users\{0}\AppData\Roaming\SecondStudio", username);
                System.IO.Directory.CreateDirectory(directory);
                string path = String.Format(@"C:\Users\{0}\AppData\Roaming\SecondStudio\spawn.xml", username);
                using (XmlWriter writer = XmlWriter.Create(path))
                {
                    writer.WriteStartDocument();
                    writer.WriteStartElement("Spawn");

                    writer.WriteElementString("Location", pt1.ToString());


                    writer.WriteEndElement();
                    writer.WriteEndDocument();
                }
            }
            RhinoApp.WriteLine(pt1.ToString());
            return(Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            GetObject go = new GetObject();

            go.SetCommandPrompt("Select closed curve for seam adjustment");
            go.GeometryFilter          = ObjectType.Curve;
            go.GeometryAttributeFilter = GeometryAttributeFilter.ClosedCurve;
            go.SubObjectSelect         = false;
            go.Get();
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            Curve curve = go.Object(0).Curve();

            if (null == curve)
            {
                return(Result.Failure);
            }

            GetPoint gp = new GetPoint();

            gp.SetCommandPrompt("New seam location");
            gp.Constrain(curve, false);
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            Point3d point = gp.Point();

            Curve  new_curve = curve.DuplicateCurve();
            double t         = Rhino.RhinoMath.UnsetValue;

            if (new_curve.ClosestPoint(point, out t))
            {
                if (new_curve.ChangeClosedCurveSeam(t))
                {
                    doc.Objects.Replace(go.Object(0), new_curve);
                }
            }

            return(Result.Success);
        }
        //this function gets the first point from the user
        private Result GetFirstPoint(ref Point3d pt, Plane pl, bool IsFirstRun)
        {
            using (GetPoint getPointAction = new GetPoint())
            {
                if (IsFirstRun)
                {
                    getPointAction.AddOptionDouble("Width", ref this.width);
                    getPointAction.AddOptionDouble("RailHeight", ref this.railHeight);
                    getPointAction.AddOptionToggle("LeftRail", ref this.leftRail);
                    getPointAction.AddOptionToggle("RightRail", ref this.rightRail);
                }
                if (!IsFirstRun)
                {
                    getPointAction.AddOptionToggle("Landing", ref this.LandingToggle);
                }

                getPointAction.SetCommandPrompt("Begin making stairs. Select the starting point of the run");
                if (!IsFirstRun)
                {
                    getPointAction.Constrain(pl, false);
                }

                while (true)
                {
                    GetResult get_rc = getPointAction.Get();
                    if (getPointAction.CommandResult() != Result.Success)
                    {
                        return(getPointAction.CommandResult());
                    }
                    if (get_rc == GetResult.Point)
                    {
                        pt = getPointAction.Point();
                    }
                    else if (get_rc == GetResult.Option)
                    {
                        continue;
                    }
                    break;
                }

                return(Result.Success);
            }
        }
Пример #12
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            ObjRef[] obj_refs;
            var      rc = RhinoGet.GetMultipleObjects("Select points to move", false, ObjectType.Point, out obj_refs);

            if (rc != Result.Success || obj_refs == null)
            {
                return(rc);
            }

            var gp = new GetPoint();

            gp.SetCommandPrompt("Point to move from");
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }
            var start_point = gp.Point();

            gp.SetCommandPrompt("Point to move to");
            gp.SetBasePoint(start_point, false);
            gp.DrawLineFromPoint(start_point, true);
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }
            var end_point = gp.Point();

            var xform = Transform.Translation(end_point - start_point);

            foreach (var obj_ref in obj_refs)
            {
                doc.Objects.Transform(obj_ref, xform, true);
            }

            doc.Views.Redraw();
            return(Result.Success);
        }
Пример #13
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var gp = new GetPoint();

            gp.SetCommandPrompt("Center of circle");
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            var view = gp.View();

            if (null == view)
            {
                return(Result.Failure);
            }

            var plane = view.ActiveViewport.ConstructionPlane();

            plane.Origin = gp.Point();

            var gr = new GetRadiusPoint(plane);

            gr.SetCommandPrompt("Radius");
            gr.Get();
            if (gr.CommandResult() != Result.Success)
            {
                return(gr.CommandResult());
            }

            if (gr.CalculateCircle(gr.Point()))
            {
                doc.Objects.AddCircle(gr.Circle);
                doc.Views.Redraw();
            }

            return(Result.Success);
        }
Пример #14
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var gp = new GetPoint();

            gp.SetCommandPrompt("Pick a point");
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            var point = gp.Point();

            var format   = string.Format("F{0}", doc.DistanceDisplayPrecision);
            var provider = CultureInfo.InvariantCulture;

            var x = point.X.ToString(format, provider);
            var y = point.Y.ToString(format, provider);
            var z = point.Z.ToString(format, provider);

            RhinoApp.WriteLine("World coordinates: {0},{1},{2}", x, y, z);

            var view = gp.View();

            if (null != view)
            {
                var plane = view.ActiveViewport.ConstructionPlane();
                var xform = Transform.ChangeBasis(Plane.WorldXY, plane);

                point.Transform(xform);

                x = point.X.ToString(format, provider);
                y = point.Y.ToString(format, provider);
                z = point.Z.ToString(format, provider);
                RhinoApp.WriteLine("CPlane coordinates: {0},{1},{2}", x, y, z);
            }

            return(Result.Success);
        }
Пример #15
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var list = new Rhino.Collections.TransformObjectList();
            var rc   = SelectObjects("Select objects to move", list);

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

            var gp = new GetPoint();

            gp.SetCommandPrompt("Point to move from");
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }


            var gt = new GetTranslation();

            gt.SetCommandPrompt("Point to move to");
            gt.SetBasePoint(gp.Point(), true);
            gt.DrawLineFromPoint(gp.Point(), true);
            gt.AddTransformObjects(list);
            gt.GetXform();
            if (gt.CommandResult() != Result.Success)
            {
                return(gt.CommandResult());
            }

            var xform = gt.CalculateTransform(gt.View().ActiveViewport, gt.Point());

            TransformObjects(list, xform, false, false);
            doc.Views.Redraw();
            return(Result.Success);
        }
Пример #16
0
    public static Result Ortho(RhinoDoc doc)
    {
        var gp = new GetPoint();

        gp.SetCommandPrompt("Start of line");
        gp.Get();
        if (gp.CommandResult() != Result.Success)
        {
            return(gp.CommandResult());
        }
        var start_point = gp.Point();

        var original_ortho = ModelAidSettings.Ortho;

        if (!original_ortho)
        {
            ModelAidSettings.Ortho = true;
        }

        gp.SetCommandPrompt("End of line");
        gp.SetBasePoint(start_point, false);
        gp.DrawLineFromPoint(start_point, true);
        gp.Get();
        if (gp.CommandResult() != Result.Success)
        {
            return(gp.CommandResult());
        }
        var end_point = gp.Point();

        if (ModelAidSettings.Ortho != original_ortho)
        {
            ModelAidSettings.Ortho = original_ortho;
        }

        doc.Objects.AddLine(start_point, end_point);
        doc.Views.Redraw();
        return(Result.Success);
    }
    public static Result FindCurveParameterAtPoint(RhinoDoc doc)
    {
        Rhino.DocObjects.ObjRef objref;
        var rc = RhinoGet.GetOneObject("Select curve", true, ObjectType.Curve, out objref);

        if (rc != Result.Success)
        {
            return(rc);
        }
        var curve = objref.Curve();

        if (curve == null)
        {
            return(Result.Failure);
        }

        var gp = new GetPoint();

        gp.SetCommandPrompt("Pick a location on the curve");
        gp.Constrain(curve, false);
        gp.Get();
        if (gp.CommandResult() != Result.Success)
        {
            return(gp.CommandResult());
        }

        var    point = gp.Point();
        double closest_point_param;

        if (curve.ClosestPoint(point, out closest_point_param))
        {
            RhinoApp.WriteLine("point: ({0}), parameter: {1}", point, closest_point_param);
            doc.Objects.AddPoint(point);
            doc.Views.Redraw();
        }
        return(Result.Success);
    }
Пример #18
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var gp = new GetPoint();

            string prompt;

            prompt = "select a point";

            gp.SetCommandPrompt(prompt);

            gp.Get();

            Result res = gp.CommandResult();

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

            var point = gp.Point();

            var format   = string.Format("F{0}", doc.DistanceDisplayPrecision);
            var provider = System.Globalization.CultureInfo.InvariantCulture;

            var x = point.X.ToString(format);
            var y = point.Y.ToString(format);
            var z = point.Z.ToString(format);

            RhinoApp.Write("World coordinates: {0},{1},{2}" + Environment.NewLine, x, y, z);

            double number = 0.56;

            RhinoApp.WriteLine(number.ToString("F5", provider));


            return(Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Loop loop = new Loop();

            loop.Run(doc);

            return(Result.Success);

            // TODO: start here modifying the behaviour of your command.
            // ---
            RhinoApp.WriteLine("The {0} command will add a line right now.", EnglishName);

            Point3d pt0;

            using (GetPoint getPointAction = new GetPoint())
            {
                getPointAction.SetCommandPrompt("Please select the start point");
                if (getPointAction.Get() != GetResult.Point)
                {
                    RhinoApp.WriteLine("No start point was selected.");
                    return(getPointAction.CommandResult());
                }
                pt0 = getPointAction.Point();
            }

            Point3d pt1;

            using (GetPoint getPointAction = new GetPoint())
            {
                getPointAction.SetCommandPrompt("Please select the end point");
                getPointAction.SetBasePoint(pt0, true);
                getPointAction.DynamicDraw +=
                    (sender, e) => e.Display.DrawLine(pt0, e.CurrentPoint, System.Drawing.Color.DarkRed);
                if (getPointAction.Get() != GetResult.Point)
                {
                    RhinoApp.WriteLine("No end point was selected.");
                    return(getPointAction.CommandResult());
                }
                pt1 = getPointAction.Point();
            }

            doc.Objects.AddLine(pt0, pt1);
            doc.Views.Redraw();
            RhinoApp.WriteLine("The {0} command added one line to the document.", EnglishName);

            // ---

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

            gp.SetCommandPrompt("Center point");
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }
            var center_point = gp.Point();

            if (center_point == Point3d.Unset)
            {
                return(Result.Failure);
            }

            var gcp = new GetCircleRadiusPoint(center_point);

            gcp.SetCommandPrompt("Radius");
            gcp.ConstrainToConstructionPlane(false);
            gcp.SetBasePoint(center_point, true);
            gcp.DrawLineFromPoint(center_point, true);
            gcp.Get();
            if (gcp.CommandResult() != Result.Success)
            {
                return(gcp.CommandResult());
            }

            var radius = center_point.DistanceTo(gcp.Point());
            var cplane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();

            doc.Objects.AddCircle(new Circle(cplane, center_point, radius));
            doc.Views.Redraw();
            return(Result.Success);
        }
Пример #21
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Point3d pt0;

            using (GetPoint getPointAction = new GetPoint())
            {
                getPointAction.SetCommandPrompt("Please select the plane origin.");

                if (getPointAction.Get() != GetResult.Point)
                {
                    RhinoApp.WriteLine("No plane origin was selected.");
                    return(getPointAction.CommandResult());
                }
                pt0 = getPointAction.Point();
            }

            Point3d pt1;

            using (GetPoint getPointAction = new GetPoint())
            {
                getPointAction.SetCommandPrompt("Please select a point on the new X-axis.");
                if (getPointAction.Get() != GetResult.Point)
                {
                    RhinoApp.WriteLine("No point was selected.");
                    return(getPointAction.CommandResult());
                }
                pt1 = getPointAction.Point();
            }

            Point3d pt2;

            using (GetPoint getPointAction = new GetPoint())
            {
                getPointAction.SetCommandPrompt("Please select a point on the new Y-axis.");
                if (getPointAction.Get() != GetResult.Point)
                {
                    RhinoApp.WriteLine("No point was selected.");
                    return(getPointAction.CommandResult());
                }
                pt2 = getPointAction.Point();
            }

            Plane plane = new Plane(pt0, pt1, pt2);

            RNNPlugin.Instance.rnn.SetPlane(plane);
            return(Result.Success);
        }
Пример #22
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            ObjRef objref;
            var    rc = RhinoGet.GetOneObject("Select object to move", false, ObjectType.AnyObject, out objref);

            if (rc != Result.Success)
            {
                return(rc);
            }
            if (null == objref)
            {
                return(Result.Failure);
            }

            Point3d first_point;

            rc = RhinoGet.GetPoint("Point to move from", false, out first_point);
            if (rc != Result.Success)
            {
                return(rc);
            }

            var gp = new GetPoint();

            gp.SetCommandPrompt("Point to move to");
            gp.SetBasePoint(first_point, true);
            gp.DrawLineFromPoint(first_point, true);
            gp.Get();
            rc = gp.CommandResult();
            if (rc != Result.Success)
            {
                return(rc);
            }

            var second_point = gp.Point();

            var dir = second_point - first_point;

            if (dir.Length > RhinoMath.ZeroTolerance)
            {
                var xform = Transform.Translation(dir);
                doc.Objects.Transform(objref, xform, true);
                doc.Views.Redraw();
            }

            return(rc);
        }
        protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode)
        {
#if IncludeSample
            // TODO: start here modifying the behaviour of your command.
            // ---
            RhinoApp.WriteLine("The {0} command will add a line right now.", EnglishName);

            Point3d pt0;
            using (GetPoint getPointAction = new GetPoint())
            {
                getPointAction.SetCommandPrompt("Please select the start point");
                if (getPointAction.Get() != GetResult.Point)
                {
                    RhinoApp.WriteLine("No start point was selected.");
                    return(getPointAction.CommandResult());
                }
                pt0 = getPointAction.Point();
            }

            Point3d pt1;
            using (GetPoint getPointAction = new GetPoint())
            {
                getPointAction.SetCommandPrompt("Please select the end point");
                getPointAction.SetBasePoint(pt0, true);
                getPointAction.DrawLineFromPoint(pt0, true);
                if (getPointAction.Get() != GetResult.Point)
                {
                    RhinoApp.WriteLine("No end point was selected.");
                    return(getPointAction.CommandResult());
                }
                pt1 = getPointAction.Point();
            }

            doc.Objects.AddLine(pt0, pt1);
            doc.Views.Redraw();
            RhinoApp.WriteLine("The {0} command added one line to the document.", EnglishName);


            return(Result.Success);
#else
            // TODO: start here modifying the behaviour of your command.

            return(Result.Success);
#endif
        }
Пример #24
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)                                    // всё происходит здесь внутри
        {
            // TODO: start here modifying the behaviour of your command.
            // ---
            RhinoApp.WriteLine("The {0} command will add a line right now.", EnglishName);                  // сообщение в командной строке о том что команда запущена и что она будет делать
                                                                                                            //
            Point3d pt0;                                                                                    // декларируем новую переменную точка (начало линии)

            using (GetPoint getPointAction = new GetPoint())                                                // ??
            {                                                                                               //
                getPointAction.SetCommandPrompt("Please select the start point");                           // призыв к действию в командной строке (жирным)
                if (getPointAction.Get() != GetResult.Point)                                                // что делать если точкка не выбрана но был нажет Enter
                {                                                                                           //
                    RhinoApp.WriteLine("No start point was selected.");                                     // если точкка не выбрана но был нажет Enter, то написать это в командной строке
                    return(getPointAction.CommandResult());                                                 // ??
                }                                                                                           //
                pt0 = getPointAction.Point();                                                               // присвоить для переменной pt1 только что выбранную точку
            }

            Point3d pt1;                                                                                    // декларируе новую переменную точка ( конец линии)

            using (GetPoint getPointAction = new GetPoint())
            {                                                                                               //
                getPointAction.SetCommandPrompt("Please select the end point");
                getPointAction.SetBasePoint(pt0, true);
                getPointAction.DynamicDraw +=
                    (sender, e) => e.Display.DrawLine(pt0, e.CurrentPoint, System.Drawing.Color.DarkRed);
                if (getPointAction.Get() != GetResult.Point)                                                // если точкка не выбрана но был нажет Enter
                {
                    RhinoApp.WriteLine("No end point was selected.");
                    return(getPointAction.CommandResult());
                }
                pt1 = getPointAction.Point();                                                               // присвоить для переменной pt1 только что выбранную точку
            }

            doc.Objects.AddLine(pt0, pt1);
            doc.Views.Redraw();
            RhinoApp.WriteLine("The {0} command added one line to the document.", EnglishName);             // сообщение в командную строку что всё готово

            // ---

            return(Result.Success);
        }
        protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode)
        {
            // TODO: start here modifying the behaviour of your command.
            // ---
            RhinoApp.WriteLine("The {0} command will add a line right now.", EnglishName);

            Point3d pt0;

            using (GetPoint getPointAction = new GetPoint())
            {
                getPointAction.SetCommandPrompt("Please select the start point");
                if (getPointAction.Get() != GetResult.Point)
                {
                    RhinoApp.WriteLine("No start point was selected.");
                    return(getPointAction.CommandResult());
                }
                pt0 = getPointAction.Point();
            }

            Point3d pt1;

            using (GetPoint getPointAction = new GetPoint())
            {
                getPointAction.SetCommandPrompt("Please select the end point");
                getPointAction.SetBasePoint(pt0, true);
                getPointAction.DrawLineFromPoint(pt0, true);
                if (getPointAction.Get() != GetResult.Point)
                {
                    RhinoApp.WriteLine("No end point was selected.");
                    return(getPointAction.CommandResult());
                }
                pt1 = getPointAction.Point();
            }
            Rhino.Geometry.Line line1 = new Line(pt0, pt1);
            doc.Objects.AddLine(line1);
            doc.Views.Redraw();
            RhinoApp.WriteLine("The {0} command added one line to the document.", EnglishName);
            RhinoApp.WriteLine("The distance between the two points is {0} {1}.", line1.Length, doc.ModelUnitSystem.ToString().ToLower());

            return(Result.Success);
        }
Пример #26
0
        public static Result GetOrigin()
        {
            Point3d pt0;
            //string origin = "0,0,0";
            EventModel _event = new EventModel();

            using (GetPoint getPointAction = new GetPoint())
            {
                getPointAction.SetCommandPrompt("Please select your project's origin point");
                if (getPointAction.Get() != GetResult.Point)
                {
                    RhinoApp.WriteLine("No origin point selected");
                    return(getPointAction.CommandResult());
                }
                pt0           = getPointAction.Point();
                _event.Origin = pt0.ToString();

                string username  = Environment.UserName;
                string directory = String.Format(@"C:\Users\{0}\AppData\Roaming\SecondStudio", username);
                System.IO.Directory.CreateDirectory(directory);
                string path = String.Format(@"C:\Users\{0}\AppData\Roaming\SecondStudio\origin.xml", username);
                using (XmlWriter writer = XmlWriter.Create(path))
                {
                    writer.WriteStartDocument();
                    writer.WriteStartElement("Origin");

                    writer.WriteElementString("Location", pt0.ToString());


                    writer.WriteEndElement();
                    writer.WriteEndDocument();
                }
            }



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

            go.SetCommandPrompt("Select curve to split");
            go.GeometryFilter          = ObjectType.Curve;
            go.GeometryAttributeFilter = GeometryAttributeFilter.OpenCurve;
            go.SubObjectSelect         = false;
            go.Get();
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            ObjRef      object_ref = go.Object(0);
            RhinoObject rh_object  = object_ref.Object();
            Curve       curve      = object_ref.Curve();

            if (null == rh_object || null == curve)
            {
                return(Result.Failure);
            }

            GetPoint gp = new GetPoint();

            gp.SetCommandPrompt("Point on curve to split at");
            gp.Constrain(curve, false);
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            Point3d point = gp.Point();
            double  t     = Rhino.RhinoMath.UnsetValue;

            if (!curve.ClosestPoint(point, out t))
            {
                return(Result.Failure);
            }

            List <double> curve_t = new List <double>(3);

            curve_t.Add(curve.Domain.Min);
            curve_t.Add(curve.Domain.Max);
            curve_t.Add(t);
            curve_t.Sort();

            List <double> culled_t = curve_t.Distinct().ToList();

            if (culled_t.Count < 3)
            {
                return(Result.Nothing);
            }

            ObjectAttributes attributes = rh_object.Attributes.Duplicate();

            attributes.ObjectId = Guid.Empty;

            for (int i = 0; i < culled_t.Count - 1; i++)
            {
                Interval domain = new Interval(culled_t[i], culled_t[i + 1]);
                if (curve.Domain.IncludesInterval(domain))
                {
                    Curve trim = curve.Trim(domain);
                    if (null != trim)
                    {
                        doc.Objects.Add(trim, attributes);
                    }
                }
            }

            doc.Objects.Delete(object_ref, false);
            doc.Views.Redraw();

            return(Result.Success);
        }
        /// <summary>
        /// Runs the command
        /// </summary>
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Select objects to orient
            var go = new GetObject();

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

            // Point to orient from
            var gp = new GetPoint();

            gp.SetCommandPrompt("Point to orient from");
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            // Define source plane
            var view = gp.View();

            if (view == null)
            {
                view = doc.Views.ActiveView;
                if (view == null)
                {
                    return(Result.Failure);
                }
            }

            var plane = view.ActiveViewport.ConstructionPlane();

            plane.Origin = gp.Point();

            // Curve to orient on
            var gc = new GetObject();

            gc.SetCommandPrompt("Curve to orient on");
            gc.GeometryFilter = ObjectType.Curve;
            gc.EnablePreSelect(false, true);
            gc.DeselectAllBeforePostSelect = false;
            gc.Get();
            if (gc.CommandResult() != Result.Success)
            {
                return(gc.CommandResult());
            }

            var objref = gc.Object(0);
            var obj    = objref.Object();
            var curve  = objref.Curve();

            if (obj == null || curve == null)
            {
                return(Result.Failure);
            }

            // Unselect curve
            obj.Select(false);

            // Point on surface to orient to
            var gx = new GetOrientPerpendicularPoint(curve, plane, go.Object(0).Object());

            gx.SetCommandPrompt("New base point on curve");
            gx.Get();
            if (gx.CommandResult() != Result.Success)
            {
                return(gx.CommandResult());
            }

            // One final calculation
            var xform = new Transform(1);

            if (gx.CalculateTransform(gx.View().ActiveViewport, gx.Point(), ref xform))
            {
                doc.Objects.Transform(go.Object(0).Object(), xform, true);
                doc.Views.Redraw();
            }

            return(Result.Success);
        }
Пример #29
0
        protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode)
        {
            var dirname = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            string[] pathComponent = new string[] { dirname.ToString(), @"common_paper_sizes.json" };
            var      jsonPath      = Path.Combine(pathComponent);

            GetPoint gp   = new GetPoint();
            string   text = System.IO.File.ReadAllText(jsonPath);

            gp.SetCommandPrompt("Set Origin of Paper Rectangle");

            OptionToggle boolOption = new OptionToggle(false, "Off", "On");

            gp.AddOptionToggle("Portrait", ref boolOption);

            var listNames  = new List <string>();
            var listValues = new List <Point2d>();



            List <Paper> papers = JsonConvert.DeserializeObject <List <Paper> >(text);
            //foreach(var paper in papers)
            //{
            var count = 0;

            foreach (var format in papers[0].formats)
            {
                var num = int.Parse(Regex.Match(format.name, @"\d+").Value);

                if (num < 6 && !format.name.Contains("C"))
                {
                    listNames.Add(format.name);
                    listValues.Add(new Point2d(format.size.mm[0], format.size.mm[1]));
                    count++;
                }
            }

            //}
            var listNamesArr = listNames.ToArray();
            int listIndex    = 0;
            int opList       = gp.AddOptionList("PaperType", listNamesArr, listIndex);

            while (true)
            {
                // perform the get operation. This will prompt the user to input a point, but also
                // allow for command line options defined above
                Rhino.Input.GetResult get_rc = gp.Get();
                if (gp.CommandResult() != Rhino.Commands.Result.Success)
                {
                    return(gp.CommandResult());
                }

                if (get_rc == Rhino.Input.GetResult.Point)
                {
                    var plane = doc.Views.ActiveView.ActiveViewport.GetConstructionPlane().Plane;
                    plane.Origin = gp.Point();
                    var item       = listValues[listIndex];
                    var isPortrait = boolOption.CurrentValue;
                    var rect       = new Rectangle3d(plane, isPortrait ? item.X : item.Y, isPortrait ? item.Y : item.X);
                    var attr       = new Rhino.DocObjects.ObjectAttributes();
                    attr.Name       = listNames[listIndex];
                    attr.LayerIndex = doc.Layers.CurrentLayerIndex;
                    doc.Objects.AddRectangle(rect, attr);
                    doc.Views.Redraw();
                }
                else if (get_rc == Rhino.Input.GetResult.Option)
                {
                    if (gp.OptionIndex() == opList)
                    {
                        listIndex = gp.Option().CurrentListOptionIndex;
                    }
                    continue;
                }
                break;
            }
            return(Rhino.Commands.Result.Success);
        }
Пример #30
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            ObjRef obj_ref;

            const string     prompt      = "Select curve to edit";
            const ObjectType object_type = ObjectType.Curve;

            Result res = RhinoGet.GetOneObject(prompt, false, object_type, out obj_ref);

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

            Curve crv = obj_ref.Curve();

            if (null == crv)
            {
                return(Result.Failure);
            }

            GetPoint gp = new GetPoint();

            gp.SetCommandPrompt("Start point for deletion");
            gp.Constrain(crv, false);
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            double t0      = RhinoMath.UnsetValue;
            Curve  out_crv = gp.PointOnCurve(out t0);

            if (null == out_crv)
            {
                return(Result.Failure);
            }

            gp.SetCommandPrompt("End point for deletion");
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            double t1 = RhinoMath.UnsetValue;

            out_crv = gp.PointOnCurve(out t1);
            if (null == out_crv)
            {
                return(Result.Failure);
            }

            if (Math.Abs(t1 - t0) < RhinoMath.ZeroTolerance)
            {
                return(Result.Nothing);
            }

            Interval range = new Interval(t0, t1);

            if (!crv.IsClosed && range.IsDecreasing)
            {
                range.Swap();
            }

            Curve sub_crv = crv.Trim(crv.Domain.Min, range.Min);

            if (null != sub_crv)
            {
                doc.Objects.AddCurve(sub_crv);
            }

            sub_crv = crv.Trim(range.Max, crv.Domain.Max);
            if (null != sub_crv)
            {
                doc.Objects.AddCurve(sub_crv);
            }

            doc.Objects.Delete(obj_ref, true);

            doc.Views.Redraw();

            return(Result.Success);
        }