public static Result SetRhinoPageViewWidthAndHeight(RhinoDoc doc)
    {
        var width       = 1189;
        var height      = 841;
        var page_views  = doc.Views.GetPageViews();
        int page_number = (page_views == null) ? 1 : page_views.Length + 1;
        var pageview    = doc.Views.AddPageView(string.Format("A0_{0}", page_number), width, height);

        int new_width = width;
        var rc        = RhinoGet.GetInteger("new width", false, ref new_width);

        if (rc != Result.Success || new_width <= 0)
        {
            return(rc);
        }

        int new_height = height;

        rc = RhinoGet.GetInteger("new height", false, ref new_height);
        if (rc != Result.Success || new_height <= 0)
        {
            return(rc);
        }

        pageview.PageWidth  = new_width;
        pageview.PageHeight = new_height;
        doc.Views.Redraw();
        return(Result.Success);
    }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var data_table = SampleCsUserDataPlugIn.Instance.SimpleDocumentDataTable;

            if (0 == data_table.Count)
            {
                var number = 6;
                var rc     = RhinoGet.GetInteger("Number of data objects to create", true, ref number, 1, 100);
                if (rc != Result.Success)
                {
                    return(rc);
                }

                for (var i = 0; i < number; i++)
                {
                    data_table.Add(new SampleCsSimpleDocumentData());
                }
            }

            for (var i = 0; i < data_table.Count; i++)
            {
                RhinoApp.WriteLine("Data[{0}] = {1}", i, data_table[i].Value);
            }

            return(Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var width       = 1189;
            var height      = 841;
            var page_views  = doc.Views.GetPageViews();
            int page_number = (page_views == null) ? 1 : page_views.Length + 1;
            var pageview    = doc.Views.AddPageView(string.Format("A0_{0}", page_number), width, height);

            int new_width = width;
            var rc        = RhinoGet.GetInteger("new width", false, ref new_width);

            if (rc != Result.Success || new_width <= 0)
            {
                return(rc);
            }

            int new_height = height;

            rc = RhinoGet.GetInteger("new height", false, ref new_height);
            if (rc != Result.Success || new_height <= 0)
            {
                return(rc);
            }

            pageview.PageWidth  = new_width;
            pageview.PageHeight = new_height;
            doc.Views.Redraw();
            return(Result.Success);
        }
    public static Result NurbsSurfaceIncreaseDegree(RhinoDoc doc)
    {
        ObjRef obj_ref;
        var    rc = RhinoGet.GetOneObject(
            "Select surface", false, ObjectType.Surface, out obj_ref);

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

        if (surface == null)
        {
            return(Result.Failure);
        }
        var nurbs_surface = surface.ToNurbsSurface();

        int new_u_degree = -1;

        rc = RhinoGet.GetInteger(string.Format("New U degree <{0}...11>", nurbs_surface.Degree(0)), true, ref new_u_degree,
                                 nurbs_surface.Degree(0), 11);
        if (rc != Result.Success)
        {
            return(rc);
        }

        int new_v_degree = -1;

        rc = RhinoGet.GetInteger(string.Format("New V degree <{0}...11>", nurbs_surface.Degree(1)), true, ref new_v_degree,
                                 nurbs_surface.Degree(1), 11);
        if (rc != Result.Success)
        {
            return(rc);
        }

        rc = Result.Failure;
        if (nurbs_surface.IncreaseDegreeU(new_u_degree))
        {
            if (nurbs_surface.IncreaseDegreeV(new_v_degree))
            {
                if (doc.Objects.Replace(obj_ref.ObjectId, nurbs_surface))
                {
                    rc = Result.Success;
                }
            }
        }

        RhinoApp.WriteLine("Result: {0}", rc.ToString());
        doc.Views.Redraw();
        return(rc);
    }
Exemple #5
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: complete command.
            int stepSize = 100;

            RhinoGet.GetInteger("Step Size", true, ref stepSize);

            DrawRandomPolyline(stepSize, doc);
            return(Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            //GET DATA FROM THE USER

            //Select multiple points
            ObjRef[]       obj_refs;
            List <Point3d> finalPts = new List <Point3d>();

            var rc = RhinoGet.GetMultipleObjects("Select point", false, ObjectType.Point, out obj_refs);

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

            foreach (var o_ref in obj_refs)
            {
                var point = o_ref.Point();
                finalPts.Add(point.Location);
            }

            doc.Objects.UnselectAll();


            int depth = 0;
            var rc1   = RhinoGet.GetInteger("The Depth of the Snowflake?", false, ref depth, 0, 5);

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

            double radius = 10;
            var    rc2    = RhinoGet.GetNumber("The size of the Snowflake?", false, ref radius);

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

            //CREATE SNOWFLAKES FOR EACH SELECTED POINT AND DEPTH AND RADIUS
            foreach (Point3d pt in finalPts)
            {
                //STEP 1 - Create the initial triangle (just a list of 3 points)
                List <Point3d> triangle = GenerateSnowflakeTriangle(pt, radius);

                //STEP 2 - FROM TRIANGLE TO SNOWFLAKE
                List <Point3d> snowflake = GenerateSnowflake(triangle, depth, doc);
            }


            return(Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            RhinoApp.WriteLine("The {0} command will run now", EnglishName);

            int after = 10;

            RhinoGet.GetInteger("Disable Autosave for: (minutes):", true, ref after);

            FileSettings.AutoSaveEnabled = false;

            RhinoApp.WriteLine("Disabling Autosave for {0} minutes", after);

            enableAutosave(after);

            return(Result.Success);
        }
Exemple #8
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            ObjRef obj_ref;
            var    rc = RhinoGet.GetOneObject(
                "Select curve", false, ObjectType.Curve, out obj_ref);

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

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

            int new_degree = -1;

            rc = RhinoGet.GetInteger(string.Format("New degree <{0}...11>", nurbs_curve.Degree), true, ref new_degree,
                                     nurbs_curve.Degree, 11);
            if (rc != Result.Success)
            {
                return(rc);
            }

            rc = Result.Failure;
            if (nurbs_curve.IncreaseDegree(new_degree))
            {
                if (doc.Objects.Replace(obj_ref.ObjectId, nurbs_curve))
                {
                    rc = Result.Success;
                }
            }

            RhinoApp.WriteLine("Result: {0}", rc.ToString());
            doc.Views.Redraw();
            return(rc);
        }
Exemple #9
0
    public static Result DivideCurveBySegments(RhinoDoc doc)
    {
        const ObjectType filter = ObjectType.Curve;
        ObjRef           objref;
        var rc = RhinoGet.GetOneObject("Select curve to divide", false, filter, out objref);

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

        var curve = objref.Curve();

        if (curve == null || curve.IsShort(RhinoMath.ZeroTolerance))
        {
            return(Result.Failure);
        }

        var segment_count = 2;

        rc = RhinoGet.GetInteger("Divide curve into how many segments?", false, ref segment_count);
        if (rc != Result.Success)
        {
            return(rc);
        }

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

        foreach (var point in points)
        {
            doc.Objects.AddPoint(point);
        }

        doc.Views.Redraw();
        return(Result.Success);
    }
Exemple #10
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            RhinoApp.WriteLine("The {0} command will run now", EnglishName);

            ObjectType filter  = ObjectType.Curve;
            int        percent = 50;
            int        degree  = 3;

            RhinoGet.GetInteger("Enter the percentage you want to reduce the curves by (1-100)", true, ref percent);
            double reduce = ((double)percent) / 100;

            RhinoGet.GetInteger("Enter the new curve degree", true, ref degree);

            GetObject go = new GetObject();

            go.SetCommandPrompt("Select curves you want to reduce");
            go.GeometryFilter = filter;
            go.GroupSelect    = true;

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

            for (int i = 0; i < go.ObjectCount; i++)
            {
                CurveObject curObj           = (CurveObject)go.Object(i).Object();
                Curve       curCurve         = curObj.CurveGeometry;
                NurbsCurve  curNurbsCurve    = curCurve.ToNurbsCurve();
                int         curControlPoints = curNurbsCurve.Points.Count;
                int         newPoints        = Convert.ToInt32(curControlPoints * reduce);
                Curve       rebuiltCurve     = curCurve.Rebuild(newPoints, degree, false);
                doc.Objects.Add(rebuiltCurve, curObj.Attributes);
                doc.Objects.Delete(curObj);
            }

            doc.Views.Redraw();
            RhinoApp.WriteLine("The curves were rebuilt");

            return(Result.Success);
        }
    public static Result LockLayer(RhinoDoc doc)
    {
        string layer_name = "";
        var    rc         = RhinoGet.GetString("Name of layer to lock", true, ref layer_name);

        if (rc != Result.Success)
        {
            return(rc);
        }
        if (String.IsNullOrWhiteSpace(layer_name))
        {
            return(Result.Nothing);
        }

        // because of sublayers it's possible that mone than one layer has the same name
        // so simply calling doc.Layers.Find(layerName) isn't good enough.  If "layerName" returns
        // more than one layer then present them to the user and let him decide.
        var matching_layers = (from layer in doc.Layers
                               where layer.Name == layer_name
                               select layer).ToList <Rhino.DocObjects.Layer>();

        Rhino.DocObjects.Layer layer_to_lock = null;
        if (matching_layers.Count == 0)
        {
            RhinoApp.WriteLine("Layer \"{0}\" does not exist.", layer_name);
            return(Result.Nothing);
        }
        else if (matching_layers.Count == 1)
        {
            layer_to_lock = matching_layers[0];
        }
        else if (matching_layers.Count > 1)
        {
            for (int i = 0; i < matching_layers.Count; i++)
            {
                RhinoApp.WriteLine("({0}) {1}", i + 1, matching_layers[i].FullPath.Replace("::", "->"));
            }
            int selected_layer = -1;
            rc = RhinoGet.GetInteger("which layer?", true, ref selected_layer);
            if (rc != Result.Success)
            {
                return(rc);
            }
            if (selected_layer > 0 && selected_layer <= matching_layers.Count)
            {
                layer_to_lock = matching_layers[selected_layer - 1];
            }
            else
            {
                return(Result.Nothing);
            }
        }

        if (layer_to_lock == null)
        {
            return(Result.Nothing);
        }

        if (!layer_to_lock.IsLocked)
        {
            layer_to_lock.IsLocked = true;
            layer_to_lock.CommitChanges();
            return(Result.Success);
        }
        else
        {
            RhinoApp.WriteLine("layer {0} is already locked.", layer_to_lock.FullPath);
            return(Result.Nothing);
        }
    }
Exemple #12
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Mesh   m1, m2;
            ObjRef objref1, objref2;
            Result res = Result.Nothing;

            res = RhinoGet.GetOneObject("Select first mesh", false, ObjectType.Mesh, out objref1);
            if (res != Result.Success)
            {
                return(res);
            }

            m1 = objref1.Mesh();
            if (m1 == null)
            {
                return(Result.Failure);
            }

            RhinoApp.WriteLine("Got Mesh1 with {0} verts and {1} faces.", m1.Vertices.Count, m1.Faces.Count);

            // De-select first mesh...

            RhinoObject rhinoObject = objref1.Object();

            if (null != rhinoObject)
            {
                rhinoObject.Select(false);
            }



            res = RhinoGet.GetOneObject("Select second mesh", false, ObjectType.Mesh, out objref2);

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

            m2 = objref2.Mesh();
            if (m2 == null)
            {
                return(Result.Failure);
            }

            RhinoApp.WriteLine("Got Mesh2 with {0} verts and {1} faces.", m2.Vertices.Count, m2.Faces.Count);


            int option = 0;

            res = RhinoGet.GetInteger("Union (0), Intersection (1), AMinusB (2), BMinusA (3), SymmetricalDifferent (4), All (5)", false, ref option);
            RhinoApp.WriteLine("Operation {0} selected.", ((CarveRC.Operations)(option)).ToString());

            if (option < 0 || option > 5)
            {
                RhinoApp.WriteLine("Invalid input value for Carve operation.");
                return(Result.Failure);
            }

            Mesh result = CarveRC.CarveOps.PerformCSG(m1, m2, (CarveRC.Operations)option);

            RhinoApp.WriteLine("Performed Carve operation. New mesh has {0} verts and {1} faces.", result.Vertices.Count, result.Faces.Count);

            doc.Objects.AddMesh(result);
            doc.Views.Redraw();

            return(Result.Success);
        }
Exemple #13
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            int  transFactor = 3;
            int  index       = 0;
            Mesh seed        = new Mesh();

            var rc = RhinoGet.GetInteger("Select seed value between 1 and 5", false, ref index, 1, 5);

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

            switch (index)
            {
            case 1:
                seed = new Octahedron();
                break;

            case 2:
                seed = new Icosahedron();
                break;

            case 3:
                seed = new Tetrahedron();
                break;

            case 4:
                seed = new Cube();
                break;

            case 5:
                RhinoApp.WriteLine($"{index} not implemented!");
                return(Result.Failure);
            }

            doc.Objects.AddMesh(seed);

            var dual = seed.Dual();

            dual.Translate(new Vector3d(transFactor, 0, 0));
            doc.Objects.AddMesh(dual);

            var kis = seed.Kis();

            kis.Translate(new Vector3d(transFactor * 2, 0, 0));
            doc.Objects.AddMesh(kis);

            var ambo = seed.Ambo();

            ambo.Translate(new Vector3d(transFactor * 3, 0, 0));
            doc.Objects.AddMesh(ambo);

            var zip = seed.Zip();

            zip.Translate(new Vector3d(transFactor * 0, transFactor * 1, 0));
            doc.Objects.AddMesh(zip);

            var join = seed.Join();

            join.Translate(new Vector3d(transFactor * 1, transFactor * 1, 0));
            doc.Objects.AddMesh(join);

            var needle = seed.Needle();

            needle.Translate(new Vector3d(transFactor * 2, transFactor * 1, 0));
            doc.Objects.AddMesh(needle);

            var truncate = seed.Truncate();

            truncate.Translate(new Vector3d(transFactor * 3, transFactor * 1, 0));
            doc.Objects.AddMesh(truncate);

            var ortho = seed.Ortho();

            ortho.Translate(new Vector3d(transFactor * 0, transFactor * 2, 0));
            doc.Objects.AddMesh(ortho);

            var expand = seed.Expand();

            expand.Translate(new Vector3d(transFactor * 1, transFactor * 2, 0));
            doc.Objects.AddMesh(expand);

            var meta = seed.Meta();

            meta.Translate(new Vector3d(transFactor * 2, transFactor * 2, 0));
            doc.Objects.AddMesh(meta);

            var bevel = seed.Bevel();

            bevel.Translate(new Vector3d(transFactor * 3, transFactor * 2, 0));
            doc.Objects.AddMesh(bevel);

            doc.Views.Redraw();

            return(Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            string layer_name = "";
            var    rc         = RhinoGet.GetString("Name of layer to rename", true, ref layer_name);

            if (rc != Result.Success)
            {
                return(rc);
            }
            if (String.IsNullOrWhiteSpace(layer_name))
            {
                return(Result.Nothing);
            }

            // because of sublayers it's possible that more than one layer has the same name
            // so simply calling doc.Layers.Find(layerName) isn't good enough.  If "layerName" returns
            // more than one layer then present them to the user and let him decide.
            var matching_layers = (from layer in doc.Layers
                                   where layer.Name == layer_name
                                   select layer).ToList <Layer>();

            Layer layer_to_rename = null;

            if (matching_layers.Count == 0)
            {
                RhinoApp.WriteLine("Layer \"{0}\" does not exist.", layer_name);
                return(Result.Nothing);
            }
            else if (matching_layers.Count == 1)
            {
                layer_to_rename = matching_layers[0];
            }
            else if (matching_layers.Count > 1)
            {
                for (int i = 0; i < matching_layers.Count; i++)
                {
                    RhinoApp.WriteLine("({0}) {1}", i + 1, matching_layers[i].FullPath.Replace("::", "->"));
                }
                int selected_layer = -1;
                rc = RhinoGet.GetInteger("which layer?", true, ref selected_layer);
                if (rc != Result.Success)
                {
                    return(rc);
                }
                if (selected_layer > 0 && selected_layer <= matching_layers.Count)
                {
                    layer_to_rename = matching_layers[selected_layer - 1];
                }
                else
                {
                    return(Result.Nothing);
                }
            }

            if (layer_to_rename == null)
            {
                return(Result.Nothing);
            }

            layer_name = "";
            rc         = RhinoGet.GetString("New layer name", true, ref layer_name);
            if (rc != Result.Success)
            {
                return(rc);
            }
            if (String.IsNullOrWhiteSpace(layer_name))
            {
                return(Result.Nothing);
            }

            layer_to_rename.Name = layer_name;
            if (!layer_to_rename.CommitChanges())
            {
                return(Result.Failure);
            }
            return(Result.Success);
        }