Ejemplo n.º 1
0
        /// <summary> RunCommandPickPlane is a helper method for picking an existing surface to draw on </summary>
        /// <param name="mRhinoDoc"></param>
        /// <param name="mode"></param>
        /// <returns></returns>
        protected Result RunCommandPickPlane(RhinoDoc mRhinoDoc, RunMode mode)
        {
            //routine for picking an existing surface to draw on

            //please select a plane

            Rhino.DocObjects.ObjectType filter = Rhino.DocObjects.ObjectType.Surface;
            Rhino.DocObjects.ObjRef     objref = null;
            Rhino.Commands.Result       rc     = Rhino.Input.RhinoGet.GetOneObject("Select surface", false, filter, out objref);
            if (rc != Rhino.Commands.Result.Success || objref == null)
            {
                return(rc);
            }

            Rhino.Geometry.Surface refSrf = objref.Surface();
            refSrf.FrameAt(.5, .5, out plane1);

            Point3d  pOrigin = refSrf.PointAt(1, 1);
            Point3d  pY      = refSrf.PointAt(0.5, 1);
            Point3d  pX      = refSrf.PointAt(1, 0.75);
            Vector3d vX      = Rhino.Geometry.Point3d.Subtract(pX, pOrigin);
            Vector3d vY      = Rhino.Geometry.Point3d.Subtract(pY, pOrigin);

            plane1 = new Plane(pOrigin, vX, vY);

            Rhino.DocObjects.RhinoObject rhobj = objref.Object();
            rhobj.Select(false);

            mRhinoDoc.Objects.AddPoint(pOrigin);
            mRhinoDoc.Objects.AddPoint(pX);
            mRhinoDoc.Objects.AddPoint(pY);
            mRhinoDoc.Views.Redraw();

            return(Result.Success);
        }
Ejemplo n.º 2
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.DocObjects.ObjectType filter = Rhino.DocObjects.ObjectType.Mesh;
            Rhino.DocObjects.ObjRef     objref = null;
            Rhino.Commands.Result       rc     = Rhino.Input.RhinoGet.GetOneObject("Select mesh to contour", false, filter, out objref);
            if (rc != Rhino.Commands.Result.Success || objref == null)
            {
                return(rc);
            }

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

            Rhino.Geometry.BoundingBox bbox     = mesh.GetBoundingBox(false);
            Rhino.Geometry.Point3d     start_pt = bbox.Corner(true, true, true);
            Rhino.Geometry.Point3d     end_pt   = bbox.Corner(false, true, true);
            double interval = start_pt.DistanceTo(end_pt) / 10;

            Rhino.Geometry.Curve[] curves = Rhino.Geometry.Mesh.CreateContourCurves(mesh, start_pt, end_pt, interval);
            if (null != curves && curves.Length > 0)
            {
                for (int i = 0; i < curves.Length; i++)
                {
                    doc.Objects.AddCurve(curves[i]);
                }
                doc.Views.Redraw();
            }

            return(Result.Success);
        }
    /// <summary>
    /// Commmand.RunCommand override
    /// </summary>
    protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, RunMode mode)
    {
        Rhino.Commands.Result rc = Rhino.Commands.Result.Success;

        if (!_bIsLoaded)
        {
            string script = ScriptFromResources(ResourceName, Password);
            if (!string.IsNullOrEmpty(script))
            {
                string macro = string.Format("_-RunScript ({0})", script);
                if (RhinoApp.RunScript(macro, false))
                {
                    _bIsLoaded = true;
                }
                else
                {
                    rc = Result.Failure;
                }
            }
        }

        if (rc == Result.Success)
        {
            string macro = string.Format("_-RunScript ({0})", EnglishName);
            RhinoApp.RunScript(macro, false);
        }

        return(rc);
    }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            SampleCsGetMultiplePointsConduit conduit = new SampleCsGetMultiplePointsConduit();

            conduit.Enabled = true;

            Rhino.Commands.Result rc = Result.Nothing;

            Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
            while (true)
            {
                if (0 == conduit.PointCount)
                {
                    gp.SetCommandPrompt("Location of point object.");
                    gp.AcceptNothing(false);
                    gp.ClearCommandOptions();
                }
                else
                {
                    gp.SetCommandPrompt("Location of point object. Press Enter when done");
                    gp.AcceptNothing(true);
                    gp.AddOption("Undo");
                }

                Rhino.Input.GetResult res = gp.Get();

                if (res == Rhino.Input.GetResult.Point)
                {
                    conduit.AddPoint(gp.Point());
                    doc.Views.Redraw();
                }
                else if (res == Rhino.Input.GetResult.Option)
                {
                    conduit.RemoveLastPoint();
                    doc.Views.Redraw();
                }
                else if (res == Rhino.Input.GetResult.Nothing)
                {
                    rc = Rhino.Commands.Result.Success;
                    break;
                }
                else
                {
                    rc = Rhino.Commands.Result.Cancel;
                    break;
                }
            }

            if (rc == Result.Success && conduit.PointCount > 0)
            {
                doc.Objects.AddPoints(conduit.Points);
            }

            conduit.Enabled = false;
            doc.Views.Redraw();

            return(rc);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.Geometry.Line   line;
            Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetLine(out line);
            if (rc == Rhino.Commands.Result.Success)
            {
                Rhino.Geometry.LineCurve crv = new Rhino.Geometry.LineCurve(line);
                SampleCsCustomLineObject obj = new SampleCsCustomLineObject();
                doc.Objects.AddRhinoObject(obj, crv);
                doc.Views.Redraw();
            }

            return(Rhino.Commands.Result.Success);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Rhino calls this function to run the command.
        /// </summary>
        protected override Rhino.Commands.Result RunCommand(Rhino.RhinoDoc doc, Rhino.Commands.RunMode mode)
        {
            const Rhino.DocObjects.ObjectType filter = Rhino.DocObjects.ObjectType.Curve;

            Rhino.DocObjects.ObjRef objref;
            Rhino.Commands.Result   rc = Rhino.Input.RhinoGet.GetOneObject("Select curve to divide", false, filter, out objref);
            if (rc != Rhino.Commands.Result.Success || objref == null)
            {
                return(rc);
            }

            Rhino.Geometry.Curve curve = objref.Curve();
            if (null == curve || curve.IsShort(Rhino.RhinoMath.ZeroTolerance))
            {
                return(Rhino.Commands.Result.Failure);
            }

            int segmentCount = 2;

            rc = Rhino.Input.RhinoGet.GetInteger("Number of segments", false, ref segmentCount, 2, 100);
            if (rc != Rhino.Commands.Result.Success)
            {
                return(rc);
            }

            Rhino.Geometry.Point3d[] points;
            curve.DivideByCount(segmentCount, true, out points);
            if (null == points)
            {
                return(Rhino.Commands.Result.Failure);
            }

            // Create a history record
            Rhino.DocObjects.HistoryRecord history = new Rhino.DocObjects.HistoryRecord(this, _historyVersion);
            WriteHistory(history, objref, segmentCount, points.Length);

            for (int i = 0; i < points.Length; i++)
            {
                doc.Objects.AddPoint(points[i], null, history, false);
            }

            doc.Views.Redraw();

            return(Rhino.Commands.Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.DocObjects.ObjectType filter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.PolysrfFilter;
            Rhino.DocObjects.ObjRef     objref = null;
            Rhino.Commands.Result       rc     = Rhino.Input.RhinoGet.GetOneObject("Select surface or polysurface", false, filter, out objref);
            if (rc != Rhino.Commands.Result.Success || objref == null)
            {
                return(rc);
            }

            Rhino.DocObjects.RhinoObject rhobj = objref.Object();
            Rhino.Geometry.Brep          brep  = objref.Brep();
            if (rhobj == null || brep == null)
            {
                return(Rhino.Commands.Result.Failure);
            }

            rhobj.Select(false);

            System.Collections.Generic.List <Rhino.Geometry.Curve> curves = new System.Collections.Generic.List <Rhino.Geometry.Curve>();
            foreach (Rhino.Geometry.BrepEdge edge in brep.Edges)
            {
                // Find only the naked edges
                if (edge.Valence == Rhino.Geometry.EdgeAdjacency.Naked)
                {
                    Rhino.Geometry.Curve crv = edge.DuplicateCurve();
                    if (null != crv)
                    {
                        curves.Add(crv);
                    }
                }
            }

            double tol = 2.1 * doc.ModelAbsoluteTolerance;

            Rhino.Geometry.Curve[] output = Rhino.Geometry.Curve.JoinCurves(curves, tol);
            for (int i = 0; i < output.Length; i++)
            {
                Guid id = doc.Objects.AddCurve(output[i]);
                doc.Objects.Select(id);
            }

            doc.Views.Redraw();
            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 select the curve with same length", EnglishName);
            double tolerance = 0.001;

            Rhino.Commands.Result rc = Rhino.Commands.Result.Failure;

            using (GetObject getObjectAction = new GetObject())
            {
                getObjectAction.GeometryFilter = ObjectType.Curve;
                getObjectAction.SetCommandPrompt("Please select curves");
                var dblOption = new OptionDouble(tolerance, true, 0);
                getObjectAction.AddOptionDouble("SelectionTolerance", ref dblOption);
                getObjectAction.EnablePreSelect(true, true);
                var    result    = getObjectAction.Get();
                double refLength = 0.0;
                if (result == GetResult.Object)
                {
                    var value = getObjectAction.Object(0);
                    var crv   = value.Curve();
                    if (crv != null)
                    {
                        refLength = crv.GetLength();
                        var objects = doc.Objects.FindByObjectType(ObjectType.Curve);
                        foreach (var obj in objects)
                        {
                            var _curve = (new ObjRef(obj)).Curve();
                            if (Rhino.RhinoMath.EpsilonEquals(_curve.GetLength(), refLength, dblOption.CurrentValue))
                            {
                                obj.Select(true);
                            }
                        }
                        rc = Rhino.Commands.Result.Success;
                    }
                }
            }
            doc.Views.Redraw();
            return(rc);
        }
Ejemplo n.º 9
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.DocObjects.ObjectType filter = Rhino.DocObjects.ObjectType.Hatch;
            Rhino.DocObjects.ObjRef     objref = null;
            Rhino.Commands.Result       rc     = Rhino.Input.RhinoGet.GetOneObject("Select hatch to explode", false, filter, out objref);
            if (rc != Rhino.Commands.Result.Success || objref == null)
            {
                return(rc);
            }

            Rhino.Geometry.Hatch hatch = (Rhino.Geometry.Hatch)objref.Geometry();
            if (null == hatch)
            {
                return(Rhino.Commands.Result.Failure);
            }

            Rhino.Geometry.GeometryBase[] hatch_geom = hatch.Explode();
            if (null != hatch_geom)
            {
                for (int i = 0; i < hatch_geom.Length; i++)
                {
                    Rhino.Geometry.GeometryBase geom = hatch_geom[i];
                    if (null != geom)
                    {
                        switch (geom.ObjectType)
                        {
                        case Rhino.DocObjects.ObjectType.Point:
                        {
                            Rhino.Geometry.Point point = (Rhino.Geometry.Point)geom;
                            if (null != point)
                            {
                                doc.Objects.AddPoint(point.Location);
                            }
                        }
                        break;

                        case Rhino.DocObjects.ObjectType.Curve:
                        {
                            Rhino.Geometry.Curve curve = (Rhino.Geometry.Curve)geom;
                            if (null != curve)
                            {
                                doc.Objects.AddCurve(curve);
                            }
                        }
                        break;

                        case Rhino.DocObjects.ObjectType.Brep:
                        {
                            Rhino.Geometry.Brep brep = (Rhino.Geometry.Brep)geom;
                            if (null != brep)
                            {
                                doc.Objects.AddBrep(brep);
                            }
                        }
                        break;
                        }
                    }
                }
            }

            return(Rhino.Commands.Result.Success);
        }
Ejemplo n.º 10
0
 /// <summary> btnPickOrigin allows user to select origin of drawing plane </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnPickOrigin_Click(object sender, EventArgs e)
 {
     Rhino.Commands.Result result1 = selectPoint();
 }