Example #1
0
        public Rhino.Commands.Result GetPoints(Rhino.RhinoDoc doc)
        {
            // Input interval
            var input = new Rhino.Input.Custom.GetNumber();
            // Select surface
            var go = new Rhino.Input.Custom.GetObject();

            go.SetCommandPrompt("Select point");
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Point;
            go.GetMultiple(1, 1);

            Rhino.Geometry.Point   pt     = go.Object(0).Point();
            Rhino.Geometry.Point3d pointA = pt.Location;

            go.SetCommandPrompt("Select surface");
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface;
            go.GetMultiple(1, 1);

            Rhino.Geometry.Surface surfaceB = go.Object(0).Surface();
            double u, v;

            if (surfaceB.ClosestPoint(pointA, out u, out v))
            {
                Rhino.Geometry.Point3d pointC = surfaceB.PointAt(u, v);

                Rhino.Geometry.Vector3d vector = pointA - pointC;
                // write list pointD
            }

            return(Rhino.Commands.Result.Success);
        }
Example #2
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var go = new Rhino.Input.Custom.GetObject();

            go.SetCommandPrompt("Select block to explode");
            go.GeometryFilter = ObjectType.InstanceReference;
            go.Get();
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            var iref = go.Object(0).Object() as Rhino.DocObjects.InstanceObject;

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

            var  xform = Transform.Identity;
            bool rc    = ExplodeBlockHelper(doc, iref, xform);

            if (rc)
            {
                doc.Objects.Delete(go.Object(0), false);
                doc.Views.Redraw();
            }

            return(Result.Success);
        }
Example #3
0
    public static Rhino.Commands.Result TweenCurve(Rhino.RhinoDoc doc)
    {
        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select two curves");
        go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
        go.GetMultiple(2, 2);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        Rhino.Geometry.Curve curve0 = go.Object(0).Curve();
        Rhino.Geometry.Curve curve1 = go.Object(1).Curve();
        if (null != curve0 && null != curve1)
        {
            Rhino.Geometry.Curve[] curves = Rhino.Geometry.Curve.CreateTweenCurves(curve0, curve1, 1);
            if (null != curves)
            {
                for (int i = 0; i < curves.Length; i++)
                {
                    doc.Objects.AddCurve(curves[i]);
                }

                doc.Views.Redraw();
                return(Rhino.Commands.Result.Success);
            }
        }

        return(Rhino.Commands.Result.Failure);
    }
Example #4
0
    public static Rhino.Commands.Result AddObjectsToGroup(Rhino.RhinoDoc doc)
    {
        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select objects to group");
        go.GroupSelect = true;
        go.GetMultiple(1, 0);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        List <Guid> ids = new List <Guid>();

        for (int i = 0; i < go.ObjectCount; i++)
        {
            ids.Add(go.Object(i).ObjectId);
        }
        int index = doc.Groups.Add(ids);

        doc.Views.Redraw();
        if (index >= 0)
        {
            return(Rhino.Commands.Result.Success);
        }
        return(Rhino.Commands.Result.Failure);
    }
    public static Rhino.Commands.Result Sweep1(Rhino.RhinoDoc doc)
    {
        Rhino.DocObjects.ObjRef rail_ref;
        var rc = RhinoGet.GetOneObject("Select rail curve", false, Rhino.DocObjects.ObjectType.Curve, out rail_ref);

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

        var rail_crv = rail_ref.Curve();

        if (rail_crv == null)
        {
            return(Rhino.Commands.Result.Failure);
        }

        var gx = new Rhino.Input.Custom.GetObject();

        gx.SetCommandPrompt("Select cross section curves");
        gx.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
        gx.EnablePreSelect(false, true);
        gx.GetMultiple(1, 0);
        if (gx.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gx.CommandResult());
        }

        var cross_sections = new List <Rhino.Geometry.Curve>();

        for (int i = 0; i < gx.ObjectCount; i++)
        {
            var crv = gx.Object(i).Curve();
            if (crv != null)
            {
                cross_sections.Add(crv);
            }
        }
        if (cross_sections.Count < 1)
        {
            return(Rhino.Commands.Result.Failure);
        }

        var sweep = new Rhino.Geometry.SweepOneRail();

        sweep.AngleToleranceRadians = doc.ModelAngleToleranceRadians;
        sweep.ClosedSweep           = false;
        sweep.SweepTolerance        = doc.ModelAbsoluteTolerance;
        sweep.SetToRoadlikeTop();
        var breps = sweep.PerformSweep(rail_crv, cross_sections);

        for (int i = 0; i < breps.Length; i++)
        {
            doc.Objects.AddBrep(breps[i]);
        }
        doc.Views.Redraw();
        return(Rhino.Commands.Result.Success);
    }
Example #6
0
    public static Rhino.Commands.Result ConstrainedCopy(Rhino.RhinoDoc doc)
    {
        // Get a single planar closed curve
        var go = new Rhino.Input.Custom.GetObject();

        go.SetCommandPrompt("Select curve");
        go.GeometryFilter          = Rhino.DocObjects.ObjectType.Curve;
        go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve;
        go.Get();
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }
        var objref      = go.Object(0);
        var base_curve  = objref.Curve();
        var first_point = objref.SelectionPoint();

        if (base_curve == null || !first_point.IsValid)
        {
            return(Rhino.Commands.Result.Cancel);
        }

        Rhino.Geometry.Plane plane;
        if (!base_curve.TryGetPlane(out plane))
        {
            return(Rhino.Commands.Result.Cancel);
        }

        // Get a point constrained to a line passing through the initial selection
        // point and parallel to the plane's normal
        var gp = new Rhino.Input.Custom.GetPoint();

        gp.SetCommandPrompt("Offset point");
        gp.DrawLineFromPoint(first_point, true);
        var line = new Rhino.Geometry.Line(first_point, first_point + plane.Normal);

        gp.Constrain(line);
        gp.Get();
        if (gp.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gp.CommandResult());
        }
        var second_point = gp.Point();

        Rhino.Geometry.Vector3d vec = second_point - first_point;
        if (vec.Length > 0.001)
        {
            var  xf = Rhino.Geometry.Transform.Translation(vec);
            Guid id = doc.Objects.Transform(objref, xf, false);
            if (id != Guid.Empty)
            {
                doc.Views.Redraw();
                return(Rhino.Commands.Result.Success);
            }
        }
        return(Rhino.Commands.Result.Cancel);
    }
Example #7
0
    public static Rhino.Commands.Result IntersectCurves(Rhino.RhinoDoc doc)
    {
        // Select two curves to intersect
        var go = new Rhino.Input.Custom.GetObject();

        go.SetCommandPrompt("Select two curves");
        go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
        go.GetMultiple(2, 2);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        // Validate input
        var curveA = go.Object(0).Curve();
        var curveB = go.Object(1).Curve();

        if (curveA == null || curveB == null)
        {
            return(Rhino.Commands.Result.Failure);
        }

        // Calculate the intersection
        const double intersection_tolerance = 0.001;
        const double overlap_tolerance      = 0.0;
        var          events = Rhino.Geometry.Intersect.Intersection.CurveCurve(curveA, curveB, intersection_tolerance, overlap_tolerance);

        // Process the results
        if (events != null)
        {
            for (int i = 0; i < events.Count; i++)
            {
                var ccx_event = events[i];
                doc.Objects.AddPoint(ccx_event.PointA);
                if (ccx_event.PointA.DistanceTo(ccx_event.PointB) > double.Epsilon)
                {
                    doc.Objects.AddPoint(ccx_event.PointB);
                    doc.Objects.AddLine(ccx_event.PointA, ccx_event.PointB);
                }
            }
            doc.Views.Redraw();
        }
        return(Rhino.Commands.Result.Success);
    }
Example #8
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Select objects to define block
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select surface or polysurface to box morph");
            go.GeometryFilter  = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.Brep;
            go.SubObjectSelect = false;
            go.Get();
            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }

            Rhino.Geometry.Brep brep = go.Object(0).Brep();
            if (null == brep)
            {
                return(Result.Failure);
            }

            Rhino.Geometry.BoundingBox bbox = brep.GetBoundingBox(true);

            // The original box points
            Rhino.Geometry.Point3d[] box = new Rhino.Geometry.Point3d[8];
            box[0] = bbox.Corner(true, true, true);
            box[1] = bbox.Corner(false, true, true);
            box[2] = bbox.Corner(false, false, true);
            box[3] = bbox.Corner(true, false, true);
            box[4] = bbox.Corner(true, true, false);
            box[5] = bbox.Corner(false, true, false);
            box[6] = bbox.Corner(false, false, false);
            box[7] = bbox.Corner(true, false, false);

            // The modified box points
            Rhino.Geometry.Point3d[] corners = new Rhino.Geometry.Point3d[8];
            corners[0] = box[0];
            corners[1] = box[1];
            corners[2] = box[2];
            corners[3] = box[3];
            corners[4] = box[4];
            corners[5] = box[5];
            corners[6] = box[6] * 2; // some goofy point
            corners[7] = box[7];

            BoxMorph box_morph = new BoxMorph(box, corners);

            if (box_morph.IsValid() && !box_morph.IsIdentity())
            {
                if (box_morph.Morph(brep))
                {
                    doc.Objects.Add(brep);
                    doc.Views.Redraw();
                }
            }

            return(Result.Success);
        }
    public static Rhino.Commands.Result HatchCurve(Rhino.RhinoDoc doc)
    {
        var go = new Rhino.Input.Custom.GetObject();

        go.SetCommandPrompt("Select closed planar curve");
        go.GeometryFilter          = Rhino.DocObjects.ObjectType.Curve;
        go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve;
        go.SubObjectSelect         = false;
        go.Get();
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

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

        if (curve == null || !curve.IsClosed || !curve.IsPlanar())
        {
            return(Rhino.Commands.Result.Failure);
        }

        string hatch_name = doc.HatchPatterns[doc.HatchPatterns.CurrentHatchPatternIndex].Name;
        var    rc         = Rhino.Input.RhinoGet.GetString("Hatch pattern", true, ref hatch_name);

        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }
        hatch_name = hatch_name.Trim();
        if (string.IsNullOrWhiteSpace(hatch_name))
        {
            return(Rhino.Commands.Result.Nothing);
        }
        int index = doc.HatchPatterns.Find(hatch_name, true);

        if (index < 0)
        {
            Rhino.RhinoApp.WriteLine("Hatch pattern does not exist.");
            return(Rhino.Commands.Result.Nothing);
        }

        var hatches = Rhino.Geometry.Hatch.Create(curve, index, 0, 1);

        for (int i = 0; i < hatches.Length; i++)
        {
            doc.Objects.AddHatch(hatches[i]);
        }
        if (hatches.Length > 0)
        {
            doc.Views.Redraw();
        }
        return(Rhino.Commands.Result.Success);
    }
Example #10
0
        protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
        {
            // Input interval
            var input = new Rhino.Input.Custom.GetNumber();
            // Select surface
            var go = new Rhino.Input.Custom.GetObject();

            go.SetCommandPrompt("Select points");
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Point;
            Rhino.Input.GetResult res = go.GetMultiple(1, 0);
            if (res == Rhino.Input.GetResult.Nothing)
            {
                return(Rhino.Commands.Result.Failure);
            }

            RhinoApp.WriteLine("Points {0} were selected", go.ObjectCount);

            try
            {
                SaveFileDialog dialog = new SaveFileDialog();
                dialog.FileName = "PointFile.xyz";
                dialog.Filter   = "XYZ file|*.xyz|text file|*.txt";
                dialog.Title    = "Save point cloud file";
                dialog.ShowDialog();

                if (dialog.FileName == "")
                {
                    return(Rhino.Commands.Result.Failure);
                }

                FileStream   fileStream = (System.IO.FileStream)dialog.OpenFile(); //  new FileStream(@"C:\Users\KTW\Documents\PointFile.xyz", FileMode.Create, FileAccess.Write);
                StreamWriter writer     = new StreamWriter(fileStream);

                for (int i = 0; i < go.ObjectCount; i++)
                {
                    Rhino.Geometry.Point   pt   = go.Object(i).Point();
                    Rhino.Geometry.Point3d pt3d = pt.Location;

                    string text = pt3d.X + " " + pt3d.Y + " " + pt3d.Z;
                    writer.WriteLine(text);
                }

                RhinoApp.WriteLine("File was saved");
                fileStream.Close();
            }
            catch (Exception e)
            {
                RhinoApp.WriteLine("{0}", e.Message);
            }

            return(Rhino.Commands.Result.Success);
        }
  public static Rhino.Commands.Result IntersectCurves(Rhino.RhinoDoc doc)
  {
    // Select two curves to intersect
    var go = new Rhino.Input.Custom.GetObject();
    go.SetCommandPrompt("Select two curves");
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
    go.GetMultiple(2, 2);
    if (go.CommandResult() != Rhino.Commands.Result.Success)
      return go.CommandResult();

    // Validate input
    var curveA = go.Object(0).Curve();
    var curveB = go.Object(1).Curve();
    if (curveA == null || curveB == null)
      return Rhino.Commands.Result.Failure;

    // Calculate the intersection
    const double intersection_tolerance = 0.001;
    const double overlap_tolerance = 0.0;
    var events = Rhino.Geometry.Intersect.Intersection.CurveCurve(curveA, curveB, intersection_tolerance, overlap_tolerance);

    // Process the results
    if (events != null)
    {
      for (int i = 0; i < events.Count; i++)
      {
        var ccx_event = events[i];
        doc.Objects.AddPoint(ccx_event.PointA);
        if (ccx_event.PointA.DistanceTo(ccx_event.PointB) > double.Epsilon)
        {
          doc.Objects.AddPoint(ccx_event.PointB);
          doc.Objects.AddLine(ccx_event.PointA, ccx_event.PointB);
        }
      }
      doc.Views.Redraw();
    }
    return Rhino.Commands.Result.Success;
  }
    public static Rhino.Commands.Result LineBetweenCurves(Rhino.RhinoDoc doc)
    {
        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select two curves");
        go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
        go.GetMultiple(2, 2);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        Rhino.DocObjects.ObjRef objRef0 = go.Object(0);
        Rhino.DocObjects.ObjRef objRef1 = go.Object(1);

        double t0 = Rhino.RhinoMath.UnsetValue;
        double t1 = Rhino.RhinoMath.UnsetValue;

        Rhino.Geometry.Curve curve0 = objRef0.CurveParameter(out t0);
        Rhino.Geometry.Curve curve1 = objRef1.CurveParameter(out t1);
        if (null == curve0 || !Rhino.RhinoMath.IsValidDouble(t0) ||
            null == curve1 || !Rhino.RhinoMath.IsValidDouble(t1))
        {
            return(Rhino.Commands.Result.Failure);
        }

        Rhino.Geometry.Line line = Rhino.Geometry.Line.Unset;
        bool rc = Rhino.Geometry.Line.TryCreateBetweenCurves(curve0, curve1, ref t0, ref t1, false, false, out line);

        if (rc)
        {
            if (Guid.Empty != doc.Objects.AddLine(line))
            {
                doc.Views.Redraw();
                return(Rhino.Commands.Result.Success);
            }
        }
        return(Rhino.Commands.Result.Failure);
    }
Example #13
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);
    }
Example #14
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: complete command.
            RhinoApp.WriteLine("The {0} command is under construction.", EnglishName);

            Rhino.Input.Custom.GetObject gmesh = new Rhino.Input.Custom.GetObject();
            gmesh.SetCommandPrompt("Get the Mesh");
            gmesh.GeometryFilter  = Rhino.DocObjects.ObjectType.Mesh;
            gmesh.SubObjectSelect = true;
            gmesh.Get();
            if (gmesh.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gmesh.CommandResult());
            }
            Rhino.DocObjects.ObjRef      objref = gmesh.Object(0);
            Rhino.DocObjects.RhinoObject obj    = objref.Object();
            if (obj == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            Rhino.Geometry.Mesh mesh = objref.Mesh();
            if (mesh == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            obj.Select(false);

            MeshTextureCoordinateList texture_list = mesh.TextureCoordinates;

            for (int i = 0; i < texture_list.Count - 1; i++)
            {
                Point2f f1 = texture_list[i];
                Point2f f2 = texture_list[i + 1];
                Point3d t1 = new Point3d(f1.X, f1.Y, 0);
                Point3d t2 = new Point3d(f2.X, f2.Y, 0);
                Line    l  = new Line(t1, t2);
                doc.Objects.AddLine(l);
                RhinoApp.WriteLine("Line added");
            }
            doc.Views.Redraw();
            MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance;

            p.painted_object_        = mesh;
            p.if_painted_object_set_ = true;
            mesh.UserDictionary.Set("name", "myMesh");
            mesh.UserDictionary.Set("isMovable", false);
            p.graph = new DijkstraGraph(10);
            RhinoApp.WriteLine("Mesh Got");
            return(Result.Success);
        }
Example #15
0
        public Rhino.Commands.Result delete(Rhino.RhinoDoc doc)
        {
            // Input incomplate
            double _incomplate = 0.1;

            var input = new Rhino.Input.Custom.GetNumber();

            input.SetCommandPrompt("Input incomplate(0.0 ~ 1.0)<0.1>");
            Rhino.Input.GetResult res = input.Get();
            if (res == Rhino.Input.GetResult.Number)
            {
                _incomplate = input.Number();
            }
            if (_incomplate == 0.0)
            {
                _incomplate = 0.1;
            }

            // Select surface
            var go = new Rhino.Input.Custom.GetObject();

            go.SetCommandPrompt("Select elements");
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Point;
            res = go.GetMultiple(1, 1024 * 10);
            if (res == Rhino.Input.GetResult.Nothing)
            {
                return(Rhino.Commands.Result.Failure);
            }

            System.Collections.Generic.List <Guid> list = new System.Collections.Generic.List <Guid>();
            for (int i = 0; i < go.ObjectCount; i++)
            {
                Guid guid = go.Object(i).ObjectId;
                list.Add(guid);
            }

            int deleteCount = (int)((double)(list.Count) * _incomplate);

            Rhino.DocObjects.Tables.ObjectTable ot = Rhino.RhinoDoc.ActiveDoc.Objects;
            for (int i = 0; i < deleteCount; i++)
            {
                Guid guid = list[i];
                ot.Delete(guid, true);
            }

            return(Rhino.Commands.Result.Success);
        }
Example #16
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);
    }
Example #17
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select surface or polysurface to smash");
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.PolysrfFilter;
            go.Get();
            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }

            Rhino.Geometry.Brep brep = go.Object(0).Brep();
            if (null == brep)
            {
                return(Rhino.Commands.Result.Failure);
            }

            Rhino.Geometry.Unroller unroller = new Rhino.Geometry.Unroller(brep);
            unroller.AbsoluteTolerance = doc.ModelAbsoluteTolerance;
            unroller.RelativeTolerance = 1.0; // big relative tolerance for smash
            unroller.ExplodeSpacing    = 2.0;
            unroller.ExplodeOutput     = true;

            Rhino.Geometry.Curve[]   unrolledCurves = null;
            Rhino.Geometry.Point3d[] unrolledPoints = null;
            Rhino.Geometry.TextDot[] unrolledDots   = null;

            Rhino.Geometry.Brep[] output = unroller.PerformUnroll(out unrolledCurves, out unrolledPoints, out unrolledDots);
            if (null != output)
            {
                for (int i = 0; i < output.Length; i++)
                {
                    doc.Objects.Add(output[i]);
                }
            }

            doc.Views.Redraw();

            return(Rhino.Commands.Result.Success);
        }
  public static Rhino.Commands.Result HatchCurve(Rhino.RhinoDoc doc)
  {
    var go = new Rhino.Input.Custom.GetObject();
    go.SetCommandPrompt("Select closed planar curve");
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
    go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve;
    go.SubObjectSelect = false;
    go.Get();
    if( go.CommandResult() != Rhino.Commands.Result.Success )
      return go.CommandResult();

    var curve = go.Object(0).Curve();
    if( curve==null || !curve.IsClosed || !curve.IsPlanar() )
      return Rhino.Commands.Result.Failure;

    string hatch_name = doc.HatchPatterns[doc.HatchPatterns.CurrentHatchPatternIndex].Name;
    var rc = Rhino.Input.RhinoGet.GetString("Hatch pattern", true, ref hatch_name);
    if( rc!= Rhino.Commands.Result.Success )
      return rc;
    hatch_name = hatch_name.Trim();
    if( string.IsNullOrWhiteSpace(hatch_name) )
      return Rhino.Commands.Result.Nothing;
    int index = doc.HatchPatterns.Find(hatch_name, true);
    if( index < 0 )
    {
      Rhino.RhinoApp.WriteLine("Hatch pattern does not exist.");
      return Rhino.Commands.Result.Nothing;
    }

    var hatches = Rhino.Geometry.Hatch.Create( curve, index, 0, 1);
    for( int i=0; i<hatches.Length; i++ )
      doc.Objects.AddHatch(hatches[i]);
    if( hatches.Length>0 )
      doc.Views.Redraw();
    return Rhino.Commands.Result.Success;
  }
    public static Rhino.Commands.Result ExtrudeBrepFace(Rhino.RhinoDoc doc)
    {
        Rhino.Input.Custom.GetObject go0 = new Rhino.Input.Custom.GetObject();
        go0.SetCommandPrompt("Select surface to extrude");
        go0.GeometryFilter = Rhino.DocObjects.ObjectType.Surface;
        go0.SubObjectSelect = true;
        go0.Get();
        if (go0.CommandResult() != Rhino.Commands.Result.Success)
          return go0.CommandResult();

        Rhino.Geometry.BrepFace face = go0.Object(0).Face();
        if (null == face)
          return Rhino.Commands.Result.Failure;

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

        Rhino.Geometry.Curve curve = go1.Object(0).Curve();
        if (null == curve)
          return Rhino.Commands.Result.Failure;

        Rhino.Geometry.Brep brep = face.CreateExtrusion(curve, true);
        if (null != brep)
        {
          doc.Objects.Add(brep);
          doc.Views.Redraw();
        }

        return Rhino.Commands.Result.Success;
    }
            ///<summary> This gets called when when the user runs this command.</summary> 
            protected override Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
            {
                SourceConduit m_source_conduit = SourceConduit.Instance;

                Rhino.Input.Custom.GetObject GO = new Rhino.Input.Custom.GetObject();
                GO.SetCommandPrompt("Select source curve...");
                GO.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
                GO.AddOption("TrafficWelsh");
                GO.AddOption("TrafficFHWA");
                GO.AddOption("AircraftANCON");
                GO.AddOption("Custom");
                //GO.AddOptionList("SourceType", new List<string>() { "TrafficWelshStandard", "TrafficFHWA Standard", "Custom" }, 2);
                GO.GroupSelect = false;
                GO.SubObjectSelect = false;
                GO.EnableClearObjectsOnEntry(false);
                GO.EnableUnselectObjectsOnExit(false);
                GO.DeselectAllBeforePostSelect = false;

                int pavement = 0;
                double SPLW = 0;
                double[] SWL = new double[] { 120, 120, 120, 120, 120, 120, 120, 120 };
                double velocity = 83;
                double delta = 45;
                double choice = 0;
                for (; ; )
                {
                    Rhino.Input.GetResult GR = GO.GetMultiple(1, 1);
                    int type = GO.OptionIndex();
                    if (GR == Rhino.Input.GetResult.Option)
                    {
                        choice = (int)type;
                        //type = GO.Option().EnglishName;
                        if (type == 1)//"Traffic (Welsh Standard)")
                        {
                            Rhino.Input.RhinoGet.GetNumber("Input basis road sound pressure level at 1 m from street...", false, ref SPLW);
                            SPLW += 8;
                        }
                        else if (type == 2)//"Traffic (FHWA Standard)")
                        {
                            ///Described at:
                            ///http://www.fhwa.dot.gov/environment/noise/traffic_noise_model/old_versions/tnm_version_10/tech_manual/tnm03.cfm#tnma2

                            double s = 0;
                            //int i = 0;

                            Rhino.Input.RhinoGet.GetNumber("Enter the speed of traffic on this road (in kph)...", false, ref s);

                            ///Pavement
                            Rhino.Input.Custom.GetOption GOpt = new Rhino.Input.Custom.GetOption();
                            GOpt.SetCommandPrompt("Pavement type...");
                            GOpt.AddOption("Average_DGAC_PCC)");
                            GOpt.AddOption("DGAC_Asphalt");
                            GOpt.AddOption("PCC_Concrete");
                            GOpt.AddOption("OGAC_OpenGradedAsphalt");
                            GOpt.AcceptNothing(false);
                            GOpt.Get();
                            pavement = GOpt.OptionIndex();

                            ///Vehicle tallies
                            double[] Veh = new double[5] { 0, 0, 0, 0, 0 };
                            Rhino.Input.RhinoGet.GetNumber("Enter the number of automobiles per hour...", false, ref Veh[0]);
                            Rhino.Input.RhinoGet.GetNumber("Enter the number of medium trucks per hour...", false, ref Veh[1]);
                            Rhino.Input.RhinoGet.GetNumber("Enter the number of heavy trucks per hour...", false, ref Veh[2]);
                            Rhino.Input.RhinoGet.GetNumber("Enter the number of buses per hour...", false, ref Veh[3]);
                            Rhino.Input.RhinoGet.GetNumber("Enter the number of motorcycles per hour...", false, ref Veh[4]);

                            bool throttle = false;
                            int t = 0;
                            Rhino.Input.RhinoGet.GetBool("Full throttle?", false, "Yes", "No", ref throttle);
                            t = (throttle) ? 1 : 0;
                            double root2 = Math.Sqrt(2);
                            double vtot = 0;
                            double[] Es = new double[8] { 0, 0, 0, 0, 0, 0, 0, 0 };

                            for (int v = 0; v < 5; v++)
                            {
                                double A = FHWATraffic[v][pavement][t][0];
                                double B = FHWATraffic[v][pavement][t][1];
                                double C = FHWATraffic[v][pavement][t][2];
                                double D1 = FHWATraffic[v][pavement][t][3];
                                double D2 = FHWATraffic[v][pavement][t][4];
                                double E1 = FHWATraffic[v][pavement][t][5];
                                double E2 = FHWATraffic[v][pavement][t][6];
                                double F1 = FHWATraffic[v][pavement][t][7];
                                double F2 = FHWATraffic[v][pavement][t][8];
                                double G1 = FHWATraffic[v][pavement][t][9];
                                double G2 = FHWATraffic[v][pavement][t][10];
                                double H1 = FHWATraffic[v][pavement][t][11];
                                double H2 = FHWATraffic[v][pavement][t][12];
                                double I1 = FHWATraffic[v][pavement][t][13];
                                double I2 = FHWATraffic[v][pavement][t][14];
                                double J1 = FHWATraffic[v][pavement][t][15];
                                double J2 = FHWATraffic[v][pavement][t][16];

                                vtot += Veh[v];

                                for (int oct = 0; oct < 8; oct++)
                                {
                                    double f = 62.5 * Math.Pow(2, oct);
                                    double[] freq = new double[3] { f / root2, f, f * root2 };

                                    for (int oct3 = 0; oct3 < 3; oct3++)
                                    {
                                        double Ea = Math.Pow(0.6214 * s, A / 10) * Math.Pow(10, B / 10) + Math.Pow(10, C / 10);
                                        double logf = Math.Log10(freq[oct3]);
                                        double Ls = 10 * Math.Log10(Ea) + (D1 + 0.6214 * D2 * s) + (E1 + 0.6214 * E2 * s) * logf
                                            + (F1 + 0.6214 * F2 * s) * logf * logf + (G1 + 0.6214 * G2 * s) * logf * logf * logf
                                            + (H1 + 0.6214 * H2 * s) * logf * logf * logf * logf + (I1 + 0.6214 * I2 * s) * logf * logf * logf * logf * logf
                                            + (J1 + 0.6214 * J2 * s) * logf * logf * logf * logf * logf * logf;
                                        Es[oct] += 0.0476 * Math.Pow(10, Ls / 10) * Veh[v] / s;
                                    }
                                }
                            }

                            double[] Awt = new double[8] { -26, -16, -9, -3, 0, 1.2, 1, -1 };
                            double dmod = 10 * Math.Log10(1 / (Utilities.Numerics.PiX2 * 15));

                            for (int oct = 0; oct < 8; oct++)
                            {
                                SWL[oct] = 10 * Math.Log10(Es[oct]) - Awt[oct] - dmod;//
                            }
                        }
                        else if (type == 3)//"Aircraft (ANCON-derived)")
                        {
                            Rhino.Input.Custom.GetOption GOpt = new Rhino.Input.Custom.GetOption();
                            GOpt.SetCommandPrompt("Takeoff or Landing?");
                            GOpt.AddOption("Takeoff");
                            GOpt.AddOption("Landing");
                            GOpt.AddOption("Both");
                            GOpt.AcceptNothing(false);
                            GOpt.Get();
                            int TL_Choice = GOpt.OptionIndex();

                            double SWLA = 150;

                            Rhino.Input.RhinoGet.GetNumber("What is the broadband sound power of the aircraft (in dBA)?", false, ref SWLA);
                            Rhino.Input.RhinoGet.GetNumber("What is the maximum velocity of the aircraft in m/s?", false, ref velocity);
                            Rhino.Input.RhinoGet.GetNumber("What is the slant angle for this aircraft?", false, ref delta);

                            double[][] Aircraft_Normalization = new double[3][] {
                                //new double[8]{ -12, -10.5, -12, -15, -20, -27, -40, -44},
                                //new double[8]{-11, -13, -12, -13.5, -18, -21, -25, -35},
                                //new double[8]{-11, -10.5, -12, -13.5, -18, -21, -25, -35}
                            new double[8] { 6.191472203, 7.691472203, 6.191472203, 3.191472203, -1.808527797, -8.808527797,-21.8085278, -25.8085278},
                            new double[8] { 5.6783811710, 3.6783811710, 4.678381171, 3.178381171, -1.321618829, -4.321618829, -8.321618829, -18.32161883},
                            new double[8] { 5.678381171, 6.178381171, 4.678381171, 3.178381171, -1.321618829, -4.321618829, -8.321618829, -18.32161883}
                            };

                            for (int oct = 0; oct < 8; oct++)
                            {
                                SWL[oct] = SWLA + Aircraft_Normalization[TL_Choice-1][oct];//
                            }
                        }
                        //    continue;
                        //    //return Result.Success;
                        //}
                    }
                    else if (GR == Rhino.Input.GetResult.Object)
                    {
                        for (int i = 0; i < GO.ObjectCount; i++)
                        {
                            Rhino.DocObjects.ObjRef obj = GO.Object(i);

                            Rhino.DocObjects.RhinoObject rhObj = doc.Objects.Find(obj.ObjectId);

                            rhObj.Attributes.Name = "Acoustical Source";

                            if (choice == 1)//"Traffic (Welsh Standard)")
                            {
                                rhObj.Geometry.SetUserString("SourceType", "Traffic (Welsh)");
                                for (int oct = 0; oct < 8; oct++) SWL[oct] = SPLW + WelshTraffic[oct];
                            }
                            else if (choice == 2)//"Traffic (FWHA Standard)")
                            {
                                rhObj.Geometry.SetUserString("SourceType", "Traffic (FHWA)");
                            }
                            else if (choice == 3)//"Aircraft (ANCON-derived)")
                            {
                                rhObj.Geometry.SetUserString("SourceType", "Aircraft (ANCON derived)");
                                rhObj.Geometry.SetUserString("Velocity", velocity.ToString());
                                rhObj.Geometry.SetUserString("delta", delta.ToString());
                            }
                            else
                            {
                                Rhino.Input.RhinoGet.GetNumber("62.5 Hz. Sound Power Level", true, ref SWL[0]);
                                Rhino.Input.RhinoGet.GetNumber("125 Hz. Sound Power Level", true, ref SWL[1]);
                                Rhino.Input.RhinoGet.GetNumber("250 Hz. Sound Power Level", true, ref SWL[2]);
                                Rhino.Input.RhinoGet.GetNumber("500 Hz. Sound Power Level", true, ref SWL[3]);
                                Rhino.Input.RhinoGet.GetNumber("1000 Hz. Sound Power Level", true, ref SWL[4]);
                                Rhino.Input.RhinoGet.GetNumber("2000 Hz. Sound Power Level", true, ref SWL[5]);
                                Rhino.Input.RhinoGet.GetNumber("4000 Hz. Sound Power Level", true, ref SWL[6]);
                                Rhino.Input.RhinoGet.GetNumber("8000 Hz. Sound Power Level", true, ref SWL[7]);
                            }

                            rhObj.Geometry.SetUserString("SWL", Utilities.PachTools.EncodeSourcePower(SWL));
                            rhObj.Geometry.SetUserString("Phase", "0;0;0;0;0;0;0;0");
                            doc.Objects.ModifyAttributes(rhObj, rhObj.Attributes, true);

                            m_source_conduit.SetSource(rhObj);
                        }

                        doc.Views.Redraw();
                        return Result.Success;
                    }
                    else return Result.Cancel;
                }
            }
            ///<summary> This gets called when when the user runs this command.</summary> 
            protected override Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
            {
                SourceConduit m_source_conduit = SourceConduit.Instance;

                //Rhino.DocObjects.ObjRef location;

                string type = "custom";

                Rhino.Input.Custom.GetObject GO = new Rhino.Input.Custom.GetObject();
                GO.SetCommandPrompt("Select source surface...");
                GO.GeometryFilter = Rhino.DocObjects.ObjectType.Brep;
                GO.AddOption("Crowd");
                GO.GroupSelect = false;
                GO.SubObjectSelect = false;
                GO.EnableClearObjectsOnEntry(false);
                GO.EnableUnselectObjectsOnExit(false);
                GO.DeselectAllBeforePostSelect = false;

                int Men = 100, Women = 100, Kids = 100, effort = 0;

                do
                {
                    Rhino.Input.GetResult GR = GO.Get();

                    if (GR == Rhino.Input.GetResult.Option)
                    {
                        type = GO.Option().EnglishName;
                        if (type == "Crowd")
                        {
                            Rhino.Input.RhinoGet.GetInteger("Number of Men in Crowd...", true, ref Men);
                            Rhino.Input.RhinoGet.GetInteger("Number of Women in Crowd...", true, ref Women);
                            Rhino.Input.RhinoGet.GetInteger("Number of Children in Crowd...", true, ref Kids);

                            Rhino.Input.Custom.GetOption GOpt = new Rhino.Input.Custom.GetOption();
                            GOpt.SetCommandPrompt("Speech Activity");
                            GOpt.AddOption("SoftOrWhispered");
                            GOpt.AddOption("Conversation");
                            GOpt.AddOption("CompetingConversation");
                            GOpt.AddOption("Singing");
                            GOpt.AddOption("AllShouting");
                            GOpt.AcceptNothing(false);

                            GOpt.Get();
                            effort = GOpt.OptionIndex() - 1;
                        }
                        continue;
                    }
                    else if (GR == Rhino.Input.GetResult.Object)
                    {
                        for (int i = 0; i < GO.ObjectCount; i++)
                        {
                            Rhino.DocObjects.ObjRef obj = GO.Object(i);

                            Rhino.DocObjects.RhinoObject rhObj = doc.Objects.Find(obj.ObjectId);

                            double Area = (rhObj.Geometry as Rhino.Geometry.Brep).GetArea();

                            rhObj.Attributes.Name = "Acoustical Source";
                            rhObj.Geometry.SetUserString("SourceType", "");

                            double[] SPL = new double[] { 120, 120, 120, 120, 120, 120, 120, 120 };

                            if (type == "Crowd")
                            {
                                //double mod = (effort < 3) ? .5 : 1;

                                //Correct for tightly packed spaces, and competing speech.
                                //if (Area / (Men + Women + Kids) < 3.0f)
                                //{
                                //    //In overcrowded scenarios, vocal effort escalates as such:
                                //    //whispering becomes conversation.
                                //    //conversation becomes competing conversation.
                                //    //competing conversation becomes shouting.
                                //    //Singing stays singing... I'm pretty sure experienced singers wouldn't start shouting...
                                //    if (effort < 2) effort++;
                                //    else effort = 4;
                                //}

                                for (int oct = 0; oct < 8; oct++)
                                {
                                    double Power = Men * Math.Pow(10, Males[effort][oct] / 10) + Women * Math.Pow(10, Females[effort][oct] / 10) + Kids * Math.Pow(10, Children[effort][oct] / 10);
                                    //Power /= (Area);
                                    SPL[oct] = 10 * Math.Log10(Power) + 11;
                                }
                            }
                            else
                            {
                                Rhino.Input.RhinoGet.GetNumber("62.5 Hz. Sound Power Level", true, ref SPL[0]);
                                Rhino.Input.RhinoGet.GetNumber("125 Hz. Sound Power Level", true, ref SPL[1]);
                                Rhino.Input.RhinoGet.GetNumber("250 Hz. Sound Power Level", true, ref SPL[2]);
                                Rhino.Input.RhinoGet.GetNumber("500 Hz. Sound Power Level", true, ref SPL[3]);
                                Rhino.Input.RhinoGet.GetNumber("1000 Hz. Sound Power Level", true, ref SPL[4]);
                                Rhino.Input.RhinoGet.GetNumber("2000 Hz. Sound Power Level", true, ref SPL[5]);
                                Rhino.Input.RhinoGet.GetNumber("4000 Hz. Sound Power Level", true, ref SPL[6]);
                                Rhino.Input.RhinoGet.GetNumber("8000 Hz. Sound Power Level", true, ref SPL[7]);
                            }

                            rhObj.Geometry.SetUserString("SWL", Utilities.PachTools.EncodeSourcePower(SPL));
                            rhObj.Geometry.SetUserString("Phase", "0;0;0;0;0;0;0;0");
                            doc.Objects.ModifyAttributes(rhObj, rhObj.Attributes, true);

                            m_source_conduit.SetSource(rhObj);
                        }

                        doc.Views.Redraw();
                        return Result.Success;
                    }
                    else return Result.Cancel;
                } while (true);
            }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Point;

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Pick all the points that you want to change to reinforcement.");
            go.GeometryFilter  = geometryFilter;
            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;

            bool bHavePreselectedObjects = false;

            for (;;)
            {
                Rhino.Input.GetResult res = go.GetMultiple(1, 0);

                /*
                 * if (res == Rhino.Input.GetResult.Option)
                 * {
                 *  go.EnablePreSelect(false, true);
                 *  continue;
                 * }
                 * else if (res != Rhino.Input.GetResult.Option)
                 * {
                 *  return Rhino.Commands.Result.Cancel;
                 * }
                 */
                if (go.ObjectsWerePreselected)
                {
                    bHavePreselectedObjects = true;
                    go.EnablePreSelect(false, true);
                    continue;
                }
                break;
            }

            List <Point3d> points = new List <Point3d>();

            if (bHavePreselectedObjects)
            {
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    RhinoObject rhinoObject = go.Object(i).Object();
                    if (null != rhinoObject)
                    {
                        rhinoObject.Select(false);
                    }
                }
                doc.Views.Redraw();
            }

            int layerIndex = getLayerIndex(doc, "Reinforcement");

            doc.Layers[layerIndex].Color = Color.Black;
            if (layerIndex == 999)
            {
                return(Result.Failure);
            }

            ObjRef[] objects = go.Objects();
            foreach (ObjRef obj in objects)
            {
                Point3d point = obj.Point().Location;

                //TODO add the functionality how to assign different steel materials.
                Reinforcement reinf = new Reinforcement(ProjectPlugIn.Instance.CurrentBeam)
                {
                    Material = new SteelMaterial("B500B", SteelType.Reinforcement, ProjectPlugIn.Instance.CurrentBeam),
                    Centroid = point,
                    Diameter = 8
                };



                ObjectAttributes attr = new ObjectAttributes();
                attr.UserData.Add(reinf);
                attr.SetUserString("Name", "Reinforcement");
                attr.LayerIndex = layerIndex;

                //Unused code to create a hatch around the point

                /*
                 * doc.Objects.AddCurve(reinf.OutLine,attr);
                 * ObjectAttributes attrHatch = new ObjectAttributes();
                 * attrHatch.LayerIndex = layerIndex;
                 * doc.Objects.AddHatch(reinf.Hatch, attrHatch);
                 */


                doc.Objects.ModifyAttributes(obj, attr, true);
            }



            return(Result.Success);
        }
 /// <summary>
 /// Select an object for object name display
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void GetObjectForName(object sender, EventArgs e)
 {
   using (Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject())
   {
     go.SetCommandPrompt(Rhino.UI.Localization.LocalizeString("Select object", 384));
     go.AcceptNothing(true);
     go.SubObjectSelect = false;
     go.DisablePreSelect();
     go.Get();
     if (go.CommandResult() == Rhino.Commands.Result.Success)
     {
       Rhino.DocObjects.ObjRef objref = go.Object(0);
       if (objref != null)
       {
         SelectedObjectId = objref.ObjectId;
         objref.Dispose();
       }
     }
   }
 }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select curves");
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
            go.GetMultiple(1, 0);
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            for (int i = 0; i < go.ObjectCount; i++)
            {
                Rhino.Geometry.Curve curve = go.Object(i).Curve();
                if (null == curve)
                {
                    return(Result.Failure);
                }

                if (curve is LineCurve)
                {
                    RhinoApp.WriteLine("Curve {0} is a line.", i);
                }
                else if (curve is ArcCurve)
                {
                    if (curve.IsClosed)
                    {
                        RhinoApp.WriteLine("Curve {0} is a circle.", i);
                    }
                    else
                    {
                        RhinoApp.WriteLine("Curve {0} is an arc.", i);
                    }
                }
                else if (curve is PolylineCurve)
                {
                    RhinoApp.WriteLine("Curve {0} is a polyline.", i);
                }
                else if (curve is PolyCurve)
                {
                    RhinoApp.WriteLine("Curve {0} is a polycurve.", i);
                }
                else if (curve is NurbsCurve)
                {
                    if (curve.IsEllipse())
                    {
                        if (curve.IsClosed)
                        {
                            RhinoApp.WriteLine("Curve {0} is an ellipse.", i);
                        }
                        else
                        {
                            RhinoApp.WriteLine("Curve {0} is an elliptical arc.", i);
                        }
                    }
                    else
                    {
                        RhinoApp.WriteLine("Curve {0} is a NURBS curve.", i);
                    }
                }
                else
                {
                    RhinoApp.WriteLine("Curve {0} is an unknown type.", i);
                }
            }

            return(Result.Success);
        }
Example #25
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select sphere");
            go.GeometryFilter          = Rhino.DocObjects.ObjectType.Surface;
            go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedSurface;
            go.SubObjectSelect         = false;
            go.Get();
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            Rhino.Geometry.Brep brep = go.Object(0).Brep();
            if (null == brep || 1 != brep.Faces.Count)
            {
                return(Result.Failure);
            }

            Rhino.Geometry.Surface srf = brep.Faces[0].UnderlyingSurface();
            if (null == srf)
            {
                return(Result.Failure);
            }

            Rhino.Geometry.Sphere sphere;
            if (!srf.TryGetSphere(out sphere))
            {
                RhinoApp.WriteLine("Surface is not a sphere");
                return(Result.Nothing);
            }

            Rhino.Input.Custom.GetNumber gn = new Rhino.Input.Custom.GetNumber();
            gn.SetCommandPrompt("New radius");
            gn.SetDefaultNumber(sphere.Radius);
            gn.SetLowerLimit(1.0, false); // or whatever you deem appripriate...
            gn.Get();
            if (gn.CommandResult() != Result.Success)
            {
                return(gn.CommandResult());
            }

            sphere.Radius = gn.Number();

            // Sometimes, Surface.TryGetSphere() will return a sphere with a left-handed
            // plane. So, ensure the plane is right-handed.
            Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(
                sphere.EquitorialPlane.Origin,
                sphere.EquitorialPlane.XAxis,
                sphere.EquitorialPlane.YAxis
                );

            sphere.EquitorialPlane = plane;

            Rhino.Geometry.RevSurface rev_srf = sphere.ToRevSurface();
            if (null != rev_srf)
            {
                doc.Objects.Replace(go.Object(0).ObjectId, rev_srf);
                doc.Views.Redraw();
            }

            return(Result.Success);
        }
  public static Rhino.Commands.Result GetMultipleWithOptions(Rhino.RhinoDoc doc)
  {
    const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Surface | 
                                                       Rhino.DocObjects.ObjectType.PolysrfFilter | 
                                                       Rhino.DocObjects.ObjectType.Mesh;
    int integer1 = 300;
    int integer2 = 300;

    Rhino.Input.Custom.OptionInteger optionInteger1 = new Rhino.Input.Custom.OptionInteger(integer1, 200, 900);
    Rhino.Input.Custom.OptionInteger optionInteger2 = new Rhino.Input.Custom.OptionInteger(integer2, 200, 900);

    Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
    go.SetCommandPrompt("Select surfaces, polysurfaces, or meshes");
    go.GeometryFilter = geometryFilter;
    go.AddOptionInteger("Option1", ref optionInteger1);
    go.AddOptionInteger("Option2", ref optionInteger2);
    go.GroupSelect = true;
    go.SubObjectSelect = false;
    go.EnableClearObjectsOnEntry(false);
    go.EnableUnselectObjectsOnExit(false);
    go.DeselectAllBeforePostSelect = false;

    bool bHavePreselectedObjects = false;

    for (; ; )
    {
      Rhino.Input.GetResult res = go.GetMultiple(1, 0);

      if (res == Rhino.Input.GetResult.Option)
      {
        go.EnablePreSelect(false, true);
        continue;
      }

      else if (res != Rhino.Input.GetResult.Object)
        return Rhino.Commands.Result.Cancel;

      if (go.ObjectsWerePreselected)
      {
        bHavePreselectedObjects = true;
        go.EnablePreSelect(false, true);
        continue;
      }

      break;
    }

    if (bHavePreselectedObjects)
    {
      // Normally when command finishes, pre-selected objects will remain
      // selected, when and post-selected objects will be unselected.
      // With this sample, it is possible to have a combination of 
      // pre-selected and post-selected objects. To make sure everything
      // "looks the same", unselect everything before finishing the command.
      for (int i = 0; i < go.ObjectCount; i++)
      {
        Rhino.DocObjects.RhinoObject rhinoObject = go.Object(i).Object();
        if (null != rhinoObject)
          rhinoObject.Select(false);
      }
      doc.Views.Redraw();
    }

    int objectCount = go.ObjectCount;
    integer1 = optionInteger1.CurrentValue;
    integer2 = optionInteger2.CurrentValue;

    Rhino.RhinoApp.WriteLine("Select object count = {0}", objectCount);
    Rhino.RhinoApp.WriteLine("Value of integer1 = {0}", integer1);
    Rhino.RhinoApp.WriteLine("Value of integer2 = {0}", integer2);

    return Rhino.Commands.Result.Success;
  }
    public static Result ExtendSurface(RhinoDoc doc)
    {
        var go = new Rhino.Input.Custom.GetObject();

        go.SetCommandPrompt("Select edge of surface to extend");
        go.GeometryFilter          = ObjectType.EdgeFilter;
        go.GeometryAttributeFilter = GeometryAttributeFilter.EdgeCurve;
        go.Get();
        if (go.CommandResult() != Result.Success)
        {
            return(go.CommandResult());
        }
        var obj_ref = go.Object(0);

        var surface = obj_ref.Surface();

        if (surface == null)
        {
            RhinoApp.WriteLine("Unable to extend polysurfaces.");
            return(Result.Failure);
        }

        var brep = obj_ref.Brep();
        var face = obj_ref.Face();

        if (brep == null || face == null)
        {
            return(Result.Failure);
        }
        if (face.FaceIndex < 0)
        {
            return(Result.Failure);
        }

        if (!brep.IsSurface)
        {
            RhinoApp.WriteLine("Unable to extend trimmed surfaces.");
            return(Result.Nothing);
        }

        var curve = obj_ref.Curve();

        var trim = obj_ref.Trim();

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

        if (trim.TrimType == BrepTrimType.Seam)
        {
            RhinoApp.WriteLine("Unable to extend surface at seam.");
            return(Result.Nothing);
        }

        var extended_surface = surface.Extend(trim.IsoStatus, 5.0, true);

        if (extended_surface != null)
        {
            var mybrep = Brep.CreateFromSurface(extended_surface);
            doc.Objects.Replace(obj_ref.ObjectId, mybrep);
            doc.Views.Redraw();
        }
        return(Result.Success);
    }
        private Tuple <Brep[], Dictionary <int, List <Guid> > > GetObjectsToNest()
        {
            //Select Objects To Nest

            const Rhino.DocObjects.ObjectType geometryFilter =
                Rhino.DocObjects.ObjectType.Annotation |
                Rhino.DocObjects.ObjectType.TextDot |
                Rhino.DocObjects.ObjectType.Point |
                Rhino.DocObjects.ObjectType.Curve |
                Rhino.DocObjects.ObjectType.Surface |
                Rhino.DocObjects.ObjectType.PolysrfFilter |
                Rhino.DocObjects.ObjectType.Mesh;

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("OpenNest: Select objects for nesting");
            go.GeometryFilter  = geometryFilter;
            go.GroupSelect     = false;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(true);
            go.EnableUnselectObjectsOnExit(true);
            go.DeselectAllBeforePostSelect = false;


            bool bHavePreselectedObjects = false;

            for (; ;)
            {
                Rhino.Input.GetResult res = go.GetMultiple(1, 0);

                if (res == Rhino.Input.GetResult.Option)
                {
                    go.EnablePreSelect(false, true);
                    continue;
                }
                else if (res != Rhino.Input.GetResult.Object)
                {
                    return(null);//Rhino.Commands.Result.Cancel;
                }
                if (go.ObjectsWerePreselected)
                {
                    bHavePreselectedObjects = true;
                    go.EnablePreSelect(false, true);
                    continue;
                }

                break;
            }

            if (bHavePreselectedObjects)
            {
                // Normally when command finishes, pre-selected objects will remain
                // selected, when and post-selected objects will be unselected.
                // With this sample, it is possible to have a combination of
                // pre-selected and post-selected objects. To make sure everything
                // "looks the same", unselect everything before finishing the command.
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    Rhino.DocObjects.RhinoObject rhinoObject = go.Object(i).Object();

                    if (null != rhinoObject)
                    {
                        rhinoObject.Select(false);
                    }
                }
                //doc.Views.Redraw();
            }

            List <Guid> guids = new List <Guid>();

            for (int i = 0; i < go.ObjectCount; i++)
            {
                guids.Add(go.Object(i).ObjectId);
            }

            Tuple <Brep[], Dictionary <int, List <Guid> > > data = OpenNestLib.OpenNestUtil.SortGuidsByPlanarCurves(guids, this.cp);

            Rhino.RhinoApp.WriteLine("OpenNest: Select object count = {0}", go.ObjectCount);
            this.n = data.Item1.Length;
            Rhino.RhinoDoc.ActiveDoc.Views.Redraw();
            return(data);
        }
        protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
        {
            Mesh meshObj;
            Point3d pointObj = new Point3d(0.0,0.0,0.0);

            RhinoApp.WriteLine("dikka dikka dikka...");

            Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
            gp.SetCommandPrompt("Start of ray");
            gp.Get();
            if (gp.CommandResult() != Rhino.Commands.Result.Success)
                return gp.CommandResult();

            pointObj = gp.Point();
            doc.Objects.AddPoint(pointObj);

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select the mesh to print");
            go.Get();
            Result rc = go.CommandResult();

            if (rc != Rhino.Commands.Result.Success)
            {
                RhinoApp.WriteLine("sdfafadsfda");
                return rc;
            }

            RhinoApp.WriteLine("2 2 dikka dikka dikka...");

            meshObj = new Mesh();
            if (go.ObjectCount == 1)
            {
                ObjRef tmpRef = new ObjRef(go.Object(0).ObjectId);
                meshObj = tmpRef.Mesh();
                if (meshObj == null)
                {
                    return rc;
                }
            }

            Ray3d rayObj = new Ray3d(pointObj, new Vector3d(1.0, 1.0, 1.0));
            doc.Objects.AddPoint(rayObj.PointAt(1.0));
            doc.Objects.AddPoint(rayObj.PointAt(2.0));
            doc.Objects.AddPoint(rayObj.PointAt(3.0));

            double p  = Intersection.MeshRay(meshObj, rayObj);
            string a = string.Format("mesh ray gives {0:0.00}",p);
            doc.Objects.AddPoint(rayObj.PointAt(p));
            RhinoApp.WriteLine(a);
            return Rhino.Commands.Result.Success;
        }
Example #30
0
        public Rhino.Commands.Result AddPoints(Rhino.RhinoDoc doc)
        {
            // Input interval
            double _interval = 0.1;
            double _noise    = 1; // 1% noise

            var input = new Rhino.Input.Custom.GetNumber();

            input.SetCommandPrompt("Input interval(0.0 ~ 1.0)<0.1>");
            Rhino.Input.GetResult res = input.Get();
            if (res == Rhino.Input.GetResult.Number)
            {
                _interval = input.Number();
            }
            if (_interval == 0.0)
            {
                _interval = 0.1;
            }

            input.SetCommandPrompt("Noise factor(0.0 ~ 100.0)");
            res = input.Get();
            if (res == Rhino.Input.GetResult.Number)
            {
                _noise = input.Number();
            }

            // Select surface
            var go = new Rhino.Input.Custom.GetObject();

            go.SetCommandPrompt("Select surface");
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface;
            res = go.GetMultiple(1, 1024);
            if (res == Rhino.Input.GetResult.Nothing)
            {
                return(Rhino.Commands.Result.Failure);
            }

            Utility.SetOutputCount(10);
            for (int i = 0; i < go.ObjectCount; i++)
            {
                Rhino.Geometry.Surface surfaceA = go.Object(i).Surface();
                if (surfaceA == null)
                {
                    return(Rhino.Commands.Result.Failure);
                }

                Rhino.Geometry.Interval domU = surfaceA.Domain(0);
                Rhino.Geometry.Interval domV = surfaceA.Domain(1);

                double u, v;
                u = v = 0.0;
                for (u = domU.Min; u <= domU.Max; u += _interval)
                {
                    for (v = domV.Min; v <= domV.Max; v += _interval)
                    {
                        Rhino.Geometry.Point3d  pt  = surfaceA.PointAt(u, v);
                        Rhino.Geometry.Vector3d n   = surfaceA.NormalAt(u, v);
                        Rhino.Geometry.Point3d  pt2 = randomPoint(surfaceA, u, v, _interval, _noise);
                        doc.Objects.AddPoint(pt2);
                    }
                }
            }
            return(Rhino.Commands.Result.Success);
        }
 /// <summary>
 /// Select an object which will be used for the user text list
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void GetObjectForUserText(object sender, EventArgs e)
 {
   using (Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject())
   {
     go.SetCommandPrompt(Rhino.UI.Localization.LocalizeString("Select object", 361));
     go.AcceptNothing(true);
     go.DisablePreSelect();
     go.Get();
     if (go.CommandResult() == Rhino.Commands.Result.Success)
     {
       Rhino.DocObjects.ObjRef objref = go.Object(0);
       if (objref != null)
       {
         SelectedObjectId = objref.ObjectId;
         SetupSelectObjectPanelHelper(TextFieldType.usertext, false);
         objref.Dispose();
       }
     }
   }
 }
Example #32
0
        private void RunScript(object x, object y, ref object A)
        {
            try
            {
                if (sign)
                {
                    sign = false;
                    Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
                    go.Get();
                    Rhino.DocObjects.ObjRef or = go.Object(0);
                    ID = or.ObjectId;

                    Rhino.DocObjects.RhinoObject obj = RhinoDoc.ActiveDoc.Objects.Find(ID);
                    TextObject T = (TextObject)obj;
                    TextEntity t = T.TextGeometry;
                    m_tags = new Rhino.Display.Text3d(t.Text, t.Plane, t.TextHeight + 1);
                }
            }
            catch (Exception ex) { Print(ex.ToString()); }
        }
  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;
  }
Example #34
0
        public static GeometryLarge CreateGeometry(MaterialType mType, string mName)

        {
            RhinoDoc doc = RhinoDoc.ActiveDoc;

            //Allow user to pick multiple objects
            const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Curve;

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject()
            {
                GeometryFilter              = geometryFilter,
                GroupSelect                 = true,
                SubObjectSelect             = false,
                DeselectAllBeforePostSelect = false
            };
            go.SetCommandPrompt("Pick one or two closed curves.");
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);

            bool bHavePreselectedObjects = false;

            for (;;)
            {
                Rhino.Input.GetResult res = go.GetMultiple(1, 0);
                if (go.ObjectsWerePreselected)
                {
                    bHavePreselectedObjects = true;
                    go.EnablePreSelect(false, true);
                    continue;
                }
                break;
            }

            //Unselects the preselected objects
            if (bHavePreselectedObjects)
            {
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    RhinoObject rhinoObject = go.Object(i).Object();
                    if (null != rhinoObject)
                    {
                        rhinoObject.Select(false);
                    }
                }

                doc.Views.Redraw();
            }

            ObjRef[]     objs           = go.Objects();
            List <Curve> selectedCurves = new List <Curve>();

            foreach (ObjRef objRef in objs)
            {
                if (objRef.Curve() == null)
                {
                    RhinoApp.WriteLine("One of the selected objects was invalid.");
                    continue;
                }
                else if (!objRef.Curve().IsClosed)
                {
                    RhinoApp.WriteLine("One of the selected curves was not closed.");
                    continue;
                }
                selectedCurves.Add(objRef.Curve());
            }

            GeometryLarge larg;

            //if the curve is not closed do nothing
            switch (selectedCurves.Count)
            {
            case 0:
                Rhino.RhinoApp.WriteLine("No valid geometries was found.");
                return(null);

            case 1:
                larg = DrawAndSaveUserAttr(Brep.CreatePlanarBreps(selectedCurves)[0], doc, mType, mName);
                break;

            case 2:
                Brep brep1 = Brep.CreatePlanarBreps(new[] { selectedCurves[0] })[0];
                Brep brep2 = Brep.CreatePlanarBreps(new[] { selectedCurves[1] })[0];

                double area      = Brep.CreateBooleanUnion(new[] { brep1, brep2 }, 0.001)[0].GetArea();
                double brep1Area = brep1.GetArea();
                double brep2Area = brep2.GetArea();
                if (area > 0.999 * brep1Area && area < 1.001 * brep1Area)
                {
                    Brep brep = Brep.CreateBooleanDifference(brep1, brep2, doc.ModelAbsoluteTolerance)[0];
                    larg = DrawAndSaveUserAttr(brep, doc, mType, mName);
                    break;
                }

                else if (area > 0.999 * brep2Area && area < 1.001 * brep2Area)
                {
                    Brep brep = Brep.CreateBooleanDifference(brep1, brep2, doc.ModelAbsoluteTolerance)[0];
                    larg = DrawAndSaveUserAttr(brep, doc, mType, mName);
                    break;
                }
                else
                {
                    RhinoApp.WriteLine("The curves were not inside one another.");
                    return(null);
                }

            default:
                return(null);
            }

            foreach (ObjRef objRef in objs)
            {
                doc.Objects.Delete(objRef, false);
            }
            return(larg);
        }
Example #35
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Select objects to define block
            var go = new Rhino.Input.Custom.GetObject();

            go.SetCommandPrompt("Select objects to define block");
            go.ReferenceObjectSelect = false;
            go.SubObjectSelect       = false;
            go.GroupSelect           = true;

            // Phantoms, grips, lights, etc., cannot be in blocks.
            var forbidden_geometry_filter = Rhino.DocObjects.ObjectType.Light |
                                            Rhino.DocObjects.ObjectType.Grip | Rhino.DocObjects.ObjectType.Phantom;
            var geometry_filter = forbidden_geometry_filter ^ Rhino.DocObjects.ObjectType.AnyObject;

            go.GeometryFilter = geometry_filter;
            go.GetMultiple(1, 0);
            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }

            // Block base point
            Rhino.Geometry.Point3d base_point;
            var rc = Rhino.Input.RhinoGet.GetPoint("Block base point", false, out base_point);

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

            // Block definition name
            string idef_name = "";

            rc = Rhino.Input.RhinoGet.GetString("Block definition name", false, ref idef_name);
            if (rc != Rhino.Commands.Result.Success)
            {
                return(rc);
            }
            // Validate block name
            idef_name = idef_name.Trim();
            if (string.IsNullOrEmpty(idef_name))
            {
                return(Rhino.Commands.Result.Nothing);
            }

            // See if block name already exists
            Rhino.DocObjects.InstanceDefinition existing_idef = doc.InstanceDefinitions.Find(idef_name, true);
            if (existing_idef != null)
            {
                Rhino.RhinoApp.WriteLine("Block definition {0} already exists", idef_name);
                return(Rhino.Commands.Result.Nothing);
            }

            // Gather all of the selected objects
            var geometry   = new System.Collections.Generic.List <Rhino.Geometry.GeometryBase>();
            var attributes = new System.Collections.Generic.List <Rhino.DocObjects.ObjectAttributes>();

            for (int i = 0; i < go.ObjectCount; i++)
            {
                var rhinoObject = go.Object(i).Object();
                if (rhinoObject != null)
                {
                    geometry.Add(rhinoObject.Geometry);
                    attributes.Add(rhinoObject.Attributes);
                }
            }

            // Gather all of the selected objects
            int idef_index = doc.InstanceDefinitions.Add(idef_name, string.Empty, base_point, geometry, attributes);

            if (idef_index < 0)
            {
                Rhino.RhinoApp.WriteLine("Unable to create block definition", idef_name);
                return(Rhino.Commands.Result.Failure);
            }

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

        Rhino.DocObjects.ObjRef objref;
        Result rc = Rhino.Input.RhinoGet.GetOneObject("Select surface or brep to unroll", false, filter, out objref);

        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }
        Rhino.Geometry.Unroller unroll = null;
        Rhino.Geometry.Brep     brep   = objref.Brep();
        if (brep != null)
        {
            unroll = new Rhino.Geometry.Unroller(brep);
        }
        else
        {
            Rhino.Geometry.Surface srf = objref.Surface();
            if (srf != null)
            {
                unroll = new Rhino.Geometry.Unroller(srf);
            }
        }
        if (unroll == null)
        {
            return(Rhino.Commands.Result.Cancel);
        }

        unroll.AbsoluteTolerance = 0.01;
        unroll.RelativeTolerance = 0.01;

        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select points, curves, and dots to unroll with surface");
        go.GeometryFilter = Rhino.DocObjects.ObjectType.Point | Rhino.DocObjects.ObjectType.Curve | Rhino.DocObjects.ObjectType.TextDot;
        go.AcceptNothing(true);
        go.GetMultiple(0, 0);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }
        for (int i = 0; i < go.ObjectCount; i++)
        {
            objref = go.Object(i);
            Rhino.Geometry.GeometryBase g   = objref.Geometry();
            Rhino.Geometry.Point        pt  = g as Rhino.Geometry.Point;
            Rhino.Geometry.Curve        crv = g as Rhino.Geometry.Curve;
            Rhino.Geometry.TextDot      dot = g as Rhino.Geometry.TextDot;
            if (pt != null)
            {
                unroll.AddFollowingGeometry(pt.Location);
            }
            else if (crv != null)
            {
                unroll.AddFollowingGeometry(crv);
            }
            else if (dot != null)
            {
                unroll.AddFollowingGeometry(dot);
            }
        }

        unroll.ExplodeOutput = false;
        Rhino.Geometry.Curve[]   curves;
        Rhino.Geometry.Point3d[] points;
        Rhino.Geometry.TextDot[] dots;
        Rhino.Geometry.Brep[]    breps = unroll.PerformUnroll(out curves, out points, out dots);
        if (breps == null || breps.Length < 1)
        {
            return(Rhino.Commands.Result.Failure);
        }

        for (int i = 0; i < breps.Length; i++)
        {
            doc.Objects.AddBrep(breps[i]);
        }
        for (int i = 0; i < curves.Length; i++)
        {
            doc.Objects.AddCurve(curves[i]);
        }
        doc.Objects.AddPoints(points);
        for (int i = 0; i < dots.Length; i++)
        {
            doc.Objects.AddTextDot(dots[i]);
        }
        doc.Views.Redraw();
        return(Rhino.Commands.Result.Success);
    }
 /// <summary>
 /// Select object for which an area value can be calculated
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void GetObjectForArea(object sender, EventArgs e)
 {
   using (Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject())
   {
     go.SetCommandPrompt(Rhino.UI.Localization.LocalizeString("Select closed curve, hatch, surface, or mesh", 359));
     go.AcceptNothing(true);
     go.SubObjectSelect = false;
     go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve | Rhino.DocObjects.ObjectType.Hatch | Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.Brep | Rhino.DocObjects.ObjectType.Mesh;
     go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve;
     go.DisablePreSelect();
     go.Get();
     if (go.CommandResult() == Rhino.Commands.Result.Success)
     {
       Rhino.DocObjects.ObjRef objref = go.Object(0);
       if (objref != null)
       {
         SelectedObjectId = objref.ObjectId;
         objref.Dispose();
       }
     }
   }
 }
Example #38
0
 public static Commands.Result GetOneObject(string prompt, bool acceptNothing, Rhino.DocObjects.ObjectType filter, out Rhino.DocObjects.ObjRef rhObject)
 {
   rhObject = null;
   Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
   go.SetCommandPrompt(prompt);
   go.AcceptNothing(acceptNothing);
   go.GeometryFilter = filter;
   go.Get();
   Commands.Result rc = go.CommandResult();
   if (rc == Rhino.Commands.Result.Success && go.ObjectCount > 0)
   {
     rhObject = go.Object(0);
   }
   go.Dispose();
   return rc;
 }
Example #39
0
        protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
        {
            nishanchiPlugin pluginObj = ((nishanchiPlugin)this.PlugIn);

            Boolean selectedObjectIsBrep = false;
            Boolean selectedObjectIsCurve = false;

            if (!pluginObj.trackerConnected)
            {
                RhinoApp.WriteLine("Tracker disconnected");
                return Rhino.Commands.Result.Failure;
            }
            connectKbEvt();

            //Ask the user to select Breps to print.
            //Result rc = Rhino.Input.RhinoGet.GetMultipleObjects("Select the surfaces to print",
            //false, Rhino.DocObjects.ObjectType.Surface, out objrefs);

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();

            go.SetCommandPrompt("Select the entity to print");
            go.GroupSelect = true;

            //Set this to go.GetMultiple(0,0) if you want to allow multiple entities to be selected
            go.GetMultiple(0, 1);

            Result rc = go.CommandResult();

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

            List<Rhino.Geometry.Brep> breps = new List<Rhino.Geometry.Brep>();
            List<Rhino.Geometry.Curve> curves = new List<Rhino.Geometry.Curve>();

            for (int i = 0; i < go.ObjectCount; i++)
            {
                ObjRef tmpRef = new ObjRef(go.Object(i).ObjectId);
                Rhino.Geometry.Brep brep = tmpRef.Brep();
                if (brep != null)
                {
                    breps.Add(brep);
                    selectedObjectIsBrep = true;
                }

                Rhino.Geometry.Curve curve = tmpRef.Curve();
                if (curve != null)
                {
                    curves.Add(curve);
                    selectedObjectIsCurve = true;
                }

            }
            if (selectedObjectIsBrep)
                RhinoApp.WriteLine("Selected " + breps.Count + " surfaces! Good! No, not, really, I'm just a program, I couldn't care less.");

            if (selectedObjectIsCurve)
                RhinoApp.WriteLine("Selected " + curves.Count + " curves! Good! No, not, really, I'm just a program, I couldn't care less.");

            createEntities(doc);

            fastrak trackerObj = pluginObj.trackerObj;
            int numPoints = 0;
            int numIntersections = 0;
            Boolean retval;

            RhinoApp.WriteLine(string.Format("Starting continuous mode on the tracker."));
            pluginObj.trackerObj.setContinuous();
            RhinoApp.WriteLine(string.Format("Printing mode enabled now."));

            Curve[] intersectionCurves;
            Point3d[] intersectionPoints;

            running = true;
            while (running)
            {
                retval = trackerObj.readFrame();
                if (retval)
                {
                    //q0,q1,q2,q3 Quaternion begin
                    //Compute the rotation matrix
                    rxTxTx = new Point3d(trackerObj.x, trackerObj.y, trackerObj.z);
                    orientationQuat = new Quaternion(trackerObj.q0, trackerObj.q1, trackerObj.q2, trackerObj.q3);
                    orientationQuat.GetRotation(out angle, out axis);
                    rotMat = Transform.Rotation(angle, axis, origin);

                    // Compute the new positions for the nozzlePoints and also compute the new lines
                    for (int i = 0; i < numNozzles; i++)
                    {
                        nozzleStartPointRxTx[i] = rotMat * nozzleStartPointRxRx[i];
                        nozzleStartPointTxTx[i] = nozzleStartPointRxTx[i] + rxTxTx;

                        nozzleEndPointRxTx[i] = rotMat * nozzleEndPointRxRx[i];
                        nozzleEndPointTxTx[i] = nozzleEndPointRxTx[i] + rxTxTx;

                        nozzleLinesTx[i] = new Line(nozzleStartPointTxTx[i], nozzleEndPointTxTx[i]);
                        nozzleCurves[i] = new LineCurve(nozzleLinesTx[i]);
                    }

                    numIntersections = 0;
                    if (selectedObjectIsBrep)
                    {
                        for (int i = 0; i < numNozzles; i++)
                        {
                            foreach (Brep b in breps)
                            {
                                try
                                {
                                    Intersection.CurveBrep(nozzleCurves[i], b, nozzleTolerance, out intersectionCurves, out intersectionPoints);
                                    if (intersectionPoints.Length > 0)
                                    {
                                        intersectionsBits[i] = 1;
                                        numIntersections++;
                                    }
                                    else
                                    {
                                        intersectionsBits[i] = 0;
                                    }
                                }
                                catch (Exception e)
                                {
                                    RhinoApp.WriteLine(e.Message);
                                }
                            }
                        }
                    }

                    if (selectedObjectIsCurve)
                    {
                        for (int i = 0; i < numNozzles; i++)
                        {
                            foreach (Curve c in curves)
                            {
                                try
                                {
                                    var events = Intersection.CurveCurve(nozzleCurves[i], c, nozzleTolerance, nozzleTolerance);
                                    if (events != null)
                                    {
                                        if (events.Count >= 1)
                                        {
                                            intersectionsBits[i] = 1;
                                            numIntersections++;
                                        }
                                        else
                                        {
                                            intersectionsBits[i] = 0;
                                        }
                                    }
                                }
                                catch (Exception e)
                                {
                                    RhinoApp.WriteLine(e.Message);
                                }
                            }
                        }
                    }

                    if (pluginObj.printHeadConnected)
                    {
                        // I print
                        if (((numPoints % 5) == 0)&&(numIntersections > 0))
                        {
                            string p = printCommand();
                            //RhinoApp.WriteLine(p);
                            pluginObj.printHeadObj.printFrame(p);
                            //pluginObj.printHeadObj.printFullLine();
                        }
                    }

                    numPoints++;
                }

                //And, I move the printer like thing on the screen
                if ((numPoints % 10) == 0)
                {
                    for (int i = 0; i < numNozzles; i++)
                    {
                        doc.Objects.Delete(lineGuids[i],false);
                        lineGuids[i] = doc.Objects.AddLine(nozzleLinesTx[i]);
                    }
                    doc.Objects.Delete(ballGuid, false);
                    ball = new Sphere(rxTxTx, ballRadius);
                    ballGuid = doc.Objects.AddSphere(ball);

                    doc.Views.ActiveView.Redraw();
                    RhinoApp.Wait();
                }
            }

            running = false;
            removeEntities(doc);

            RhinoApp.WriteLine(string.Format("Stopping continuous mode on the tracker."));
            pluginObj.trackerObj.stopContinuous();
            disconnectKbEvt();
            RhinoApp.WriteLine(string.Format("I guess you don't wanna print anymore, well who cares! Not me!"));
            return Rhino.Commands.Result.Success;
        }
Example #40
0
        protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
        {
            pluginObj = ((nishanchiPlugin)this.PlugIn);
            RhinoView viewObj = doc.Views.ActiveView;
            RhinoViewport viewPortObj = viewObj.ActiveViewport;
            Vector3d originalCameraVector = viewPortObj.CameraDirection;
            Point3d originalCameraLocation = viewPortObj.CameraLocation;
            Mesh meshObj;

            Boolean logging = false;
            StreamWriter logWriter = null;

            String reportString;
            String logString;
            String printCommandStr;

            if (((nishanchiPlugin)this.PlugIn).logEnabled())
            {
                logWriter = new StreamWriter(((nishanchiPlugin)this.PlugIn).getNewLogFile());
                logWriter.WriteLine("Printing...");
                logging = true;
            }

            if (!pluginObj.trackerConnected)
            {
                RhinoApp.WriteLine("Tracker disconnected");
                return Rhino.Commands.Result.Failure;
            }

            connectKbEvt();

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select the mesh to print");
            go.Get();
            Result rc = go.CommandResult();

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

            meshObj = new Mesh();
            if (go.ObjectCount == 1){
                ObjRef tmpRef = new ObjRef(go.Object(0).ObjectId);
                meshObj = tmpRef.Mesh();
                if (meshObj == null){
                    disconnectKbEvt();
                    return rc;
                }
            }

            createNozzles(doc);
            cameraPoint = new tPoint(Nozzle.XOffset + 100.0, Nozzle.YOffset, Nozzle.ZOffset + (Nozzle.ZMultiplier * ((numNozzles-1)/2)));

            fastrak trackerObj = pluginObj.trackerObj;
            int numPoints = 0;

            Boolean retval;

            RhinoApp.WriteLine(string.Format("Starting continuous mode on the tracker."));
            pluginObj.trackerObj.setContinuous();
            RhinoApp.WriteLine(string.Format("Printing mode enabled now."));

            running = true;
            while (running)
            {
                retval = trackerObj.readFrame();
                if (retval)
                {
                    //q0,q1,q2,q3 Quaternion begin
                    //Compute the rotation matrix
                    reportString = String.Format("{0},{1},{2}", trackerObj.x, trackerObj.y, trackerObj.z);
                    logString = String.Format("p,{0},{1},{2},{3},{4},{5},{6},{7}", numPoints, trackerObj.x, trackerObj.y, trackerObj.z, trackerObj.q0, trackerObj.q1, trackerObj.q2, trackerObj.q3);

                    RhinoApp.WriteLine(reportString);
                    if (logging)
                    {
                        logWriter.WriteLine(logString);
                    }

                    rxTxTx = new Point3d(trackerObj.x, trackerObj.y, trackerObj.z);
                    orientationQuat = new Quaternion(trackerObj.q0, trackerObj.q1, trackerObj.q2, trackerObj.q3);
                    orientationQuat.GetRotation(out angle, out axis);
                    rotMat = Transform.Rotation(angle, axis, origin);

                    // Compute the new positions for the nozzlePoints and also compute the new lines
                    for (int i = 0; i < numNozzles; i++)
                    {
                        nozzles[i].computeTxTx(rotMat, rxTxTx);
                    }

                    //And, I move the view around
                    if ((numPoints % 100) == 0)
                    {
                        cameraPoint.computeTxTx(rotMat, rxTxTx);
                        viewPortObj.SetCameraLocation(cameraPoint.txTx(), true);
                        viewPortObj.SetCameraDirection(nozzles[4].vector(), true);
                        viewPortObj.Rotate(Math.PI / 2, nozzles[4].vector(), cameraPoint.txTx());
                        cameraUpTx = rotMat * cameraUpRx;
                        viewPortObj.CameraUp = cameraUpTx;

                        removeNozzleLinesFromDocument(doc);
                        addNozzleLinesToDocument(doc);
                        doc.Views.ActiveView.Redraw();
                        RhinoApp.Wait();
                    }

                    //Compute ray intersections
                    if ((numPoints % 4) == 0)
                    {
                        //RhinoApp.WriteLine("Calculating intersections..");
                        for (int i = 0; i < numNozzles; i++)
                        {
                            nozzles[i].rayIntersectionDistance = Intersection.MeshRay(meshObj,nozzles[i].ray());
                        }

                        printCommandStr = printCommand();
                        //RhinoApp.WriteLine(printCommandStr);

                        if (logging)
                        {
                            logString = String.Format("c,{0},{1}", numPoints, printCommandStr);
                            logWriter.WriteLine(logString);
                        }
                    }
                    numPoints++;
                }
            }

            running = false;

            //clean up
            removeNozzleLinesFromDocument(doc);
            doc.Views.ActiveView.Redraw();
            RhinoApp.WriteLine("Removing printHead objects!!");

            if (logging)
            {
                logWriter.Close();
                ((nishanchiPlugin)this.PlugIn).closeLogFile();
            }

            //stop the tracker
            RhinoApp.WriteLine(string.Format("Stopping continuous mode on the tracker."));
            pluginObj.trackerObj.stopContinuous();
            disconnectKbEvt();
            RhinoApp.WriteLine(string.Format("I guess you don't wanna print anymore, well who cares! Not me!"));

            //setup the viewport as it was
            viewPortObj.SetCameraLocation(originalCameraLocation, true);
            viewPortObj.SetCameraDirection(originalCameraVector, true);

            return Rhino.Commands.Result.Success;
        }
Example #41
0
        public Rhino.Commands.Result IntersectBrep(Rhino.RhinoDoc doc)
        {
            // Input interval
            var input = new Rhino.Input.Custom.GetNumber();

            input.SetCommandPrompt("Input slicing interval");
            input.Get();
            if (input.CommandResult() != Rhino.Commands.Result.Success)
            {
                RhinoApp.WriteLine("Can't obtain interval number");
                return(input.CommandResult());
            }
            double SlicingInterval = input.Number();

            // Select two curves to intersect
            var go = new Rhino.Input.Custom.GetObject();

            go.SetCommandPrompt("Select Brep");
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Brep;
            go.GetMultiple(1, 1);

            Rhino.Geometry.Brep    brepA    = null;
            Rhino.Geometry.Surface surfaceB = null;
            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                RhinoApp.WriteLine("Can't obtain objects");
                return(input.CommandResult());
            }
            brepA = go.Object(0).Brep();

            var go2 = new Rhino.Input.Custom.GetObject();

            go2.SetCommandPrompt("Select surface");
            go2.GeometryFilter = Rhino.DocObjects.ObjectType.Surface;
            go2.GetMultiple(1, 1);
            if (go2.CommandResult() != Rhino.Commands.Result.Success)
            {
                RhinoApp.WriteLine("Can't obtain objects");
                return(input.CommandResult());
            }
            surfaceB = go2.Object(0).Surface();

            // Calculate the intersection
            RhinoApp.WriteLine("Executing the intersection between surfaces");
            const double intersection_tolerance = 0.001;

            Rhino.Geometry.Curve[]   intersectionCurves = null;
            Rhino.Geometry.Point3d[] intersectionPoints = null;
            bool ret = Rhino.Geometry.Intersect.Intersection.BrepSurface(brepA, surfaceB, intersection_tolerance, out intersectionCurves, out intersectionPoints);

            if (ret)
            {
                List <PlanePoint> PlanePoints = new List <PlanePoint>();
                RhinoApp.WriteLine("Success - {0} curves", intersectionCurves.Length);
                for (int i = 0; i < intersectionCurves.Length; i++)
                {
                    Rhino.Geometry.Curve curve = intersectionCurves[i];
                    doc.Objects.AddCurve(curve);
                    RhinoApp.WriteLine("Curve is added");

                    Utility.CreateSections(doc, brepA, surfaceB, curve, SlicingInterval, ref PlanePoints);
                }

                RhinoApp.WriteLine("Success - {0} points", intersectionPoints.Length);
                for (int i = 0; i < intersectionPoints.Length; i++)
                {
                    Rhino.Geometry.Point3d point = intersectionPoints[i];
                    doc.Objects.AddPoint(point);
                    RhinoApp.WriteLine("Point is added");
                }

                if (Utility.SavePlanePoints(@"c:\SlicerPlanePoints.csv", PlanePoints))
                {
                    RhinoApp.WriteLine("Saved SlicerPlanePoints.csv");
                }
            }

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