public static Rhino.Commands.Result ArcLengthPoint(Rhino.RhinoDoc doc)
    {
        Rhino.DocObjects.ObjRef objref;
        Rhino.Commands.Result   rc = Rhino.Input.RhinoGet.GetOneObject("Select curve",
                                                                       true, Rhino.DocObjects.ObjectType.Curve, out objref);
        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }
        Rhino.Geometry.Curve crv = objref.Curve();
        if (crv == null)
        {
            return(Rhino.Commands.Result.Failure);
        }

        double crv_length = crv.GetLength();
        double length     = 0;

        rc = Rhino.Input.RhinoGet.GetNumber("Length from start", true, ref length, 0, crv_length);
        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }

        Rhino.Geometry.Point3d pt = crv.PointAtLength(length);
        if (pt.IsValid)
        {
            doc.Objects.AddPoint(pt);
            doc.Views.Redraw();
        }
        return(Rhino.Commands.Result.Success);
    }
Exemplo n.º 2
0
    public static Rhino.Commands.Result AddClippingPlane(Rhino.RhinoDoc doc)
    {
        // Define the corners of the clipping plane
        Rhino.Geometry.Point3d[] corners;
        Rhino.Commands.Result    rc = Rhino.Input.RhinoGet.GetRectangle(out corners);
        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }

        // Get the active view
        Rhino.Display.RhinoView view = doc.Views.ActiveView;
        if (view == null)
        {
            return(Rhino.Commands.Result.Failure);
        }

        Rhino.Geometry.Point3d p0 = corners[0];
        Rhino.Geometry.Point3d p1 = corners[1];
        Rhino.Geometry.Point3d p3 = corners[3];

        // Create a plane from the corner points
        Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(p0, p1, p3);

        // Add a clipping plane object to the document
        Guid id = doc.Objects.AddClippingPlane(plane, p0.DistanceTo(p1), p0.DistanceTo(p3), view.ActiveViewportID);

        if (id != Guid.Empty)
        {
            doc.Views.Redraw();
            return(Rhino.Commands.Result.Success);
        }
        return(Rhino.Commands.Result.Failure);
    }
Exemplo n.º 3
0
    public static Rhino.Commands.Result Stretch(Rhino.RhinoDoc doc)
    {
        ObjectType filter = SpaceMorphObjectFilter();

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

        Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();

        Rhino.Geometry.Line axis;
        rc = Rhino.Input.RhinoGet.GetLine(out axis);
        if (rc != Rhino.Commands.Result.Success || axis == null)
        {
            return(rc);
        }

        Rhino.Geometry.Morphs.StretchSpaceMorph morph = new Rhino.Geometry.Morphs.StretchSpaceMorph(axis.From, axis.To, axis.Length * 1.5);

        Rhino.Geometry.GeometryBase geom = objref.Geometry().Duplicate();
        if (morph.Morph(geom))
        {
            doc.Objects.Add(geom);
            doc.Views.Redraw();
        }

        return(Rhino.Commands.Result.Success);
    }
    public static Rhino.Commands.Result DupBorder(Rhino.RhinoDoc doc)
    {
        const ObjectType filter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.PolysrfFilter;

        Rhino.DocObjects.ObjRef objref;
        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);
        Rhino.Geometry.Curve[] curves = brep.DuplicateEdgeCurves(true);
        double tol = doc.ModelAbsoluteTolerance * 2.1;

        curves = Rhino.Geometry.Curve.JoinCurves(curves, tol);
        for (int i = 0; i < curves.Length; i++)
        {
            Guid id = doc.Objects.AddCurve(curves[i]);
            doc.Objects.Select(id);
        }
        doc.Views.Redraw();
        return(Rhino.Commands.Result.Success);
    }
Exemplo n.º 5
0
    public static Rhino.Commands.Result EditText(Rhino.RhinoDoc doc)
    {
        Rhino.DocObjects.ObjRef objref;
        Rhino.Commands.Result   rc = Rhino.Input.RhinoGet.GetOneObject("Select text", false, Rhino.DocObjects.ObjectType.Annotation, out objref);
        if (rc != Rhino.Commands.Result.Success || objref == null)
        {
            return(rc);
        }

        Rhino.DocObjects.TextObject textobj = objref.Object() as Rhino.DocObjects.TextObject;
        if (textobj == null)
        {
            return(Rhino.Commands.Result.Failure);
        }

        Rhino.Geometry.TextEntity textentity = textobj.Geometry as Rhino.Geometry.TextEntity;
        if (textentity == null)
        {
            return(Rhino.Commands.Result.Failure);
        }
        string str = textentity.Text;

        rc = Rhino.Input.RhinoGet.GetString("New text", false, ref str);
        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }

        textentity.Text = str;
        textobj.CommitChanges();
        doc.Views.Redraw();
        return(Rhino.Commands.Result.Success);
    }
            protected override Rhino.Commands.Result  RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
            {
                //List<Rhino.DocObjects.RhinoObject> ObjectList = new List<Rhino.DocObjects.RhinoObject>();
                Rhino.DocObjects.ObjectEnumeratorSettings settings = new Rhino.DocObjects.ObjectEnumeratorSettings();
                settings.DeletedObjects   = false;
                settings.HiddenObjects    = false;
                settings.LockedObjects    = true;
                settings.NormalObjects    = true;
                settings.VisibleFilter    = true;
                settings.ObjectTypeFilter = Rhino.DocObjects.ObjectType.Brep & Rhino.DocObjects.ObjectType.Surface & Rhino.DocObjects.ObjectType.Extrusion;
                List <Rhino.DocObjects.RhinoObject> RC_List = new List <Rhino.DocObjects.RhinoObject>();

                foreach (Rhino.DocObjects.RhinoObject RHobj in Rhino.RhinoDoc.ActiveDoc.Objects.GetObjectList(settings))
                {
                    if (RHobj.ObjectType == Rhino.DocObjects.ObjectType.Brep || RHobj.ObjectType == Rhino.DocObjects.ObjectType.Surface || RHobj.ObjectType == Rhino.DocObjects.ObjectType.Extrusion)
                    {
                        RC_List.Add(RHobj);
                    }
                }
                if (RC_List.Count != 0)
                {
                    Ret_NURBS_Scene = new RhCommon_Scene(RC_List, Air_Temp, Rel_Humidity, Atm_pressure, Atten_Choice, Edge_Freq, false);
                    if (!Ret_NURBS_Scene.Valid)
                    {
                        return(Rhino.Commands.Result.Failure);
                    }
                    Ret_Mesh_Scene = new RhCommon_PolygonScene(RC_List, Register_Edges, Air_Temp, Rel_Humidity, Atm_pressure, Atten_Choice, Edge_Freq, false);
                    if (!Ret_Mesh_Scene.Valid)
                    {
                        return(Rhino.Commands.Result.Failure);
                    }
                }
                C_Result = Rhino.Commands.Result.Success;
                return(Rhino.Commands.Result.Success);
            }
Exemplo n.º 7
0
        void getNewGeometry()
        {
            ObjRef[] rhObjects = new ObjRef[1];


            try
            {
                Rhino.Commands.Result result = Rhino.Commands.Result.Cancel;
                if (!allowMultiple)
                {
                    result       = Rhino.Input.RhinoGet.GetOneObject(msg, allowNone, filter, out ObjRef rhObject);
                    rhObjects[0] = rhObject;
                }
                else
                {
                    result = Rhino.Input.RhinoGet.GetMultipleObjects(msg, allowNone, filter, out rhObjects);
                }

                if (result == Rhino.Commands.Result.Cancel)
                {
                    OnPickCompleted(EventArgs.Empty);
                }
                else if (result == Rhino.Commands.Result.Success)
                {
                    objIDs = rhObjects.Select(o => o.ObjectId).ToList();
                    OnPickCompleted(EventArgs.Empty);
                    return;
                }
            }
            catch
            {
            }
        }
    public static Rhino.Commands.Result MoveGripObjects(Rhino.RhinoDoc doc)
    {
        // The following example demonstrates how to move a surface's grip objects.
        // In this sample, all grips will be moved a fixed distance of 0.5 units
        // in the normal direction of the surface at that grip location.

        Rhino.DocObjects.ObjRef objRef;
        Rhino.Commands.Result   rc = Rhino.Input.RhinoGet.GetOneObject("Select surface for control point editing", false, Rhino.DocObjects.ObjectType.Surface, out objRef);
        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }

        Rhino.DocObjects.RhinoObject obj = objRef.Object();
        if (null == obj)
        {
            return(Rhino.Commands.Result.Failure);
        }

        Rhino.Geometry.Surface srf = objRef.Surface();
        if (null == srf)
        {
            return(Rhino.Commands.Result.Failure);
        }

        // Make sure the object's grips are enabled
        obj.GripsOn = true;
        doc.Views.Redraw();

        Rhino.DocObjects.GripObject[] grips = obj.GetGrips();
        for (int i = 0; i < grips.Length; i++)
        {
            Rhino.DocObjects.GripObject grip = grips[i];

            // Calculate the point on the surface closest to our test point,
            // which is the grip's 3-D location (for this example).
            double u, v;
            if (srf.ClosestPoint(grip.CurrentLocation, out u, out v))
            {
                // Compute the surface normal at a point
                Rhino.Geometry.Vector3d dir = srf.NormalAt(u, v);
                dir.Unitize();

                // Scale by our fixed distance
                dir *= 0.5;

                // Move the grip to a new location
                grip.Move(dir);
            }
        }

        // Altered grip positions on a RhinoObject are used to calculate an updated
        // object that is added to the document.
        doc.Objects.GripUpdate(obj, false);
        doc.Views.Redraw();

        return(Rhino.Commands.Result.Success);
    }
 private void Set_Origin_Click(object sender, EventArgs e)
 {
     Rhino.Geometry.Point3d pt;
     Rhino.Commands.Result  rr = Rhino.Input.RhinoGet.GetPoint("Select the center point of the sample that you would like to analyze...", true, out pt);
     if (rr == Rhino.Commands.Result.Success)
     {
         LabCenter = pt;
     }
 }
Exemplo n.º 10
0
    public static Rhino.Commands.Result Flow(Rhino.RhinoDoc doc)
    {
        ObjectType filter = SpaceMorphObjectFilter();

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

        Rhino.Input.Custom.GetObject go0 = new Rhino.Input.Custom.GetObject();
        go0.SetCommandPrompt("Source curve");
        go0.GeometryFilter  = Rhino.DocObjects.ObjectType.Curve;
        go0.SubObjectSelect = false;
        go0.EnablePreSelect(false, true);
        go0.DeselectAllBeforePostSelect = false;
        go0.Get();
        if (go0.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go0.CommandResult());
        }

        Rhino.DocObjects.ObjRef crv0_ref = go0.Object(0);

        Rhino.Input.Custom.GetObject go1 = new Rhino.Input.Custom.GetObject();
        go1.SetCommandPrompt("Source curve");
        go1.GeometryFilter  = Rhino.DocObjects.ObjectType.Curve;
        go1.SubObjectSelect = false;
        go1.EnablePreSelect(false, true);
        go1.DeselectAllBeforePostSelect = false;
        go1.Get();
        if (go1.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go1.CommandResult());
        }

        Rhino.DocObjects.ObjRef crv1_ref = go1.Object(0);

        Rhino.Geometry.Morphs.FlowSpaceMorph morph = new Rhino.Geometry.Morphs.FlowSpaceMorph(crv0_ref.Curve(), crv1_ref.Curve(), false);

        Rhino.Geometry.GeometryBase geom = objref.Geometry().Duplicate();
        if (morph.Morph(geom))
        {
            doc.Objects.Add(geom);
            doc.Views.Redraw();
        }

        return(Rhino.Commands.Result.Success);
    }
Exemplo n.º 11
0
 public static Rhino.Commands.Result AddBrepBox(Rhino.RhinoDoc doc)
 {
     Rhino.Geometry.Point3d     pt0  = new Rhino.Geometry.Point3d(0, 0, 0);
     Rhino.Geometry.Point3d     pt1  = new Rhino.Geometry.Point3d(10, 10, 10);
     Rhino.Geometry.BoundingBox box  = new Rhino.Geometry.BoundingBox(pt0, pt1);
     Rhino.Geometry.Brep        brep = box.ToBrep();
     Rhino.Commands.Result      rc   = Rhino.Commands.Result.Failure;
     if (doc.Objects.AddBrep(brep) != System.Guid.Empty)
     {
         rc = Rhino.Commands.Result.Success;
         doc.Views.Redraw();
     }
     return(rc);
 }
Exemplo n.º 12
0
    public static Rhino.Commands.Result Maelstrom(Rhino.RhinoDoc doc)
    {
        ObjectType filter = SpaceMorphObjectFilter();

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

        Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();

        double radius0 = Rhino.RhinoMath.UnsetValue;

        rc = Rhino.Input.RhinoGet.GetNumber("Starting radius", false, ref radius0);
        if (rc != Rhino.Commands.Result.Success || !Rhino.RhinoMath.IsValidDouble(radius0))
        {
            return(rc);
        }

        double radius1 = Rhino.RhinoMath.UnsetValue;

        rc = Rhino.Input.RhinoGet.GetNumber("Ending radius", false, ref radius1);
        if (rc != Rhino.Commands.Result.Success || !Rhino.RhinoMath.IsValidDouble(radius1))
        {
            return(rc);
        }

        double angle = Rhino.RhinoMath.UnsetValue;

        rc = Rhino.Input.RhinoGet.GetNumber("Twist angle in degrees", false, ref angle);
        if (rc != Rhino.Commands.Result.Success || !Rhino.RhinoMath.IsValidDouble(angle))
        {
            return(rc);
        }

        Rhino.Geometry.Morphs.MaelstromSpaceMorph morph = new Rhino.Geometry.Morphs.MaelstromSpaceMorph(plane, radius0, radius1, Rhino.RhinoMath.ToRadians(angle));

        Rhino.Geometry.GeometryBase geom = objref.Geometry().Duplicate();
        if (morph.Morph(geom))
        {
            doc.Objects.Add(geom);
            doc.Views.Redraw();
        }

        return(Rhino.Commands.Result.Success);
    }
Exemplo n.º 13
0
    public static Rhino.Commands.Result AddMeshBox(Rhino.RhinoDoc doc)
    {
        Rhino.Geometry.Box    box;
        Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetBox(out box);
        if (rc == Rhino.Commands.Result.Success)
        {
            Rhino.Geometry.Mesh mesh = Rhino.Geometry.Mesh.CreateFromBox(box, 2, 2, 2);
            if (null != mesh)
            {
                doc.Objects.AddMesh(mesh);
                doc.Views.Redraw();
                return(Rhino.Commands.Result.Success);
            }
        }

        return(Rhino.Commands.Result.Failure);
    }
 public static Rhino.Commands.Result AddLinearDimension(Rhino.RhinoDoc doc)
 {
     Rhino.Geometry.LinearDimension dimension;
     Rhino.Commands.Result          rc = Rhino.Input.RhinoGet.GetLinearDimension(out dimension);
     if (rc == Rhino.Commands.Result.Success && dimension != null)
     {
         if (doc.Objects.AddLinearDimension(dimension) == Guid.Empty)
         {
             rc = Rhino.Commands.Result.Failure;
         }
         else
         {
             doc.Views.Redraw();
         }
     }
     return(rc);
 }
Exemplo n.º 15
0
    public static Rhino.Commands.Result AddNamedView(Rhino.RhinoDoc doc)
    {
        Rhino.Display.RhinoView view;
        Rhino.Commands.Result   rc = Rhino.Input.RhinoGet.GetView("Select view to adjust", out view);
        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }

        Rhino.Geometry.Point3d location;
        rc = Rhino.Input.RhinoGet.GetPoint("Camera Location", false, out location);
        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }

        Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
        gp.SetCommandPrompt("Look At Location");
        gp.DrawLineFromPoint(location, false);
        gp.Get();
        if (gp.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gp.CommandResult());
        }
        Rhino.Geometry.Point3d lookat = gp.Point();

        string name = view.ActiveViewport.Name;

        rc = Rhino.Input.RhinoGet.GetString("Name", true, ref name);
        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }

        Rhino.Display.RhinoViewport vp = view.ActiveViewport;
        // save the current viewport projection
        vp.PushViewProjection();
        vp.CameraUp = Rhino.Geometry.Vector3d.ZAxis;
        vp.SetCameraLocation(location, false);
        vp.SetCameraDirection(lookat - location, true);
        vp.Name = name;

        doc.NamedViews.Add(name, vp.Id);
        view.Redraw();
        return(Rhino.Commands.Result.Success);
    }
Exemplo n.º 16
0
    public static Rhino.Commands.Result Taper(Rhino.RhinoDoc doc)
    {
        ObjectType filter = SpaceMorphObjectFilter();

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

        Rhino.Geometry.Line axis;
        rc = Rhino.Input.RhinoGet.GetLine(out axis);
        if (rc != Rhino.Commands.Result.Success || axis == null)
        {
            return(rc);
        }

        double radius0 = Rhino.RhinoMath.UnsetValue;

        rc = Rhino.Input.RhinoGet.GetNumber("Starting radius", false, ref radius0);
        if (rc != Rhino.Commands.Result.Success || !Rhino.RhinoMath.IsValidDouble(radius0))
        {
            return(rc);
        }

        double radius1 = Rhino.RhinoMath.UnsetValue;

        rc = Rhino.Input.RhinoGet.GetNumber("Ending radius", false, ref radius1);
        if (rc != Rhino.Commands.Result.Success || !Rhino.RhinoMath.IsValidDouble(radius1))
        {
            return(rc);
        }

        Rhino.Geometry.Morphs.TaperSpaceMorph morph = new Rhino.Geometry.Morphs.TaperSpaceMorph(axis.From, axis.To, radius0, radius1, false, false);

        Rhino.Geometry.GeometryBase geom = objref.Geometry().Duplicate();
        if (morph.Morph(geom))
        {
            doc.Objects.Add(geom);
            doc.Views.Redraw();
        }

        return(Rhino.Commands.Result.Success);
    }
Exemplo n.º 17
0
    public static Rhino.Commands.Result DetermineObjectLayer(Rhino.RhinoDoc doc)
    {
        Rhino.DocObjects.ObjRef obref;
        Rhino.Commands.Result   rc = Rhino.Input.RhinoGet.GetOneObject("Select object", true, Rhino.DocObjects.ObjectType.AnyObject, out obref);
        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }
        Rhino.DocObjects.RhinoObject rhobj = obref.Object();
        if (rhobj == null)
        {
            return(Rhino.Commands.Result.Failure);
        }
        int    index = rhobj.Attributes.LayerIndex;
        string name  = doc.Layers[index].Name;

        Rhino.RhinoApp.WriteLine("The selected object's layer is '{0}'", name);
        return(Rhino.Commands.Result.Success);
    }
Exemplo n.º 18
0
    public static Rhino.Commands.Result Splop(Rhino.RhinoDoc doc)
    {
        ObjectType filter = SpaceMorphObjectFilter();

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

        Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();

        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Surface to splop on");
        go.GeometryFilter  = Rhino.DocObjects.ObjectType.Surface;
        go.SubObjectSelect = false;
        go.EnablePreSelect(false, true);
        go.DeselectAllBeforePostSelect = false;
        go.Get();
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        Rhino.DocObjects.ObjRef srfref = go.Object(0);

        double u, v;

        srfref.SurfaceParameter(out u, out v);

        Rhino.Geometry.Point2d uv = new Rhino.Geometry.Point2d(u, v);

        Rhino.Geometry.Morphs.SplopSpaceMorph morph = new Rhino.Geometry.Morphs.SplopSpaceMorph(plane, srfref.Surface(), uv);
        Rhino.Geometry.GeometryBase           geom  = objref.Geometry().Duplicate();
        if (morph.Morph(geom))
        {
            doc.Objects.Add(geom);
            doc.Views.Redraw();
        }

        return(Rhino.Commands.Result.Success);
    }
Exemplo n.º 19
0
    public static Rhino.Commands.Result DivideByLengthPoints(Rhino.RhinoDoc doc)
    {
        const 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 crv = objref.Curve();
        if (crv == null || crv.IsShort(Rhino.RhinoMath.ZeroTolerance))
        {
            return(Rhino.Commands.Result.Failure);
        }

        double crv_length = crv.GetLength();
        string s          = string.Format("Curve length is {0:f3}. Segment length", crv_length);

        double seg_length = crv_length / 2.0;

        rc = Rhino.Input.RhinoGet.GetNumber(s, false, ref seg_length, 0, crv_length);
        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }

        Rhino.Geometry.Point3d[] points;
        crv.DivideByLength(seg_length, true, out points);
        if (points == null)
        {
            return(Rhino.Commands.Result.Failure);
        }

        foreach (Rhino.Geometry.Point3d point in points)
        {
            doc.Objects.AddPoint(point);
        }

        doc.Views.Redraw();
        return(Rhino.Commands.Result.Success);
    }
Exemplo n.º 20
0
 public static Rhino.Commands.Result AddNurbsCurve(Rhino.RhinoDoc doc)
 {
     Rhino.Collections.Point3dList points = new Rhino.Collections.Point3dList(5);
     points.Add(0, 0, 0);
     points.Add(0, 2, 0);
     points.Add(2, 3, 0);
     points.Add(4, 2, 0);
     points.Add(4, 0, 0);
     Rhino.Geometry.NurbsCurve nc = Rhino.Geometry.NurbsCurve.Create(false, 3, points);
     Rhino.Commands.Result     rc = Rhino.Commands.Result.Failure;
     if (nc != null && nc.IsValid)
     {
         if (doc.Objects.AddCurve(nc) != Guid.Empty)
         {
             doc.Views.Redraw();
             rc = Rhino.Commands.Result.Success;
         }
     }
     return(rc);
 }
Exemplo n.º 21
0
    public static Rhino.Commands.Result Twist(Rhino.RhinoDoc doc)
    {
        ObjectType filter = SpaceMorphObjectFilter();

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

        Rhino.Geometry.Line axis;
        rc = Rhino.Input.RhinoGet.GetLine(out axis);
        if (rc != Rhino.Commands.Result.Success || axis == null)
        {
            return(rc);
        }

        double angle = Rhino.RhinoMath.UnsetValue;

        rc = Rhino.Input.RhinoGet.GetNumber("Twist angle in degrees", false, ref angle);
        if (rc != Rhino.Commands.Result.Success || !Rhino.RhinoMath.IsValidDouble(angle))
        {
            return(rc);
        }

        Rhino.Geometry.Morphs.TwistSpaceMorph morph = new Rhino.Geometry.Morphs.TwistSpaceMorph();
        morph.TwistAxis         = axis;
        morph.TwistAngleRadians = Rhino.RhinoMath.ToRadians(angle);

        Rhino.Geometry.GeometryBase geom = objref.Geometry().Duplicate();
        if (morph.Morph(geom))
        {
            doc.Objects.Add(geom);
            doc.Views.Redraw();
        }

        return(Rhino.Commands.Result.Success);
    }
Exemplo n.º 22
0
    public static Rhino.Commands.Result ExtractRenderMesh(Rhino.RhinoDoc doc)
    {
        Rhino.DocObjects.ObjRef objRef = null;
        Rhino.Commands.Result   rc     = Rhino.Input.RhinoGet.GetOneObject("Select surface or polysurface", false, Rhino.DocObjects.ObjectType.Brep, out objRef);
        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }

        Rhino.DocObjects.RhinoObject obj = objRef.Object();
        if (null == obj)
        {
            return(Rhino.Commands.Result.Failure);
        }

        System.Collections.Generic.List <Rhino.DocObjects.RhinoObject> objList = new System.Collections.Generic.List <Rhino.DocObjects.RhinoObject>(1);
        objList.Add(obj);

        Rhino.DocObjects.ObjRef[] meshObjRefs = Rhino.DocObjects.RhinoObject.GetRenderMeshes(objList, true, false);
        if (null != meshObjRefs)
        {
            for (int i = 0; i < meshObjRefs.Length; i++)
            {
                Rhino.DocObjects.ObjRef meshObjRef = meshObjRefs[i];
                if (null != meshObjRef)
                {
                    Rhino.Geometry.Mesh mesh = meshObjRef.Mesh();
                    if (null != mesh)
                    {
                        doc.Objects.AddMesh(mesh);
                    }
                }
            }
            doc.Views.Redraw();
        }

        return(Rhino.Commands.Result.Success);
    }
Exemplo n.º 23
0
    public static Rhino.Commands.Result ConduitDrawShadedMesh(Rhino.RhinoDoc doc)
    {
        Rhino.Geometry.Mesh mesh = MeshBox(100, 500, 10);
        if (null == mesh)
        {
            return(Rhino.Commands.Result.Failure);
        }

        DrawShadedMeshConduit conduit = new DrawShadedMeshConduit();

        conduit.Mesh    = mesh;
        conduit.Enabled = true;
        doc.Views.Redraw();

        string outputString = string.Empty;

        Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetString("Press <Enter> to continue", true, ref outputString);

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

        return(Rhino.Commands.Result.Success);
    }
Exemplo n.º 24
0
    public static Rhino.Commands.Result ObjectColor(Rhino.RhinoDoc doc)
    {
        Rhino.DocObjects.ObjRef[] objRefs;
        Rhino.Commands.Result     cmdResult = Rhino.Input.RhinoGet.GetMultipleObjects("Select objects to change color", false, Rhino.DocObjects.ObjectType.AnyObject, out objRefs);
        if (cmdResult != Rhino.Commands.Result.Success)
        {
            return(cmdResult);
        }

        System.Drawing.Color color = System.Drawing.Color.Black;
        bool rc = Rhino.UI.Dialogs.ShowColorDialog(ref color);

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

        for (int i = 0; i < objRefs.Length; i++)
        {
            Rhino.DocObjects.RhinoObject obj = objRefs[i].Object();
            if (null == obj || obj.IsReference)
            {
                continue;
            }

            if (color != obj.Attributes.ObjectColor)
            {
                obj.Attributes.ObjectColor = color;
                obj.Attributes.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject;
                obj.CommitChanges();
            }
        }

        doc.Views.Redraw();

        return(Rhino.Commands.Result.Success);
    }
Exemplo n.º 25
0
 public static Rhino.Commands.Result BoxShell(Rhino.RhinoDoc doc)
 {
     Rhino.Geometry.Box    box;
     Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetBox(out box);
     if (rc == Rhino.Commands.Result.Success)
     {
         Rhino.Geometry.Brep brep = Rhino.Geometry.Brep.CreateFromBox(box);
         if (null != brep)
         {
             System.Collections.Generic.List <int> facesToRemove = new System.Collections.Generic.List <int>(1);
             facesToRemove.Add(0);
             Rhino.Geometry.Brep[] shells = Rhino.Geometry.Brep.CreateShell(brep, facesToRemove, 1.0, doc.ModelAbsoluteTolerance);
             if (null != shells)
             {
                 for (int i = 0; i < shells.Length; i++)
                 {
                     doc.Objects.AddBrep(shells[i]);
                 }
                 doc.Views.Redraw();
             }
         }
     }
     return(rc);
 }
Exemplo n.º 26
0
    public static Rhino.Commands.Result Bend(Rhino.RhinoDoc doc)
    {
        ObjectType filter = SpaceMorphObjectFilter();

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

        Rhino.Geometry.Line axis;
        rc = Rhino.Input.RhinoGet.GetLine(out axis);
        if (rc != Rhino.Commands.Result.Success || axis == null)
        {
            return(rc);
        }

        Rhino.Geometry.Point3d point;
        rc = Rhino.Input.RhinoGet.GetPoint("Point to bend through", false, out point);
        if (rc != Rhino.Commands.Result.Success || !point.IsValid)
        {
            return(rc);
        }

        Rhino.Geometry.Morphs.BendSpaceMorph morph = new Rhino.Geometry.Morphs.BendSpaceMorph(axis.From, axis.To, point, true, false);

        Rhino.Geometry.GeometryBase geom = objref.Geometry().Duplicate();
        if (morph.Morph(geom))
        {
            doc.Objects.Add(geom);
            doc.Views.Redraw();
        }

        return(Rhino.Commands.Result.Success);
    }
Exemplo n.º 27
0
        /// <summary>
        /// Executes the platonic command
        /// </summary>
        protected override Rhino.Commands.Result RunCommand(Rhino.RhinoDoc doc, Rhino.Commands.RunMode mode)
        {
            // Get the platonic geometry
            Rhino.Geometry.Brep[] faces = Platonic.Faces();
            if (null == faces)
            {
                return(Rhino.Commands.Result.Failure);
            }

            // Prompt for center point
            string prompt = string.Format("Center of {0}", Platonic.DisplayName.ToLower());

            Rhino.Geometry.Point3d origin;
            Rhino.Commands.Result  rc = Rhino.Input.RhinoGet.GetPoint(prompt, false, out origin);
            if (rc != Rhino.Commands.Result.Success)
            {
                return(rc);
            }

            double length       = m_length;
            bool   create_solid = m_create_solid;
            bool   group_faces  = m_group_faces;

            // Prompt for edge length
            PlatonicGetPoint get = new PlatonicGetPoint(faces, origin);

            get.SetCommandPrompt(Platonic.Prompt);
            get.SetDefaultNumber(length);
            get.SetBasePoint(origin, true);
            get.DrawLineFromPoint(origin, true);
            get.AcceptNumber(true, false);

            Rhino.Geometry.Transform xform = new Rhino.Geometry.Transform(1.0);
            rc = Rhino.Commands.Result.Cancel;

            for (; ;)
            {
                get.ClearCommandOptions();

                Rhino.Input.Custom.OptionToggle output_toggle = null;
                Rhino.Input.Custom.OptionToggle group_toggle  = null;

                output_toggle = new Rhino.Input.Custom.OptionToggle(create_solid, "Faces", "Solid");
                get.AddOptionToggle("Output", ref output_toggle);

                if (!create_solid)
                {
                    group_toggle = new Rhino.Input.Custom.OptionToggle(group_faces, "No", "Yes");
                    get.AddOptionToggle("Group", ref group_toggle);
                }

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

                if (res == Rhino.Input.GetResult.Point)
                {
                    if (get.CalculateTransform(get.View().ActiveViewport, get.Point(), ref xform))
                    {
                        m_length = get.Length;
                        rc       = Rhino.Commands.Result.Success;
                        break;
                    }
                }
                else if (res == Rhino.Input.GetResult.Number)
                {
                    length = System.Math.Abs(get.Number());
                    if (get.CalculateTransform(get.View().ActiveViewport, length, ref xform))
                    {
                        m_length = get.Length;
                        rc       = Rhino.Commands.Result.Success;
                        break;
                    }
                }
                else if (res == Rhino.Input.GetResult.Option)
                {
                    if (null != output_toggle && create_solid != output_toggle.CurrentValue)
                    {
                        create_solid = output_toggle.CurrentValue;
                    }

                    if (null != group_toggle && group_faces != group_toggle.CurrentValue)
                    {
                        group_faces = group_toggle.CurrentValue;
                    }

                    continue;
                }
                else
                {
                    break;
                }
            }

            // If we got here, then we have the center point and edge length,
            // any any command options. Time to add the geomtry to the document.
            if (rc == Rhino.Commands.Result.Success && xform.IsValid)
            {
                m_create_solid = create_solid;
                m_group_faces  = group_faces;

                Rhino.DocObjects.ObjectAttributes attribs = doc.CreateDefaultAttributes();
                attribs.Name        = Platonic.Name;
                attribs.WireDensity = 0; // solid looks "nicer" with wires turned off...

                if (m_create_solid)
                {
                    Rhino.Geometry.Brep[] breps = Rhino.Geometry.Brep.JoinBreps(faces, 2.1 * doc.ModelAbsoluteTolerance);
                    foreach (Brep t in breps)
                    {
                        if (null == t)
                        {
                            continue;
                        }
                        t.Transform(xform);
                        doc.Objects.AddBrep(t, attribs, null, false, false);
                    }
                }
                else
                {
                    if (m_group_faces)
                    {
                        attribs.AddToGroup(doc.Groups.Add());
                    }

                    foreach (Brep t in faces)
                    {
                        if (null == t)
                        {
                            continue;
                        }
                        t.Transform(xform);
                        doc.Objects.AddBrep(t, attribs, null, false, false);
                    }
                }

                doc.Views.Redraw();
            }

            return(Rhino.Commands.Result.Success);
        }
Exemplo n.º 28
0
    public static Rhino.Commands.Result OrientOnSrf(Rhino.RhinoDoc doc)
    {
        // Select objects to orient
        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select objects to orient");
        go.SubObjectSelect = false;
        go.GroupSelect     = true;
        go.GetMultiple(1, 0);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        // Point to orient from
        Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
        gp.SetCommandPrompt("Point to orient from");
        gp.Get();
        if (gp.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gp.CommandResult());
        }

        // Define source plane
        Rhino.Display.RhinoView view = gp.View();
        if (view == null)
        {
            view = doc.Views.ActiveView;
            if (view == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
        }
        Rhino.Geometry.Plane source_plane = view.ActiveViewport.ConstructionPlane();
        source_plane.Origin = gp.Point();

        // Surface to orient on
        Rhino.Input.Custom.GetObject gs = new Rhino.Input.Custom.GetObject();
        gs.SetCommandPrompt("Surface to orient on");
        gs.GeometryFilter              = Rhino.DocObjects.ObjectType.Surface;
        gs.SubObjectSelect             = true;
        gs.DeselectAllBeforePostSelect = false;
        gs.OneByOnePostSelect          = true;
        gs.Get();
        if (gs.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gs.CommandResult());
        }

        Rhino.DocObjects.ObjRef objref = gs.Object(0);
        // get selected surface object
        Rhino.DocObjects.RhinoObject obj = objref.Object();
        if (obj == null)
        {
            return(Rhino.Commands.Result.Failure);
        }
        // get selected surface (face)
        Rhino.Geometry.Surface surface = objref.Surface();
        if (surface == null)
        {
            return(Rhino.Commands.Result.Failure);
        }
        // Unselect surface
        obj.Select(false);

        // Point on surface to orient to
        gp.SetCommandPrompt("Point on surface to orient to");
        gp.Constrain(surface, false);
        gp.Get();
        if (gp.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gp.CommandResult());
        }

        // Do transformation
        Rhino.Commands.Result rc = Rhino.Commands.Result.Failure;
        double u, v;

        if (surface.ClosestPoint(gp.Point(), out u, out v))
        {
            Rhino.Geometry.Plane target_plane;
            if (surface.FrameAt(u, v, out target_plane))
            {
                // Build transformation
                Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.PlaneToPlane(source_plane, target_plane);

                // Do the transformation. In this example, we will copy the original objects
                const bool delete_original = false;
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    doc.Objects.Transform(go.Object(i), xform, delete_original);
                }

                doc.Views.Redraw();
                rc = Rhino.Commands.Result.Success;
            }
        }
        return(rc);
    }
 protected override Rhino.Commands.Result  RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
 {
     //List<Rhino.DocObjects.RhinoObject> ObjectList = new List<Rhino.DocObjects.RhinoObject>();
     Rhino.DocObjects.ObjectEnumeratorSettings settings = new Rhino.DocObjects.ObjectEnumeratorSettings();
     settings.DeletedObjects = false;
     settings.HiddenObjects = false;
     settings.LockedObjects = true;
     settings.NormalObjects = true;
     settings.VisibleFilter = true;
     settings.ObjectTypeFilter = Rhino.DocObjects.ObjectType.Brep & Rhino.DocObjects.ObjectType.Surface & Rhino.DocObjects.ObjectType.Extrusion;
     List<Rhino.DocObjects.RhinoObject> RC_List = new List<Rhino.DocObjects.RhinoObject>();
     foreach (Rhino.DocObjects.RhinoObject RHobj in Rhino.RhinoDoc.ActiveDoc.Objects.GetObjectList(settings))
     {
         if (RHobj.ObjectType == Rhino.DocObjects.ObjectType.Brep || RHobj.ObjectType == Rhino.DocObjects.ObjectType.Surface || RHobj.ObjectType == Rhino.DocObjects.ObjectType.Extrusion)
         {
             RC_List.Add(RHobj);
         }
     }
     if (RC_List.Count != 0)
     {
         Ret_NURBS_Scene = new RhCommon_Scene(RC_List, Air_Temp, Rel_Humidity, Atm_pressure, Atten_Choice, Edge_Freq, false);
         if (!Ret_NURBS_Scene.Valid) return Rhino.Commands.Result.Failure;
         Ret_Mesh_Scene = new Polygon_Scene(RC_List, Air_Temp, Rel_Humidity, Atm_pressure, Atten_Choice, Edge_Freq, false);
         if (!Ret_Mesh_Scene.Valid) return Rhino.Commands.Result.Failure;
     }
     C_Result = Rhino.Commands.Result.Success;
     return Rhino.Commands.Result.Success;
 }
Exemplo n.º 30
0
 void Test(TestFunc func, RhinoDoc doc)
 {
     RhinoApp.WriteLine("[TEST START] - " + func.Method.ToString());
     Rhino.Commands.Result rc = func(doc);
     RhinoApp.WriteLine("[TEST DONE] - result = " + rc.ToString());
 }
Exemplo n.º 31
0
    public static Rhino.Commands.Result ExplodeHatch(Rhino.RhinoDoc doc)
    {
        const ObjectType filter = Rhino.DocObjects.ObjectType.Hatch;

        Rhino.DocObjects.ObjRef objref;
        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 = objref.Geometry() as Rhino.Geometry.Hatch;
        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 = geom as Rhino.Geometry.Point;
                        if (null != point)
                        {
                            doc.Objects.AddPoint(point.Location);
                        }
                    }
                    break;

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

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

        return(Rhino.Commands.Result.Success);
    }