public static Result IsPlanarSurfaceInPlane(RhinoDoc doc)
    {
        ObjRef obj_ref;
        var    rc = RhinoGet.GetOneObject("select surface", true, ObjectType.Surface, out obj_ref);

        if (rc != Result.Success)
        {
            return(rc);
        }
        var surface = obj_ref.Surface();

        Point3d[] corners;
        rc = RhinoGet.GetRectangle(out corners);
        if (rc != Result.Success)
        {
            return(rc);
        }

        var plane = new Plane(corners[0], corners[1], corners[2]);

        var is_or_isnt = " not ";

        if (IsSurfaceInPlane(surface, plane, doc.ModelAbsoluteTolerance))
        {
            is_or_isnt = "";
        }

        RhinoApp.WriteLine("Surface is{0} in plane.", is_or_isnt);
        return(Result.Success);
    }
Esempio n. 2
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Point3d[] corners;
            var       rc = RhinoGet.GetRectangle(out corners);

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

            var plane = new Plane(corners[0], corners[1], corners[2]);

            var plane_surface = new PlaneSurface(
                plane,
                new Interval(0, corners[0].DistanceTo(corners[1])),
                new Interval(0, corners[1].DistanceTo(corners[2]))
                );

            rc = Result.Cancel;
            if (plane_surface.IsValid)
            {
                var layer_name = doc.Layers.GetUnusedLayerName();
                rc = RhinoGet.GetString("Name of layer to create", true, ref layer_name);
                if (rc == Result.Success && !string.IsNullOrEmpty(layer_name))
                {
                    var layer_index = doc.Layers.FindByFullPath(layer_name, -1);
                    if (-1 == layer_index)
                    {
                        layer_index = doc.Layers.Add(layer_name, System.Drawing.Color.Black);
                    }

                    if (layer_index >= 0)
                    {
                        var attribs = doc.CreateDefaultAttributes();
                        attribs.LayerIndex = layer_index;
                        attribs.Name       = layer_name;
                        doc.Objects.AddSurface(plane_surface, attribs);
                        doc.Views.Redraw();
                        rc = Result.Success;
                    }
                }
            }

            return(rc);
        }
Esempio n. 3
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: complete command.

            // get image file
            Image image;
            var   fileDialog = new Rhino.UI.OpenFileDialog
            {
                Filter = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*"
            };

            if (!fileDialog.ShowOpenDialog())
            {
                return(Result.Cancel);
            }

            image = Image.FromFile(fileDialog.FileName);

            // get Dimensions
            var    rc     = RhinoGet.GetRectangle("Specify bounding rectangle", out var corners);
            double width  = corners[1].DistanceTo(corners[0]);
            double height = corners[3].DistanceTo(corners[0]);

            // create material image data
            var plane = Plane.WorldXY;

            plane.Origin = corners[0];
            var data = new MaterialImageData(plane, image, width, height);

            // create custom object
            var mObject = data.GetCustomObject();

            // add custom object to doc
            doc.Objects.AddRhinoObject(mObject, mObject.CurveGeometry);

            // redraw the view
            doc.Views.Redraw();

            // return success
            return(Result.Success);
        }