コード例 #1
0
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      // this creates a point where the mouse is clicked.
      var gp = new GetPoint();
      gp.SetCommandPrompt("Click for new point");
      gp.Get();
      if (gp.CommandResult() != Result.Success)
        return gp.CommandResult();
      var point3d = gp.Point();
      doc.Objects.AddPoint(point3d);
      doc.Views.Redraw();

      // selects a point that already exists
      ObjRef obj_ref;
      var rc = RhinoGet.GetOneObject("Select point", false, ObjectType.Point, out obj_ref);
      if (rc != Result.Success)
        return rc;
      var point = obj_ref.Point();
      RhinoApp.WriteLine("Point: x:{0}, y:{1}, z:{2}", 
        point.Location.X,
        point.Location.Y,
        point.Location.Z);
      doc.Objects.UnselectAll();

      // selects multiple points that already exist
      ObjRef[] obj_refs;
      rc = RhinoGet.GetMultipleObjects("Select point", false, ObjectType.Point, out obj_refs);
      if (rc != Result.Success)
        return rc;
      foreach (var o_ref in obj_refs)
      {
        point = o_ref.Point();
        RhinoApp.WriteLine("Point: x:{0}, y:{1}, z:{2}",
          point.Location.X,
          point.Location.Y,
          point.Location.Z);
      }
      doc.Objects.UnselectAll();

      // also selects a point that already exists.
      // Used when RhinoGet doesn't provide enough control
      var go = new GetObject();
      go.SetCommandPrompt("Select point");
      go.GeometryFilter = ObjectType.Point;
      go.GetMultiple(1, 0);
      if (go.CommandResult() != Result.Success)
        return go.CommandResult();
      foreach (var o_ref in  go.Objects()) 
      {
        point = o_ref.Point();
        if (point != null)
          RhinoApp.WriteLine("Point: x:{0}, y:{1}, z:{2}", 
            point.Location.X,
            point.Location.Y,
            point.Location.Z);
      }

      doc.Views.Redraw();
      return Result.Success;
    }
コード例 #2
0
    public static Result CopyGroups(RhinoDoc doc)
    {
        var go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select objects to copy in place");
        go.GroupSelect = true;
        go.SubObjectSelect = false;
        go.GetMultiple(1, 0);
        if (go.CommandResult() != Result.Success)
          return go.CommandResult();

        var xform = Transform.Identity;
        var group_map = new Dictionary<int, int>();

        foreach (var obj_ref in go.Objects())
        {
          if (obj_ref != null)
          {
        var obj = obj_ref.Object();
        var duplicate = doc.Objects.Transform(obj_ref.ObjectId, xform, false);
        RhinoUpdateObjectGroups(ref obj, ref group_map);
          }
        }
        doc.Views.Redraw();
        return Result.Success;
    }
コード例 #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);
    }
コード例 #4
0
ファイル: GH_Getter2.cs プロジェクト: panhao4812/GHComponent1
        public static GH_LinearDimension GetLinearDimension2()
        {
            GetObject obj2;
            Label_0000:
            obj2 = new GetObject();
            if (m_reference)
            {
                obj2.SetCommandPrompt("LinearDimension  reference");
                obj2.AddOption("Mode", "Reference");
            }
            else
            {
                obj2.SetCommandPrompt("LinearDimension to copy");
                obj2.AddOption("Mode", "Copy");
            }
            obj2.GeometryFilter = ObjectType.Annotation;
            GetResult result = obj2.Get();
            if (result == GetResult.Option)
            {
                m_reference = !m_reference;
                goto Label_0000;
            }
            if (result != GetResult.Object)
            {
                return null;
            }
            if (!m_reference)
            {
                return new GH_LinearDimension((LinearDimension)obj2.Object(0).Geometry());
            }

            GH_LinearDimension dm =new GH_LinearDimension(obj2.Object(0).ObjectId);
            if ((dm != null) && (!dm.IsGeometryLoaded)) { dm.LoadGeometry(); }
            return dm;
        }
コード例 #5
0
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      var gm = new GetObject();
      gm.SetCommandPrompt("Select solid meshes for volume calculation");
      gm.GeometryFilter = ObjectType.Mesh;
      gm.GeometryAttributeFilter = GeometryAttributeFilter.ClosedMesh;
      gm.SubObjectSelect = false;
      gm.GroupSelect = true;
      gm.GetMultiple(1, 0);
      if (gm.CommandResult() != Result.Success)
        return gm.CommandResult();

      double volume = 0.0;
      double volume_error = 0.0;
      foreach (var obj_ref in gm.Objects())
      {
        if (obj_ref.Mesh() != null)
        {
          var mass_properties = VolumeMassProperties.Compute(obj_ref.Mesh());
          if (mass_properties != null)
          {
            volume += mass_properties.Volume;
            volume_error += mass_properties.VolumeError;
          }
        }
      }

      RhinoApp.WriteLine("Total volume = {0:f} (+/- {1:f})", volume, volume_error);
      return Result.Success;
    }
コード例 #6
0
  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;
  }
コード例 #7
0
  public static Rhino.Commands.Result CircleCenter(Rhino.RhinoDoc doc)
  {
    Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
    go.SetCommandPrompt("Select objects");
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
    go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve;
    go.GetMultiple(1, 0);
    if( go.CommandResult() != Rhino.Commands.Result.Success )
      return go.CommandResult();

    Rhino.DocObjects.ObjRef[] objrefs = go.Objects();
    if( objrefs==null )
      return Rhino.Commands.Result.Nothing;

    double tolerance = doc.ModelAbsoluteTolerance;
    for( int i=0; i<objrefs.Length; i++ )
    {
      // get the curve geometry
      Rhino.Geometry.Curve curve = objrefs[i].Curve();
      if( curve==null )
        continue;
      Rhino.Geometry.Circle circle;
      if( curve.TryGetCircle(out circle, tolerance) )
      {
        Rhino.RhinoApp.WriteLine("Circle{0}: center = {1}", i+1, circle.Center);
      }
    }
    return Rhino.Commands.Result.Success;
  }
コード例 #8
0
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      var gs = new GetObject();
      gs.SetCommandPrompt("select sphere");
      gs.GeometryFilter = ObjectType.Surface;
      gs.DisablePreSelect();
      gs.SubObjectSelect = false;
      gs.Get();
      if (gs.CommandResult() != Result.Success)
        return gs.CommandResult();

      Sphere sphere;
      gs.Object(0).Surface().TryGetSphere(out sphere);
      if (sphere.IsValid)
      {
        var mesh = Mesh.CreateFromSphere(sphere, 10, 10);
        if (mesh == null)
          return Result.Failure;

        var conduit = new DrawBlueMeshConduit(mesh) {Enabled = true};
        doc.Views.Redraw();

        var in_str = "";
        Rhino.Input.RhinoGet.GetString("press <Enter> to continue", true, ref in_str);

        conduit.Enabled = false;
        doc.Views.Redraw();
        return Result.Success;
      }
      else
        return Result.Failure;
    }
コード例 #9
0
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      var gs = new GetObject();
      gs.SetCommandPrompt("select surface");
      gs.GeometryFilter = ObjectType.Surface | ObjectType.PolysrfFilter;
      gs.DisablePreSelect();
      gs.SubObjectSelect = false;
      gs.Get();
      if (gs.CommandResult() != Result.Success)
        return gs.CommandResult();
      var brep = gs.Object(0).Brep();
      if (brep == null)
        return Result.Failure;

      var points = Intersection.ProjectPointsToBreps(
                   new List<Brep> {brep}, // brep on which to project
                   new List<Point3d> {new Point3d(0, 0, 0), new Point3d(3,0,3), new Point3d(-2,0,-2)}, // some random points to project
                   new Vector3d(0, 1, 0), // project on Y axis
                   doc.ModelAbsoluteTolerance);

      if (points != null && points.Length > 0)
      {
        foreach (var point in points)
        {
          doc.Objects.AddPoint(point);
        }
      }
      doc.Views.Redraw();
      return Result.Success;
    }
コード例 #10
0
        protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode)
        {
            Rhino.Input.Custom.GetObject getobjects = new Rhino.Input.Custom.GetObject();
            getobjects.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
            getobjects.AcceptNothing(false);

            switch (getobjects.GetMultiple(1, 0))
            {
            case GetResult.ExitRhino:
                return(Result.ExitRhino);

            case GetResult.Cancel:
                return(Result.Cancel);

            case GetResult.Object:
                if (getobjects.ObjectCount > 1)
                {
                    Rhino.DocObjects.ObjRef[] arrCurve = getobjects.Objects();
                    Array.Sort(arrCurve, (x, y) => x.Curve().GetLength().CompareTo(y.Curve().GetLength()));
                    doc.Objects.Delete(arrCurve[0], true);
                }
                return(Result.Success);

            default:
                return(Result.Failure);
            }
        }
コード例 #11
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);
    }
コード例 #12
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;
    }
コード例 #13
0
    public static Result PrePostPick(RhinoDoc doc)
    {
        var go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select objects");
        go.EnablePreSelect(true, true);
        go.EnablePostSelect(true);
        go.GetMultiple(0, 0);
        if (go.CommandResult() != Result.Success)
          return go.CommandResult();

        var selected_objects = go.Objects().ToList();

        if (go.ObjectsWerePreselected)
        {
          go.EnablePreSelect(false, true);
          go.DeselectAllBeforePostSelect = false;
          go.EnableUnselectObjectsOnExit(false);
          go.GetMultiple(0, 0);
          if (go.CommandResult() == Result.Success)
          {
        foreach (var obj in go.Objects())
        {
          selected_objects.Add(obj);
          // The normal behavior of commands is that when they finish,
          // objects that were pre-selected remain selected and objects
          // that were post-selected will not be selected. Because we
          // potentially could have both, we'll try to do something
          // consistent and make sure post-selected objects also stay selected
          obj.Object().Select(true);
        }
          }
        }
        return selected_objects.Count > 0 ? Result.Success : Result.Nothing;
    }
コード例 #14
0
    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);
    }
コード例 #15
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);
    }
コード例 #16
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var layerCheck = doc.Layers.FindName("Numbers");

            if (layerCheck == null)
            {
                doc.Layers.Add("Numbers", System.Drawing.Color.DarkRed);
                layerCheck = doc.Layers.FindName("Numbers");
            }

            //pick objects to add center point
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select objects to number");
            var heightref = new Rhino.Input.Custom.OptionDouble(height);

            go.AddOptionDouble("Text_height_mm", ref heightref);
            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.GetMultiple(1, 0);

            //Compute center and add point to doc

            for (int i = 0; i < go.ObjectCount; i++)
            {
                height = heightref.CurrentValue;
                Rhino.DocObjects.ObjRef objref = go.Object(i);
                Guid        objGuid            = objref.ObjectId;
                BoundingBox bbObj       = go.Object(i).Geometry().GetBoundingBox(true);
                Point3d     bbObjCenter = bbObj.Center;

                int a = i + 1;

                Plane plane = Plane.WorldXY;
                plane.Origin = bbObjCenter;
                var    Justification = TextJustification.MiddleCenter;
                string text          = a.ToString();
                var    Font          = "Arial";

                Guid num = doc.Objects.AddText(text, plane, height, Font, false, false, Justification);

                Rhino.DocObjects.RhinoObject circObj = doc.Objects.Find(num);
                circObj.Attributes.LayerIndex = layerCheck.Index;
                circObj.CommitChanges();

                int groupIndex = doc.Groups.Count;
                groupIndex++;
                string group = groupIndex.ToString();
                var    gI    = doc.Groups.Add(group);
                doc.Groups.AddToGroup(gI, num);
                doc.Groups.AddToGroup(gI, objGuid);
            }
            doc.Views.Redraw();
            return(Result.Success);
        }
コード例 #17
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var layerCheck = doc.Layers.FindName("CenterPoints");

            if (layerCheck == null)
            {
                doc.Layers.Add("CenterPoints", System.Drawing.Color.Blue);
                layerCheck = doc.Layers.FindName("CenterPoints");
            }

            //pick objects to add center point
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select objects to add center point");
            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.GetMultiple(1, 0);

            //Compute center and add point to doc

            for (int i = 0; i < go.ObjectCount; i++)
            {
                Guid pointG;
                Rhino.DocObjects.ObjRef      objref = go.Object(i);
                Rhino.DocObjects.RhinoObject obj    = objref.Object();
                var objType = obj.ObjectType;
                if (objType == Rhino.DocObjects.ObjectType.Curve)
                {
                    Curve  curve  = objref.Curve();
                    Circle circle = new Circle();
                    if (!curve.TryGetCircle(out circle, doc.ModelAbsoluteTolerance))
                    {
                        BoundingBox bbObj       = go.Object(i).Geometry().GetBoundingBox(true);
                        Point3d     bbObjCenter = bbObj.Center;
                        pointG = doc.Objects.AddPoint(bbObjCenter);
                    }
                    else
                    {
                        Point3d circleCenter = circle.Center;
                        pointG = doc.Objects.AddPoint(circleCenter);
                    }
                }
                else
                {
                    BoundingBox bbObj       = go.Object(i).Geometry().GetBoundingBox(true);
                    Point3d     bbObjCenter = bbObj.Center;
                    pointG = doc.Objects.AddPoint(bbObjCenter);
                }
                Rhino.DocObjects.RhinoObject circObj = doc.Objects.Find(pointG);
                circObj.Attributes.LayerIndex = layerCheck.Index;
                circObj.CommitChanges();
            }
            doc.Views.Redraw();
            return(Result.Success);
        }
コード例 #18
0
    public static Rhino.Commands.Result IntersectLines(Rhino.RhinoDoc doc)
    {
        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select lines");
        go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
        go.GetMultiple(2, 2);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }
        if (go.ObjectCount != 2)
        {
            return(Rhino.Commands.Result.Failure);
        }

        LineCurve crv0 = go.Object(0).Geometry() as LineCurve;
        LineCurve crv1 = go.Object(1).Geometry() as LineCurve;

        if (crv0 == null || crv1 == null)
        {
            return(Rhino.Commands.Result.Failure);
        }

        Line     line0 = crv0.Line;
        Line     line1 = crv1.Line;
        Vector3d v0    = line0.Direction;

        v0.Unitize();
        Vector3d v1 = line1.Direction;

        v1.Unitize();

        if (v0.IsParallelTo(v1) != 0)
        {
            Rhino.RhinoApp.WriteLine("Selected lines are parallel.");
            return(Rhino.Commands.Result.Nothing);
        }

        double a, b;

        if (!Rhino.Geometry.Intersect.Intersection.LineLine(line0, line1, out a, out b))
        {
            Rhino.RhinoApp.WriteLine("No intersection found.");
            return(Rhino.Commands.Result.Nothing);
        }

        Point3d pt0 = line0.PointAt(a);
        Point3d pt1 = line1.PointAt(b);

        // pt0 and pt1 should be equal, so we will only add pt0 to the document
        doc.Objects.AddPoint(pt0);
        doc.Views.Redraw();
        return(Rhino.Commands.Result.Success);
    }
コード例 #19
0
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      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;
    }
コード例 #20
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);
    }
コード例 #21
0
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      m_tolerance = doc.ModelAbsoluteTolerance;
      
      // only use a custom geometry filter if no simpler filter does the job

      // only curves
      var gc = new GetObject();
      gc.SetCommandPrompt("select curve");
      gc.GeometryFilter = ObjectType.Curve;
      gc.DisablePreSelect();
      gc.SubObjectSelect = false;
      gc.Get();
      if (gc.CommandResult() != Result.Success)
        return gc.CommandResult();
      if (null == gc.Object(0).Curve())
        return Result.Failure;
      Rhino.RhinoApp.WriteLine("curve was selected");

      // only closed curves
      var gcc = new GetObject();
      gcc.SetCommandPrompt("select closed curve");
      gcc.GeometryFilter = ObjectType.Curve;
      gcc.GeometryAttributeFilter = GeometryAttributeFilter.ClosedCurve;
      gcc.DisablePreSelect();
      gcc.SubObjectSelect = false;
      gcc.Get();
      if (gcc.CommandResult() != Result.Success)
        return gcc.CommandResult();
      if (null == gcc.Object(0).Curve())
        return Result.Failure;
      Rhino.RhinoApp.WriteLine("closed curve was selected");

      // only circles with a radius of 10
      var gcc10 = new GetObject();
      gcc10.SetCommandPrompt("select circle with radius of 10");
      gc.GeometryFilter = ObjectType.Curve;
      gcc10.SetCustomGeometryFilter(CircleWithRadiusOf10GeometryFilter); // custom geometry filter
      gcc10.DisablePreSelect();
      gcc10.SubObjectSelect = false;
      gcc10.Get();
      if (gcc10.CommandResult() != Result.Success)
        return gcc10.CommandResult();
      if (null == gcc10.Object(0).Curve())
        return Result.Failure;
      RhinoApp.WriteLine("circle with radius of 10 was selected");

      return Result.Success;
    }
コード例 #22
0
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      var gs = new GetObject();
      gs.SetCommandPrompt("select brep");
      gs.GeometryFilter = ObjectType.Brep;
      gs.DisablePreSelect();
      gs.SubObjectSelect = false;
      gs.Get();
      if (gs.CommandResult() != Result.Success)
        return gs.CommandResult();
      var brep = gs.Object(0).Brep();

      var gc = new GetObject();
      gc.SetCommandPrompt("select curve");
      gc.GeometryFilter = ObjectType.Curve;
      gc.DisablePreSelect();
      gc.SubObjectSelect = false;
      gc.Get();
      if (gc.CommandResult() != Result.Success)
        return gc.CommandResult();
      var curve = gc.Object(0).Curve();

      if (brep == null || curve == null)
        return Result.Failure;

      var tolerance = doc.ModelAbsoluteTolerance;

      Point3d[] intersection_points;
      Curve[] overlap_curves;
      if (!Intersection.CurveBrep(curve, brep, tolerance, out overlap_curves, out intersection_points))
      {
        RhinoApp.WriteLine("curve brep intersection failed");
        return Result.Nothing;
      }

      foreach (var overlap_curve in overlap_curves)
        doc.Objects.AddCurve(overlap_curve);
      foreach (var intersection_point in intersection_points)
        doc.Objects.AddPoint(intersection_point);

      RhinoApp.WriteLine("{0} overlap curves, and {1} intersection points", overlap_curves.Length, intersection_points.Length);
      doc.Views.Redraw();

      return Result.Success;
    }
コード例 #23
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;
    }
コード例 #24
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);
    }
コード例 #25
0
  public static Rhino.Commands.Result IntersectLines(Rhino.RhinoDoc doc)
  {
    Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
    go.SetCommandPrompt( "Select lines" );
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
    go.GetMultiple( 2, 2);
    if( go.CommandResult() != Rhino.Commands.Result.Success )
      return go.CommandResult();
    if( go.ObjectCount != 2 )
      return Rhino.Commands.Result.Failure;

    LineCurve crv0 = go.Object(0).Geometry() as LineCurve;
    LineCurve crv1 = go.Object(1).Geometry() as LineCurve;
    if( crv0==null || crv1==null )
      return Rhino.Commands.Result.Failure;

    Line line0 = crv0.Line;
    Line line1 = crv1.Line;
    Vector3d v0 = line0.Direction;
    v0.Unitize();
    Vector3d v1 = line1.Direction;
    v1.Unitize();

    if( v0.IsParallelTo(v1) != 0 )
    {
      Rhino.RhinoApp.WriteLine("Selected lines are parallel.");
      return Rhino.Commands.Result.Nothing;
    }

    double a, b;
    if( !Rhino.Geometry.Intersect.Intersection.LineLine(line0, line1, out a, out b))
    {
      Rhino.RhinoApp.WriteLine("No intersection found.");
      return Rhino.Commands.Result.Nothing;
    }

    Point3d pt0 = line0.PointAt(a);
    Point3d pt1 = line1.PointAt(b);
    // pt0 and pt1 should be equal, so we will only add pt0 to the document
    doc.Objects.AddPoint( pt0 );
    doc.Views.Redraw();
    return Rhino.Commands.Result.Success;
  }
コード例 #26
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;
    }
コード例 #27
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;
    }
コード例 #28
0
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      ObjRef[] boundary_obj_refs;
      var rc = RhinoGet.GetMultipleObjects("Select boundary objects", false, ObjectType.AnyObject, out boundary_obj_refs);
      if (rc != Result.Success)
        return rc;
      if (boundary_obj_refs == null || boundary_obj_refs.Length == 0)
        return Result.Nothing;

      var gc = new GetObject();
      gc.SetCommandPrompt("Select curve to extend");
      gc.GeometryFilter = ObjectType.Curve;
      gc.GeometryAttributeFilter = GeometryAttributeFilter.OpenCurve;
      gc.Get();
      if (gc.CommandResult() != Result.Success)
        return gc.CommandResult();
      var curve_obj_ref = gc.Object(0);

      var curve = curve_obj_ref.Curve();
      if (curve == null) return Result.Failure;
      double t;
      if (!curve.ClosestPoint(curve_obj_ref.SelectionPoint(), out t))
        return Result.Failure;
      var curve_end = t <= curve.Domain.Mid ? CurveEnd.Start : CurveEnd.End;

      var geometry = boundary_obj_refs.Select(obj=> obj.Geometry());
      var extended_curve = curve.Extend(curve_end, CurveExtensionStyle.Line, geometry);
      if (extended_curve != null && extended_curve.IsValid)
      {
        if (!doc.Objects.Replace(curve_obj_ref.ObjectId, extended_curve))
          return Result.Failure;
        doc.Views.Redraw();
      }
      else
      {
        RhinoApp.WriteLine("No boundary object was intersected so curve not extended");
        return Result.Nothing;
      }

      return Result.Success;
    }
コード例 #29
0
        public GetResult GetMultiple(int minimumNumber, int maximumNumber)
        {
            GetObject old = g_active_go;

            g_active_go = this;
            GeometryFilterCallback cb = null;
            Type t = GetType();

            // Hook up CustomGeometryFilter virtual function if this is a subclass. This way we
            // don't have to pin anything and this class will get collected on the next appropriate GC
            if (m_filter != null || t.IsSubclassOf(typeof(GetObject)))
            {
                cb = CustomGeometryFilter;
            }

            IntPtr ptr = NonConstPointer();
            uint   rc  = UnsafeNativeMethods.CRhinoGetObject_GetObjects(ptr, minimumNumber, maximumNumber, cb);

            g_active_go = old;
            return((GetResult)rc);
        }
コード例 #30
0
ファイル: ex_loft.cs プロジェクト: jackieyin2015/rhinocommon
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      // select curves to loft
      var gs = new GetObject();
      gs.SetCommandPrompt("select curves to loft");
      gs.GeometryFilter = ObjectType.Curve;
      gs.DisablePreSelect();
      gs.SubObjectSelect = false;
      gs.GetMultiple(2, 0);
      if (gs.CommandResult() != Result.Success)
        return gs.CommandResult();

      var curves = gs.Objects().Select(obj => obj.Curve()).ToList();

      var breps = Brep.CreateFromLoft(curves, Point3d.Unset, Point3d.Unset, LoftType.Tight, false);
      foreach (var brep in breps)
        doc.Objects.AddBrep(brep);

      doc.Views.Redraw();
      return Result.Success;
    }
コード例 #31
0
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      var gm = new GetObject();
      gm.SetCommandPrompt("Select open mesh");
      gm.GeometryFilter = ObjectType.Mesh;
      gm.GeometryAttributeFilter = GeometryAttributeFilter.OpenMesh;
      gm.Get();
      if (gm.CommandResult() != Result.Success)
        return gm.CommandResult();
      var mesh = gm.Object(0).Mesh();
      if (mesh == null)
        return Result.Failure;

      var polylines = mesh.GetNakedEdges();
      foreach (var polyline in polylines)
      {
        doc.Objects.AddPolyline(polyline);
      }

      return Result.Success;
    }
コード例 #32
0
ファイル: ex_sweep1.cs プロジェクト: austinlaw/rhinocommon
  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;
  }
コード例 #33
0
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      // select a surface
      var gs = new GetObject();
      gs.SetCommandPrompt("select surface");
      gs.GeometryFilter = ObjectType.Surface;
      gs.DisablePreSelect();
      gs.SubObjectSelect = false;
      gs.Get();
      if (gs.CommandResult() != Result.Success)
        return gs.CommandResult();
      // get the selected face
      var face = gs.Object(0).Face();
      if (face == null)
        return Result.Failure;

      // pick a point on the surface.  Constain
      // picking to the face.
      var gp = new GetPoint();
      gp.SetCommandPrompt("select point on surface");
      gp.Constrain(face, false);
      gp.Get();
      if (gp.CommandResult() != Result.Success)
        return gp.CommandResult();

      // get the parameters of the point on the
      // surface that is clesest to gp.Point()
      double u, v;
      if (face.ClosestPoint(gp.Point(), out u, out v))
      {
        var direction = face.NormalAt(u, v);
        if (face.OrientationIsReversed)
          direction.Reverse();
        RhinoApp.WriteLine(
          string.Format(
            "Surface normal at uv({0:f},{1:f}) = ({2:f},{3:f},{4:f})", 
            u, v, direction.X, direction.Y, direction.Z));
      }
      return Result.Success;
    }
コード例 #34
0
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      var go = new GetObject();
      go.SetCommandPrompt("Select 2, 3, or 4 open curves");
      go.GeometryFilter = ObjectType.Curve;
      go.GeometryAttributeFilter = GeometryAttributeFilter.OpenCurve;
      go.GetMultiple(2, 4);
      if (go.CommandResult() != Result.Success)
        return go.CommandResult();

      var curves = go.Objects().Select(o => o.Curve());

      var brep = Brep.CreateEdgeSurface(curves);

      if (brep != null)
      {
        doc.Objects.AddBrep(brep);
        doc.Views.Redraw();
      }

      return Result.Success;
    }
コード例 #35
0
    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);
    }
コード例 #36
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
    double intersection_tolerance = 0.001;
    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;
  }
コード例 #37
0
  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;
  }
コード例 #38
0
ファイル: GH_Getter2.cs プロジェクト: panhao4812/GHComponent1
        public static List<GH_LinearDimension> GetLinearDimensions2()
        {
            GetObject obj2;
            Label_0000:
            obj2 = new GetObject();
            if (m_reference)
            {
                obj2.SetCommandPrompt("LinearDimension  reference");
                obj2.AddOption("Mode", "Reference");
            }
            else
            {
                obj2.SetCommandPrompt("LinearDimension to copy");
                obj2.AddOption("Mode", "Copy");
            }
            obj2.GeometryFilter = ObjectType.Annotation;
            GetResult multiple = obj2.GetMultiple(1, 0);
            if (multiple == GetResult.Option)
            {
                m_reference = !m_reference;
                goto Label_0000;
            }
            if (multiple != GetResult.Object)
            {
                return null;
            }
            List<GH_LinearDimension> list2 = new List<GH_LinearDimension>();

            for (int i = 0; i < obj2.ObjectCount; i++)
            {
                if (m_reference)
                {
                    GH_LinearDimension dm = new GH_LinearDimension(obj2.Object(i).ObjectId);
                    if ((dm != null) && (!dm.IsGeometryLoaded)) { dm.LoadGeometry(); }
                    list2.Add( dm);
                }
                else
                {
                    list2.Add(new GH_LinearDimension((LinearDimension)obj2.Object(i).Geometry()));
                }
            }
            return list2;
        }
コード例 #39
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            //pick surface to orient to or block instance to relocate
            GetObject gs = new Rhino.Input.Custom.GetObject();

            gs.SetCommandPrompt("Surface to orient new object on or BlockInstance to move");
            gs.GeometryFilter              = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.InstanceReference;
            gs.SubObjectSelect             = true;
            gs.DeselectAllBeforePostSelect = false;
            gs.OneByOnePostSelect          = true;
            gs.Get();
            if (gs.CommandResult() != Result.Success)
            {
                return(gs.CommandResult());
            }

            Rhino.DocObjects.ObjRef      objref = gs.Object(0);
            Rhino.DocObjects.RhinoObject obj    = objref.Object();
            if (obj == null)
            {
                return(Result.Failure);
            }
            surface = objref.Surface();


            //relocate block instance
            if (surface == null)
            {
                Rhino.DocObjects.InstanceObject instance1 = objref.Object() as Rhino.DocObjects.InstanceObject;

                instancePoint = instance1.InsertionPoint;
                double g, h;
                surface2.ClosestPoint(instancePoint, out g, out h);
                var instanceDirection = surface2.NormalAt(g, h);
                instancePlane = new Plane(instancePoint, instanceDirection);

                Rhino.Input.Custom.GetPoint gpss = new Rhino.Input.Custom.GetPoint();
                gpss.SetCommandPrompt("Point on surface to orient to");
                gpss.Constrain(surface2, false);

                gpss.DynamicDraw += RefObjDraw;
                gpss.Tag          = instance1;

                gpss.Get();
                if (gpss.CommandResult() != Rhino.Commands.Result.Success)
                {
                    return(gpss.CommandResult());
                }
                Point3d ptss = gpss.Point();
                surface2.ClosestPoint(ptss, out g, out h);
                var       direction1 = surface2.NormalAt(g, h);
                Plane     pl11       = new Plane(ptss, direction1);
                Transform iform      = Rhino.Geometry.Transform.PlaneToPlane(instancePlane, pl11);
                doc.Objects.Transform(instance1, iform, true);

                return(Result.Success);
            }

            obj.Select(false);

            //pick objekt to orient
            var copy = new Rhino.Input.Custom.OptionToggle(false, "No", "Yes");

            GetObject go = new GetObject();

            go.SetCommandPrompt("Select object to orient.");
            go.AddOptionToggle("Copy", ref copy);
            go.SubObjectSelect             = true;
            go.DeselectAllBeforePostSelect = false;
            go.GroupSelect = true;

            for (; ;)
            {
                var res = go.GetMultiple(1, -1);
                if (gs.CommandResult() != Result.Success)
                {
                    return(gs.CommandResult());
                }
                if (res == GetResult.Option)
                {
                    copyBol = copy.CurrentValue;
                    continue;
                }
                if (gs.CommandResult() != Result.Success)
                {
                    return(gs.CommandResult());
                }

                break;
            }



            int    obCount      = go.ObjectCount;
            string instDefCount = DateTime.Now.ToString("ddMMyyyyHHmmss");

            //create block instance and plane for instance
            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());
            }

            Vector3d vt1 = new Vector3d(0, 0, 1);
            Point3d  pt1 = gp.Point();

            sourcePlane = new Plane(pt1, vt1);
            Plane     originPlane = new Plane(Point3d.Origin, vt1);
            Transform bform       = Rhino.Geometry.Transform.PlaneToPlane(sourcePlane, originPlane);

            //block instance
            GeometryBase[] obj1List = new GeometryBase[obCount];
            List <Brep>    opList   = new List <Brep>();

            for (int igo = 0; igo < obCount; igo++)
            {
                Rhino.DocObjects.ObjRef      objref1 = go.Object(igo);
                Rhino.DocObjects.RhinoObject obj1    = objref1.Object();
                if (obj == null)
                {
                    return(Result.Failure);
                }
                obj.Select(false);


                Rhino.Geometry.Brep opItem = objref1.Brep();
                opList.Add(opItem);

                GeometryBase obj1Base = obj1.Geometry;
                obj1Base.Transform(bform);

                obj1List[igo] = obj1Base;
            }

            var orientBlock = doc.InstanceDefinitions.Add("Block" + instDefCount, "OrientBlock", Point3d.Origin, obj1List);

            //get all go.Objects to .Tag
            Brep[] op = new Brep[obCount];
            op = Brep.CreateBooleanUnion(opList, 0.01);
            Brep od = new Brep();

            od = op[0];
            var odGuid = doc.Objects.AddBrep(od);

            Rhino.DocObjects.ObjRef      objref2 = new Rhino.DocObjects.ObjRef(odGuid);
            Rhino.DocObjects.RhinoObject objDrw  = objref2.Object();

            //orient plane to surface
            if (copyBol)
            {
                while (true)
                {
                    Rhino.Input.Custom.GetPoint gps = new Rhino.Input.Custom.GetPoint();
                    gps.SetCommandPrompt("Point on surface to orient to. Press enter when done.");
                    gps.Constrain(surface, false);
                    gps.AcceptNothing(true);
                    gps.DynamicDraw += RefObjDraw;
                    gps.Tag          = objDrw;

                    var res = gps.Get();

                    if (res == GetResult.Nothing)
                    {
                        break;
                    }
                    //else if (gps.CommandResult() != Rhino.Commands.Result.Success)
                    //    return gps.CommandResult();


                    Point3d pts = gps.Point();
                    double  u, v;
                    surface.ClosestPoint(pts, out u, out v);
                    Vector3d direction = surface.NormalAt(u, v);
                    Plane    pl1       = new Plane(pts, direction);

                    Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.PlaneToPlane(originPlane, pl1);

                    doc.Objects.AddInstanceObject(orientBlock, xform);

                    doc.Objects.Delete(objDrw);
                }
                copyBol = false;
            }
            else
            {
                Rhino.Input.Custom.GetPoint gps = new Rhino.Input.Custom.GetPoint();
                gps.SetCommandPrompt("Point on surface to orient to");
                gps.Constrain(surface, false);

                gps.DynamicDraw += RefObjDraw;
                gps.Tag          = objDrw;

                gps.Get();
                if (gps.CommandResult() != Rhino.Commands.Result.Success)
                {
                    return(gps.CommandResult());
                }
                Point3d pts = gps.Point();
                double  u, v;
                surface.ClosestPoint(pts, out u, out v);
                Vector3d direction = surface.NormalAt(u, v);
                Plane    pl1       = new Plane(pts, direction);

                Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.PlaneToPlane(originPlane, pl1);

                doc.Objects.AddInstanceObject(orientBlock, xform);

                doc.Objects.Delete(objDrw);
            }

            surface2 = surface;

            return(Result.Success);
        }
コード例 #40
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            double       tolerance = doc.ModelAbsoluteTolerance;
            List <Curve> curves    = new List <Curve>();

            //Select surface

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

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

            Rhino.DocObjects.ObjRef      objref_Surface = gs.Object(0);
            Rhino.DocObjects.RhinoObject obj            = objref_Surface.Object();
            if (obj == null)
            {
                return(Result.Failure);
            }
            surface = objref_Surface.Surface();

            if (surface == null)
            {
                return(Result.Failure);
            }
            obj.Select(false);

            //Select Line(s)
            GetObject gl = new GetObject();

            gl.SetCommandPrompt("Select one or two line(s)");
            gl.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
            gl.DeselectAllBeforePostSelect = true;
            gl.OneByOnePostSelect          = true;
            gl.GetMultiple(1, 0);

            for (int i = 0; i < gl.ObjectCount; i++)
            {
                Rhino.DocObjects.ObjRef objref_Line = gl.Object(i);
                curve = objref_Line.Curve();

                Curve curveRe = curve.Rebuild(60, 3, true);
                curves.Add(curveRe);
            }

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

            if (curves.Count > 1)
            {
                Curve curve2 = curves[0];
                Curve curve3 = curves[1];
                if (curve2.IsClosed || curve3.IsClosed)
                {
                    Rhino.UI.Dialogs.ShowMessage("Please only select open curves for two line pave.", "Warning!");
                    return(Result.Failure);
                }

                while (true)
                {
                    cir_guid_list = new List <Guid>();



                    var   tweenCurves = Curve.CreateTweenCurvesWithSampling(curve2, curve3, 1, 30, tolerance);
                    Curve tCurve      = tweenCurves[0];

                    //3 point circle
                    Point3d   po1   = curve2.PointAtStart;
                    Point3d   po2   = curve3.PointAtStart;
                    LineCurve line1 = new LineCurve(po1, po2);
                    double[]  param = line1.DivideByCount(2, false);

                    double param1 = param[0];
                    double param2 = param[0];
                    double param3 = param[0];

                    Curve curve1 = line1;



                    while (true)
                    {
                        Circle outCircle = Circle.TryFitCircleTTT(curve1, curve2, curve3, param1, param2, param3);


                        //circle normal to surface

                        Point3d outCircleCenter = outCircle.Center;
                        double  outCircleRadius = outCircle.Radius;
                        double  u, v;
                        surface.ClosestPoint(outCircleCenter, out u, out v);
                        var     direction  = surface.NormalAt(u, v);
                        Point3d surfCenter = surface.PointAt(u, v);
                        Plane   pl1        = new Plane(surfCenter, direction);
                        Circle  circle     = new Circle(pl1, surfCenter, outCircleRadius - offSetStone);
                        Circle  circleDist = new Circle(pl1, surfCenter, outCircleRadius + stoneDist);
                        Guid    cir_guid   = doc.Objects.AddCircle(circle);
                        cir_guid_list.Add(cir_guid);


                        //Cut tween curve at latest circle center
                        Point3d pointOnCurve;
                        Point3d pointOnCircle;
                        Curve   circleDistCurve = circleDist.ToNurbsCurve();
                        tCurve.Domain = new Interval(0, tCurve.GetLength());
                        Curve[] splitCurves = tCurve.Split(outCircleRadius);
                        if (splitCurves is null)
                        {
                            break;
                        }
                        tCurve = splitCurves[splitCurves.Length - 1];
                        tCurve.ClosestPoints(circleDistCurve, out pointOnCurve, out pointOnCircle);

                        //Cut tween curve at latest circle border
                        double curveSplitParam;
                        tCurve.Domain = new Interval(0, tCurve.GetLength());
                        tCurve.ClosestPoint(pointOnCurve, out curveSplitParam);
                        splitCurves = tCurve.Split(curveSplitParam);
                        if (splitCurves is null)
                        {
                            break;
                        }
                        tCurve = splitCurves[splitCurves.Length - 1];

                        //New parameter at curve1
                        double circleParam;
                        circleDistCurve.ClosestPoint(pointOnCircle, out circleParam);
                        param1 = circleParam;
                        curve1 = circleDistCurve;

                        //New parameter at curves[0]
                        double paramCurve0New;
                        curve2.ClosestPoint(pointOnCircle, out paramCurve0New);
                        Point3d pointCurve0New = curve2.PointAt(paramCurve0New);
                        double  distNewPoints0 = pointOnCircle.DistanceTo(pointCurve0New);
                        param2 = paramCurve0New + distNewPoints0;

                        //New parameter at curves[1]
                        double paramCurve1New;
                        curve3.ClosestPoint(pointOnCircle, out paramCurve1New);
                        Point3d pointCurve1New = curve3.PointAt(paramCurve1New);
                        double  distNewPoints1 = pointOnCircle.DistanceTo(pointCurve1New);
                        param3 = paramCurve1New + distNewPoints1;
                    }

                    doc.Views.Redraw();


                    //Options
                    var go = new GetOption();
                    go.SetCommandPrompt("Set options.");


                    var stoneOff   = new Rhino.Input.Custom.OptionDouble(offSetStone);
                    var distStone  = new Rhino.Input.Custom.OptionDouble(stoneDist);
                    var boolOption = new Rhino.Input.Custom.OptionToggle(false, "Off", "On");


                    go.AddOptionDouble("Offset", ref stoneOff);
                    go.AddOptionDouble("Distance", ref distStone);
                    go.AddOptionToggle("Reverse", ref boolOption);

                    go.AcceptNothing(true);

                    var res = go.Get();

                    if (res == GetResult.Nothing)
                    {
                        break;
                    }
                    if (res == GetResult.Cancel)
                    {
                        break;
                    }

                    foreach (var gui in cir_guid_list)
                    {
                        var gu = doc.Objects.Find(gui);
                        doc.Objects.Delete(gu);
                    }



                    offSetStone = stoneOff.CurrentValue;
                    stoneDist   = distStone.CurrentValue;
                    optionBool  = boolOption.CurrentValue;

                    if (optionBool == true)
                    {
                        curve2.Reverse();
                        curve2 = curve2.Rebuild(60, 3, false);
                        curve3.Reverse();
                        curve3     = curve3.Rebuild(60, 3, false);
                        optionBool = false;
                    }
                }
            }

            else
            {
                while (true)
                {
                    cir_guid_list = new List <Guid>();
                    List <Point3d> points = new List <Point3d>();


                    double length     = (diamStone / 2) + offSetStone;
                    double crv_length = curve.GetLength();

                    Point3d point = curve.PointAtLength(length);
                    points.Add(point);

                    while (true)
                    {
                        length += diamStone + offSetStone;
                        if (length > crv_length)
                        {
                            break;
                        }
                        point = curve.PointAtLength(length);
                        points.Add(point);
                    }

                    foreach (var poi in points)
                    {
                        double u, v;
                        surface.ClosestPoint(poi, out u, out v);
                        var      direction = surface.NormalAt(u, v);
                        double   x         = direction.X;
                        double   y         = direction.Y;
                        double   z         = direction.Z;
                        Vector3d vt1       = new Vector3d(x, y, z);
                        Plane    pl1       = new Plane(poi, vt1);
                        Circle   circle    = new Circle(pl1, poi, diamStone / 2);
                        Guid     cir_guid  = doc.Objects.AddCircle(circle);
                        cir_guid_list.Add(cir_guid);
                    }

                    doc.Views.Redraw();

                    //Options
                    var go = new GetOption();
                    go.SetCommandPrompt("Set options.");

                    var stoneDiam  = new Rhino.Input.Custom.OptionDouble(diamStone);
                    var stoneOff   = new Rhino.Input.Custom.OptionDouble(offSetStone);
                    var boolOption = new Rhino.Input.Custom.OptionToggle(false, "Off", "On");

                    go.AddOptionDouble("StoneDiam", ref stoneDiam);
                    go.AddOptionDouble("Offset", ref stoneOff);
                    go.AddOptionToggle("Reverse", ref boolOption);

                    go.AcceptNothing(true);

                    var res = go.Get();

                    if (res == GetResult.Nothing)
                    {
                        break;
                    }
                    if (res == GetResult.Cancel)
                    {
                        break;
                    }

                    foreach (var gui in cir_guid_list)
                    {
                        var gu = doc.Objects.Find(gui);
                        doc.Objects.Delete(gu);
                    }


                    diamStone   = stoneDiam.CurrentValue;
                    offSetStone = stoneOff.CurrentValue;
                    optionBool  = boolOption.CurrentValue;

                    if (optionBool == true)
                    {
                        curve.Reverse();
                    }
                }
            }


            doc.Views.Redraw();

            doc.Groups.Add(cir_guid_list);

            return(Result.Success);
        }
コード例 #41
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.PolysrfFilter;

            Rhino.DocObjects.ObjRef objref;
            Result rc = Rhino.Input.RhinoGet.GetOneObject("Select first/main polysurface or surface to bool",
                                                          false, geometryFilter, out objref);

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

            Rhino.Geometry.Brep brep = objref.Brep();
            bool resIssolid          = brep.IsSolid;

            if (!resIssolid)
            {
                Dialogs.ShowMessage("Your polysurface or surface is not solid! Result might not be valid!", "Warning!");
            }
            Guid firstBrep = objref.ObjectId;

            doc.Objects.UnselectAll(true);


            //Select rest of polysurfaces or surfaces to bool
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select rest of polysurfaces or surfaces to bool");
            go.GeometryFilter = geometryFilter | Rhino.DocObjects.ObjectType.InstanceReference;
            go.GroupSelect    = true;
            go.GetMultiple(1, 0);

            bool isSolid = true;

            //Add set to breps list
            List <Rhino.Geometry.Brep> breps = new List <Rhino.Geometry.Brep>();

            for (int i = 0; i < go.ObjectCount; i++)
            {
                //Explode if instance object and add to breps list
                if (go.Object(i).Object() is InstanceObject)
                {
                    InstanceObject     instObj = go.Object(i).Object() as InstanceObject;
                    RhinoObject[]      explodedObjects;
                    ObjectAttributes[] attributesOfExplodedObjects;
                    Transform[]        transformOfExplodedObjects;

                    instObj.Explode(false, out explodedObjects, out attributesOfExplodedObjects, out transformOfExplodedObjects);
                    Guid addedObjectID = doc.Objects.Add(explodedObjects[0].Geometry, explodedObjects[0].Attributes);

                    ObjRef objrefs            = new Rhino.DocObjects.ObjRef(addedObjectID);
                    Rhino.Geometry.Brep brepd = objrefs.Brep();

                    brepd.Transform(transformOfExplodedObjects[0]);

                    resIssolid = brepd.IsSolid;
                    if (!resIssolid)
                    {
                        isSolid = false;
                    }
                    if (brepd != null && firstBrep != addedObjectID)
                    {
                        breps.Add(brepd);
                    }
                    doc.Objects.Delete(addedObjectID, true);
                }
                else
                {
                    Rhino.DocObjects.ObjRef objrefs = go.Object(i);
                    Rhino.Geometry.Brep     brepd   = objrefs.Brep();
                    resIssolid = brepd.IsSolid;
                    if (!resIssolid)
                    {
                        isSolid = false;
                    }
                    if (brepd != null && firstBrep != objrefs.ObjectId)
                    {
                        breps.Add(brepd);
                    }
                }
            }
            if (!isSolid)
            {
                Dialogs.ShowMessage("At least on polysurface or surface to subtract is not solid! Result might not be valid!", "Warning!");
            }

            doc.Objects.UnselectAll(true);

            //Create layers for failed and successfull booleans if not already existing
            var fail_layer_index = doc.Layers.FindName("FJ Boolean Fails");

            if (fail_layer_index == null)
            {
                string name_fail_layer          = "FJ Boolean Fails";
                Rhino.DocObjects.Layer boolFail = new Rhino.DocObjects.Layer();
                boolFail.Name  = name_fail_layer;
                boolFail.Color = System.Drawing.Color.Red;
                doc.Layers.Add(boolFail);
                fail_layer_index = doc.Layers.FindName(name_fail_layer);
            }

            var done_layer_index = doc.Layers.FindName("FJ Boolean Done");

            if (done_layer_index == null)
            {
                string name_done_layer          = "FJ Boolean Done";
                Rhino.DocObjects.Layer boolDone = new Rhino.DocObjects.Layer();
                boolDone.Name  = name_done_layer;
                boolDone.Color = System.Drawing.Color.BlueViolet;
                doc.Layers.Add(boolDone);
                done_layer_index = doc.Layers.FindName(name_done_layer);
            }

            //Compute boolean union
            double tolerance = doc.ModelAbsoluteTolerance;
            int    a         = 0;

            for (int i = 0; i < breps.Count; i++)
            {
                RhinoApp.WriteLine("computing number: " + i + " of: " + breps.Count + " operations...");

                List <Brep> brepBool = new List <Brep>();
                brepBool.Add(brep);
                brepBool.Add(breps[i]);
                Rhino.Geometry.Brep[] brepBoolNew = Rhino.Geometry.Brep.CreateBooleanUnion(brepBool, tolerance, true);

                if (brepBoolNew == null || brepBoolNew.Length > 1)
                {
                    a++;
                    doc.Objects.Delete(go.Object(i).Object());

                    var    boolresultfail = doc.Objects.AddBrep(breps[i]);
                    ObjRef objFailref     = new ObjRef(boolresultfail);
                    Rhino.DocObjects.RhinoObject objFail = objFailref.Object();
                    objFail.Attributes.LayerIndex = fail_layer_index.Index;
                    objFail.CommitChanges();
                }
                else
                {
                    brep = brepBoolNew[0];
                    doc.Objects.Delete(go.Object(i).Object());

                    var    boolresult = doc.Objects.AddBrep(breps[i]);
                    ObjRef obj20ref   = new ObjRef(boolresult);
                    Rhino.DocObjects.RhinoObject obj2Org = obj20ref.Object();
                    obj2Org.Attributes.LayerIndex = done_layer_index.Index;
                    obj2Org.CommitChanges();
                }

                doc.Views.Redraw();
            }

            RhinoApp.WriteLine(a + " of " + breps.Count + " operations failed!");

            Rhino.DocObjects.RhinoObject obj1Org = objref.Object();
            doc.Objects.Delete(obj1Org);

            doc.Objects.AddBrep(brep);

            doc.Views.Redraw();
            return(Rhino.Commands.Result.Success);
        }
コード例 #42
0
        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
                {
                    Material  = new SteelMaterial("B500B"),
                    BasePoint = 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);
        }
コード例 #43
0
ファイル: BBWaffleCommand.cs プロジェクト: olitur/Bowerbird
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // --- Set tolerance

            _unit = doc.ModelAbsoluteTolerance;


            // --- Get Mesh

            var getMesh = new GetObject { GeometryFilter = ObjectType.Mesh };
            getMesh.SetCommandPrompt("Select mesh");

            while (true)
            {
                var getMeshResult = getMesh.Get();

                if (getMesh.CommandResult() != Result.Success)
                    return getMesh.CommandResult();

                if (getMeshResult == GetResult.Object)
                    break;
            }

            _mesh = (Mesh)getMesh.Object(0).Geometry();

            doc.Objects.UnselectAll();


            // --- Start preview
            
            DisplayPipeline.DrawOverlay += DisplayPipelineOnDrawOverlay;


            // --- Get options

            var getOptions = new GetOption();
            getOptions.SetCommandPrompt("Settings:");
            getOptions.AddOptionInteger("CountX", ref _countX);
            getOptions.AddOptionInteger("CountY", ref _countY);
            getOptions.AddOptionDouble("Thickness", ref _thickness);
            getOptions.AddOption("Plane");
            getOptions.AddOptionDouble("Deeper", ref _deeper);
            getOptions.AddOptionToggle("DeleteInput", ref _deleteSource);
            getOptions.AddOptionToggle("Project", ref _project);
            getOptions.AddOptionDouble("ProjectSpace", ref _projectSpace);
            getOptions.AcceptNothing(true);

            do
            {
                doc.Views.Redraw();

                getOptions.Get();

                switch (getOptions.Result())
                {
                    case GetResult.Option:
                        switch (getOptions.Option().EnglishName)
                        {
                            case "Plane":
                                _plane = PlaneGetter.GetPlane() ?? _plane;
                                break;
                        }
                        break;
                }
            } while (getOptions.CommandResult() == Result.Success && getOptions.Result() != GetResult.Nothing);


            // --- Stop preview

            DisplayPipeline.DrawOverlay -= DisplayPipelineOnDrawOverlay;


            // --- Check for cancel with ESC

            if (getOptions.Result() == GetResult.Cancel)
                return Result.Cancel;


            // --- Execute

            var result = Waffle.Create(_mesh, _plane, _thickness.CurrentValue, _deeper.CurrentValue, _countX.CurrentValue, _countY.CurrentValue, _unit, _project.CurrentValue, _projectSpace.CurrentValue);


            // --- Add objects

            foreach (var curves in result.CurvesX)
                doc.Groups.Add(curves.Select(o => doc.Objects.AddCurve(o)));

            foreach (var curves in result.CurvesY)
                doc.Groups.Add(curves.Select(o => doc.Objects.AddCurve(o)));


            // --- Delete input

            if (_deleteSource.CurrentValue)
                doc.Objects.Delete(getMesh.Object(0).ObjectId, true);


            // --- Update views

            doc.Views.Redraw();


            return Result.Success;
        }
コード例 #44
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            double tolerance      = doc.ModelAbsoluteTolerance;
            double angleTolerance = doc.ModelAngleToleranceRadians;


            List <Curve> icur = new List <Curve>();

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

            gcr.SetCommandPrompt("Select reference circles for prongs. (No curves)");
            gcr.GeometryFilter              = Rhino.DocObjects.ObjectType.Curve;
            gcr.GroupSelect                 = true;
            gcr.SubObjectSelect             = true;
            gcr.DeselectAllBeforePostSelect = true;
            gcr.OneByOnePostSelect          = false;
            gcr.GetMultiple(1, 0);

            for (int ie = 0; ie < gcr.ObjectCount; ie++)
            {
                Rhino.DocObjects.ObjRef      objref = gcr.Object(ie);
                Rhino.DocObjects.RhinoObject obj    = objref.Object();
                if (obj == null)
                {
                    return(Result.Failure);
                }
                Curve refcr = objref.Curve();
                if (refcr == null)
                {
                    return(Result.Failure);
                }
                obj.Select(false);

                icur.Add(refcr);
            }

            while (true)
            {
                m_escape_key_pressed       = false;
                RhinoApp.EscapeKeyPressed += RhinoApp_EscapeKeyPressed;

                Point3d pt0 = new Point3d(0, 0, hight);
                Point3d pt1 = new Point3d(0, 0, -(length - hight));

                double rotationRadiant = ((rotation / 180) * 3.1415);

                List <Point3d> curvePoints = new List <Point3d>()
                {
                    pt0, pt1
                };
                Curve prongCurve = Curve.CreateInterpolatedCurve(curvePoints, 3);

                if (!capBool)
                {
                    capMode = PipeCapMode.Flat;
                }
                else if (capBool)
                {
                    capMode = PipeCapMode.Round;
                }

                Brep[] cylBrep1 = Brep.CreatePipe(prongCurve, prongDia / 2, false, capMode, false, tolerance, angleTolerance);
                Brep   cylBrep2 = cylBrep1[0];
                cylBrep2.Faces.RemoveAt(2);
                Brep cylBrep3 = cylBrep2.CapPlanarHoles(tolerance);

                if (capBool)
                {
                    Vector3d     scaleVec   = new Vector3d(0, 0, 1);
                    var          scalePlane = new Plane(pt0, scaleVec);
                    var          capScale   = Transform.Scale(scalePlane, 1.0, 1.0, capHight);
                    var          surf2      = cylBrep3.Faces[1].UnderlyingSurface();
                    NurbsSurface nurbSurf2  = surf2.ToNurbsSurface();
                    nurbSurf2.Transform(capScale);
                    Brep capBrep = nurbSurf2.ToBrep();
                    cylBrep3.Append(capBrep);
                    cylBrep3.Faces.RemoveAt(1);
                }

                cylBrep3.Compact();
                cylBrep3.JoinNakedEdges(tolerance);
                string instDefCount = DateTime.Now.ToString("ddMMyyyyHHmmss");
                Brep[] brepArray    = new Brep[1] {
                    cylBrep3
                };
                var prongIndex = doc.InstanceDefinitions.Add("Prong" + instDefCount, "RefProng", Point3d.Origin, brepArray);

                foreach (Curve c in icur)
                {
                    Circle circleProngs = new Circle();
                    c.TryGetCircle(out circleProngs, tolerance);
                    NurbsCurve curveProngs = circleProngs.ToNurbsCurve();

                    Plane    planeNew = circleProngs.Plane;
                    Vector3d plVec    = planeNew.Normal;

                    if (planeNew == null)
                    {
                        curveProngs.DivideByCount(3, true, out Point3d[] curveProngsPoints);
                        planeNew = new Plane(curvePoints[0], curveProngsPoints[1], curveProngsPoints[2]);
                    }


                    Curve[] offsetCurveArray = curveProngs.Offset(planeNew, prongDia / 4, tolerance, CurveOffsetCornerStyle.Sharp);

                    Curve offsetCurve = offsetCurveArray[0];

                    double[] segParameters = offsetCurve.DivideByCount(prongCount, true);

                    List <Point3d> prongPoints = new List <Point3d>();
                    List <Guid>    idsInter    = new List <Guid>();

                    foreach (double p in segParameters)
                    {
                        Point3d zen        = new Point3d(0, 0, 0);
                        Point3d prongPoint = offsetCurve.PointAt(p);

                        Point3d  center  = circleProngs.Center;
                        Vector3d moveV   = new Vector3d(prongPoint);
                        Vector3d zaxis   = new Vector3d(0.0, 0.0, 1.0);
                        Plane    planeOr = new Plane(zen, zaxis);
                        Plane    plane   = new Plane(prongPoint, plVec);

                        var transform1 = Transform.PlaneToPlane(planeOr, plane);
                        var transform2 = Transform.Rotation(rotationRadiant, plVec, center);

                        var prongA = doc.Objects.AddInstanceObject(prongIndex, transform1);
                        var prongB = doc.Objects.Transform(prongA, transform2, true);

                        ids.Add(prongB);
                    }
                    doc.Views.Redraw();
                }


                GetOption go = new Rhino.Input.Custom.GetOption();
                go.SetCommandPrompt("Set prong parameters.");
                go.AcceptNothing(true);

                var countProng  = new Rhino.Input.Custom.OptionInteger(prongCount);
                var diaProng    = new Rhino.Input.Custom.OptionDouble(prongDia);
                var hightProng  = new Rhino.Input.Custom.OptionDouble(hight);
                var lengthProng = new Rhino.Input.Custom.OptionDouble(length);
                var rotProng    = new Rhino.Input.Custom.OptionDouble(rotation);
                var capProng    = new Rhino.Input.Custom.OptionToggle(capBool, "Flat", "Round");
                var hightCap    = new Rhino.Input.Custom.OptionDouble(capHight);

                go.AddOptionInteger("Count", ref countProng);
                go.AddOptionDouble("Diameter", ref diaProng);
                go.AddOptionDouble("Hight", ref hightProng);
                go.AddOptionDouble("Length", ref lengthProng);
                go.AddOptionDouble("Rotation", ref rotProng);
                go.AddOptionToggle("Cap", ref capProng);
                if (capBool)
                {
                    go.AddOptionDouble("Caphight", ref hightCap);
                }

                GetResult res = go.Get();

                if (m_escape_key_pressed)
                {
                    break;
                }

                hight      = hightProng.CurrentValue;
                length     = lengthProng.CurrentValue;
                prongCount = countProng.CurrentValue;
                prongDia   = diaProng.CurrentValue;
                rotation   = rotProng.CurrentValue;
                capBool    = capProng.CurrentValue;
                capHight   = hightCap.CurrentValue;

                if (length <= 0.0)
                {
                    length = 1.0;
                }
                if (prongCount <= 0)
                {
                    prongCount = 1;
                }
                if (prongDia <= 0.0)
                {
                    prongDia = 1.0;
                }
                if (res == GetResult.Nothing)
                {
                    break;
                }

                doc.Objects.Delete(ids, true);
            }
            RhinoApp.EscapeKeyPressed -= RhinoApp_EscapeKeyPressed;

            doc.Groups.Add(ids);

            return(Result.Success);
        }
コード例 #45
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            //pick objects to expand
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select objects to expand");
            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.GetMultiple(1, 0);

            //Compute center
            Point3d centersAdd = new Point3d();

            for (int i = 0; i < go.ObjectCount; i++)
            {
                BoundingBox bbObj       = go.Object(i).Geometry().GetBoundingBox(true);
                Point3d     bbObjCenter = bbObj.Center;
                centers.Add(bbObjCenter);
                centersAdd += bbObjCenter;

                Rhino.DocObjects.ObjRef objref = go.Object(i);
                // get selected surface object
                Rhino.DocObjects.RhinoObject obj = objref.Object();
                goList.Add(obj);
            }
            Point3d allCenter = centersAdd / centers.Count;

            //pick center
            GetPoint gp = new GetPoint();

            gp.SetCommandPrompt("Basepoint. Press Enter for automatic.");
            gp.AcceptNothing(true);
            var resgp = gp.Get();

            if (resgp == GetResult.Nothing)
            {
                scaleCenter = allCenter;
            }
            else
            {
                scaleCenter = gp.Point();
            }

            //Expansion factor
            GetPoint gp2 = new GetPoint();

            gp2.SetCommandPrompt("Expansion factor or first reference point <" + factor + ">");
            gp2.DrawLineFromPoint(scaleCenter, true);
            gp2.AcceptNumber(true, true);
            GetResult gr = gp2.Get();

            Rhino.Display.RhinoView view = gp2.View();
            plane2D = view.ActiveViewport.ConstructionPlane();

            if (gr == GetResult.Number)
            {
                factor = gp2.Number();
            }
            if (gr == GetResult.Point)
            {
                scaleRefPoint = gp2.Point();
                Line line1     = new Line(scaleCenter, scaleRefPoint);
                Guid tempLine  = doc.Objects.AddLine(line1);
                Guid tempPoint = doc.Objects.AddPoint(scaleRefPoint);
                if (scaleCenter == gp2.Point())
                {
                    return(Rhino.Commands.Result.Cancel);
                }
                GetPoint gp3 = new GetPoint();
                gp3.SetCommandPrompt("Secondt reference point");
                gp3.AddOptionList("ScaleDimension", dimensions, 0);
                gp3.DrawLineFromPoint(scaleCenter, true);
                gp3.DynamicDraw += RefObjDraw;

                while (true)
                {
                    GetResult res = gp3.Get();
                    if (res == GetResult.Option)
                    {
                        dimensionIndex = gp3.Option().CurrentListOptionIndex;
                        continue;
                    }
                    else if (res == GetResult.Point)
                    {
                        Point3d scaleRefPoint2 = gp3.Point();
                        factor = (scaleCenter.DistanceTo(scaleRefPoint2)) / (scaleCenter.DistanceTo(scaleRefPoint));
                        doc.Objects.Delete(tempLine, true);
                        doc.Objects.Delete(tempPoint, true);
                    }
                    break;
                }
            }
            RhinoApp.WriteLine("Expantion factor: " + factor);

            //Compute translation

            //Translate 3d
            if (dimensionIndex == 0)
            {
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    Vector3d vec   = (centers[i] - scaleCenter) * (factor - 1);
                    var      xform = Transform.Translation(vec);
                    doc.Objects.Transform(go.Object(i), xform, true);
                }
            }
            //Translate 2d
            else if (dimensionIndex == 1)
            {
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    Rhino.Geometry.Vector3d vec = (centers[i] - scaleCenter) * (factor - 1);
                    Vector3d planeNormal        = plane2D.Normal;
                    if (planeNormal[0] != 0)
                    {
                        vec.X = 0;
                    }
                    else if (planeNormal[1] != 0)
                    {
                        vec.Y = 0;
                    }
                    else if (planeNormal[2] != 0)
                    {
                        vec.Z = 0;
                    }
                    var xform = Rhino.Geometry.Transform.Translation(vec);
                    doc.Objects.Transform(go.Object(i), xform, true);
                }
            }
            //Translate 1d
            else if (dimensionIndex == 2)
            {
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    Vector3d vecEach       = (centers[i] - scaleCenter);
                    double   vecEachLength = vecEach.Length * (factor - 1);
                    Vector3d vec           = (scaleRefPoint - scaleCenter);
                    double   angleVec      = Vector3d.VectorAngle(vecEach, vec);
                    int      pol           = 1;
                    if (angleVec > 1.57)
                    {
                        pol = -1;
                    }
                    vec.Unitize();
                    vec = vec * vecEachLength * pol;

                    var xform = Transform.Translation(vec);
                    doc.Objects.Transform(go.Object(i), xform, true);
                }
            }

            goList         = new List <Object>();
            centers        = new List <Point3d>();
            dimensionIndex = 0;
            plane2D        = new Plane();

            doc.Views.Redraw();
            return(Result.Success);
        }
コード例 #46
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: complete command.
            var 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);
        }
コード例 #47
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            //select the cross-section faces
            var gc = new Rhino.Input.Custom.GetObject();

            gc.SetCommandPrompt("Select the surfaces which form the cross-section of the beam.");
            gc.GeometryFilter = Rhino.DocObjects.ObjectType.Surface;
            gc.EnablePreSelect(false, true);
            gc.GetMultiple(1, 1);
            if (gc.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gc.CommandResult());
            }

            var face = gc.Object(0).Face();

            //for each cross-section, get the base-surface curve
            var gv = new Rhino.Input.Custom.GetObject();

            gv.SetCommandPrompt("Select the base_curve.");
            gv.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
            gv.EnablePreSelect(false, true);
            gv.GetMultiple(1, 1);
            if (gv.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gv.CommandResult());
            }

            var base_curve = gv.Object(0).Curve();

            //List of all the sub section
            List <Brep> sub_sections = new List <Brep>();

            for (int i = 0; i < 10; i++)
            {
                //offset the base to form a closed loop
                var curves = base_curve.OffsetOnSurface(face, 0.1, doc.ModelAbsoluteTolerance);
                if (curves.Length > 1)
                {
                    Rhino.RhinoApp.WriteLine("More than one offset");
                    return(Result.Failure);
                }
                var offset_curve = curves[0];

                //connect the curves in a closed loop
                LineCurve    edge1   = new LineCurve(base_curve.PointAtStart, offset_curve.PointAtStart);
                LineCurve    edge2   = new LineCurve(offset_curve.PointAtEnd, base_curve.PointAtEnd);
                List <Curve> prejoin = new List <Curve>();
                prejoin.Add(edge1);
                prejoin.Add(edge2);
                prejoin.Add(base_curve);
                prejoin.Add(offset_curve);

                var loops = Curve.JoinCurves(prejoin, doc.ModelAbsoluteTolerance);

                if (loops.Length > 1)
                {
                    Rhino.RhinoApp.WriteLine("More than one joined loops");
                    return(Result.Failure);
                }
                var loop  = loops[0];
                var breps = Rhino.Geometry.Brep.CreatePlanarBreps(loop);

                if (breps.Length > 1)
                {
                    Rhino.RhinoApp.WriteLine("More than one joined loops");
                    return(Result.Failure);
                }

                sub_sections.Add(breps[0]);

                doc.Objects.AddBrep(breps[0]);
                doc.Views.Redraw();

                base_curve = offset_curve;
            }

            //compute moment of inertia
            var area_properties1 = Rhino.Geometry.AreaMassProperties.Compute(sub_sections);
            var area_properties2 = Rhino.Geometry.AreaMassProperties.Compute(face);

            //check for the difference
            Rhino.RhinoApp.WriteLine("Area {0}", area_properties1.Area);
            Rhino.RhinoApp.WriteLine("Difference in Area {0}", area_properties1.Area - area_properties2.Area);

            Rhino.RhinoApp.WriteLine("Moment X: {0}; Y: {1}; Z: {2} in WCS ", area_properties1.WorldCoordinatesMomentsOfInertia.X, area_properties1.WorldCoordinatesMomentsOfInertia.Y, area_properties1.WorldCoordinatesMomentsOfInertia.Z);
            Rhino.RhinoApp.WriteLine("Difference in Moment X: {0}; Y: {1}; Z: {2} in WCS", area_properties1.WorldCoordinatesMomentsOfInertia.X - area_properties2.WorldCoordinatesMomentsOfInertia.X, area_properties1.WorldCoordinatesMomentsOfInertia.Y - area_properties2.WorldCoordinatesMomentsOfInertia.Y, area_properties1.WorldCoordinatesMomentsOfInertia.Z - area_properties2.WorldCoordinatesMomentsOfInertia.Z);

            //display the centroids
            doc.Objects.AddPoint(area_properties1.Centroid);
            doc.Objects.AddPoint(area_properties2.Centroid);

            doc.Views.Redraw();

            return(Result.Success);
        }
コード例 #48
0
    public GetResult GetMultiple(int minimumNumber, int maximumNumber)
    {
      GetObject old = m_active_go;
      m_active_go = this;
      GeometryFilterCallback cb = null;
      Type t = GetType();
      // Hook up CustomGeometryFilter virtual function is this is a subclass. This way we
      // don't have to pin anything and this class will get collected on the next appropriate GC
      if (t.IsSubclassOf(typeof(GetObject)))
        cb = CustomGeometryFilter;

      IntPtr ptr = NonConstPointer();
      uint rc = UnsafeNativeMethods.CRhinoGetObject_GetObjects(ptr, minimumNumber, maximumNumber, cb);

      m_active_go = old;
      return (GetResult)rc;
    }
コード例 #49
0
  public static Rhino.Commands.Result CreateBlock(Rhino.RhinoDoc doc)
  {
    // 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.Failure;
  }
コード例 #50
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            bool allBrepSolid = true;
            const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Brep | Rhino.DocObjects.ObjectType.Mesh;

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

            wro.SetCommandPrompt("Select objects to weight.");
            wro.GeometryFilter = geometryFilter;

            wro.SubObjectSelect             = true;
            wro.DeselectAllBeforePostSelect = false;
            wro.OneByOnePostSelect          = true;
            wro.GetMultiple(1, 0);

            double volObj3 = 0;


            for (int i = 0; i < wro.ObjectCount; i++)
            {
                Rhino.DocObjects.ObjRef objref = wro.Object(i);
                // get selected surface object
                Rhino.DocObjects.RhinoObject obj = objref.Object();
                if (obj == null)
                {
                    return(Result.Failure);
                }
                // get selected surface (face)

                Brep refcr = objref.Brep();
                if (refcr != null)
                {
                    var    volObj  = VolumeMassProperties.Compute(refcr);
                    double volObj2 = refcr.GetVolume();
                    volObj3 = volObj3 + volObj2;
                    bool brepSolid = refcr.IsSolid;
                    if (brepSolid == false)
                    {
                        allBrepSolid = false;
                    }
                }
                if (refcr == null)
                {
                    Mesh   refcm   = objref.Mesh();
                    Brep   refmb   = Brep.CreateFromMesh(refcm, false);
                    var    volOb   = VolumeMassProperties.Compute(refmb);
                    double volObj4 = refmb.GetVolume();
                    volObj3 = volObj3 + volObj4;
                    bool brepSolid = refmb.IsSolid;
                    if (brepSolid == false)
                    {
                        allBrepSolid = false;
                    }
                }
            }

            double gold18k   = Math.Round(volObj3 * 0.0158, 2, MidpointRounding.AwayFromZero);
            double gold14k   = Math.Round(volObj3 * 0.0146, 2, MidpointRounding.AwayFromZero);
            double platinum  = Math.Round(volObj3 * 0.0214, 2, MidpointRounding.AwayFromZero);
            double palladium = Math.Round(volObj3 * 0.012, 2, MidpointRounding.AwayFromZero);
            double silver925 = Math.Round(volObj3 * 0.0102, 2, MidpointRounding.AwayFromZero);
            double diaCt     = Math.Round(volObj3 * 0.01755, 2, MidpointRounding.AwayFromZero);

            if (allBrepSolid)
            {
                RhinoApp.WriteLine("The weight is: Gold 18k " + gold18k + "g, Gold 14k " + gold14k + "g, Platinum " + platinum + "g, Palladium " + palladium + "g, Silver 925 " + silver925 + "g, Diamond" + diaCt + "Ct");
            }
            else
            {
                RhinoApp.WriteLine("AT LEAST ONE OBJECT IS OPEN! Result might be false!" + "The weight is: Gold 18k " + gold18k + "g, Gold 14k " + gold14k + "g, Platinum " + platinum + "g, Palladium " + palladium + "g, Silver 925 " + silver925 + "g, Diamond" + diaCt + "Ct");
            }



            return(Result.Success);
        }
コード例 #51
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            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);
        }
コード例 #52
0
ファイル: OneDimTest.cs プロジェクト: gkumar08/OneDim
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            //select the cross-section faces
            var gb = new Rhino.Input.Custom.GetObject();

            gb.SetCommandPrompt("Select the surfaces which form the cross-section of the beam.");
            gb.GeometryFilter = Rhino.DocObjects.ObjectType.Surface;
            gb.EnablePreSelect(false, true);
            gb.GetMultiple(1, 0);
            if (gb.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gb.CommandResult());
            }

            List <BrepFace> cross_section = new List <BrepFace>();

            for (int i = 0; i < gb.ObjectCount; i++)
            {
                var face = gb.Object(i).Face();
                if (face != null)
                {
                    cross_section.Add(face);
                }
            }

            //select the rail
            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);
        }
コード例 #53
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var myTypes = ObjectType.AnyObject ^ ObjectType.BrepLoop;


            //pick objects to expand
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select objects to scale");
            go.GeometryFilter = myTypes;
            //go.GroupSelect = true;
            go.SubObjectSelect = true;
            //go.EnableClearObjectsOnEntry(false);
            //go.EnableUnselectObjectsOnExit(false);
            //go.DeselectAllBeforePostSelect = false;
            go.GetMultiple(1, 0);

            //Compute center
            Point3d centersAdd = new Point3d();

            for (int i = 0; i < go.ObjectCount; i++)
            {
                BoundingBox bbObj       = go.Object(i).Geometry().GetBoundingBox(true);
                Point3d     bbObjCenter = bbObj.Center;
                centers.Add(bbObjCenter);
                centersAdd += bbObjCenter;

                Rhino.DocObjects.ObjRef objref = go.Object(i);
                // get selected surface object
                Rhino.DocObjects.RhinoObject obj = objref.Object();
                dynRef.Add(objref);
            }
            Point3d allCenter = centersAdd / centers.Count;

            //pick center
            GetPoint gp = new GetPoint();

            gp.SetCommandPrompt("Basepoint. Press Enter for automatic.");
            gp.AcceptNothing(true);
            var resgp = gp.Get();

            if (resgp == GetResult.Nothing)
            {
                scaleCenter = allCenter;
            }
            else
            {
                scaleCenter = gp.Point();
            }

            Rhino.Display.RhinoView view = gp.View();
            plane2D = view.ActiveViewport.ConstructionPlane();

            //Expansion factor
            GetPoint gp2 = new GetPoint();

            gp2.SetCommandPrompt("Scale factor or first reference point <" + factor + ">");
            gp2.DrawLineFromPoint(scaleCenter, true);
            gp2.AcceptNumber(true, true);
            GetResult gr = gp2.Get();



            if (gr == GetResult.Number)
            {
                factor = gp2.Number();
            }
            if (gr == GetResult.Point)
            {
                scaleRefPoint = gp2.Point();
                Line line1     = new Line(scaleCenter, scaleRefPoint);
                Guid tempLine  = doc.Objects.AddLine(line1);
                Guid tempPoint = doc.Objects.AddPoint(scaleRefPoint);
                if (scaleCenter == gp2.Point())
                {
                    return(Rhino.Commands.Result.Cancel);
                }
                GetPoint gp3 = new GetPoint();
                gp3.SetCommandPrompt("Secondt reference point");
                gp3.AddOptionList("ScaleDimension", dimensions, 0);
                gp3.DrawLineFromPoint(scaleCenter, true);
                gp3.DynamicDraw += RefObjDraw;

                while (true)
                {
                    GetResult res = gp3.Get();
                    if (res == GetResult.Option)
                    {
                        dimensionIndex = gp3.Option().CurrentListOptionIndex;
                        continue;
                    }
                    else if (res == GetResult.Point)
                    {
                        Point3d scaleRefPoint2 = gp3.Point();

                        factor = (scaleCenter.DistanceTo(scaleRefPoint2)) / (scaleCenter.DistanceTo(scaleRefPoint));
                        doc.Objects.Delete(tempLine, true);
                        doc.Objects.Delete(tempPoint, true);
                    }
                    break;
                }
            }
            RhinoApp.WriteLine("Scale factor: " + factor);

            //Compute translation

            //Translate 3d
            if (dimensionIndex == 0)
            {
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    var xform  = Transform.Scale(centers[i], factor);
                    var objref = go.Object(i);
                    var brep   = objref.Brep();
                    var index  = objref.GeometryComponentIndex.Index;
                    if (index > 0)
                    {
                        brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, doc.ModelAbsoluteTolerance, 0, true);
                        doc.Objects.Replace(objref.ObjectId, brep);
                    }
                    else
                    {
                        doc.Objects.Transform(go.Object(i), xform, true);
                    }
                }
            }
            //Translate 2d
            else if (dimensionIndex == 1)
            {
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    plane2D.Origin = centers[i];
                    var xform  = Rhino.Geometry.Transform.Scale(plane2D, factor, factor, 1);
                    var objref = go.Object(i);
                    var brep   = objref.Brep();
                    var index  = objref.GeometryComponentIndex.Index;
                    if (index > 0)
                    {
                        brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, doc.ModelAbsoluteTolerance, 0, true);
                        doc.Objects.Replace(objref.ObjectId, brep);
                    }
                    else
                    {
                        doc.Objects.Transform(go.Object(i), xform, true);
                    }
                }
            }
            //Translate 1d
            else if (dimensionIndex == 2)
            {
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    Vector3d vec        = (scaleRefPoint - scaleCenter);
                    Plane    scalePlane = new Plane(centers[i], vec);
                    var      xform      = Transform.Scale(scalePlane, 1, 1, factor);
                    var      objref     = go.Object(i);
                    var      brep       = objref.Brep();
                    var      index      = objref.GeometryComponentIndex.Index;
                    if (index > 0)
                    {
                        brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, doc.ModelAbsoluteTolerance, 0, true);
                        doc.Objects.Replace(objref.ObjectId, brep);
                    }
                    else
                    {
                        doc.Objects.Transform(go.Object(i), xform, true);
                    }
                }
            }

            centers        = new List <Point3d>();
            dimensionIndex = 0;
            plane2D        = new Plane();
            dynRef         = new List <Rhino.DocObjects.ObjRef>();

            doc.Views.Redraw();
            return(Result.Success);
        }
コード例 #54
0
        //Creates reinforcement objects and saves them into the selected point as userData
        public static Reinforcement[] CreateReinforcements(string mName, double diam)
        {
            RhinoDoc doc = RhinoDoc.ActiveDoc;

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

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject()
            {
                GeometryFilter              = geometryFilter,
                GroupSelect                 = true,
                SubObjectSelect             = false,
                DeselectAllBeforePostSelect = false
            };
            go.SetCommandPrompt("Pick all the points that you want to change to reinforcement.");
            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();
            }


            int layerIndex = GetOrCreateLayer(doc, "Reinforcement", Color.Black);

            if (layerIndex == 999)
            {
                return new Reinforcement[] {}
            }
            ;


            Reinforcement[] reinfList = { };
            //Create reinforcement objects for each selected points
            ObjRef[] objects = go.Objects();
            if (objects != null)
            {
                reinfList = CreateReinfObjs(doc, objects, layerIndex, mName, diam);
            }



            return(reinfList);
        }
コード例 #55
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            double tolerance = doc.ModelAbsoluteTolerance;

            List <Curve> icur = new List <Curve>();

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

            gcr.SetCommandPrompt("Select reference circles for drill. (No curves)");
            gcr.GeometryFilter              = Rhino.DocObjects.ObjectType.Curve;
            gcr.GroupSelect                 = true;
            gcr.SubObjectSelect             = true;
            gcr.DeselectAllBeforePostSelect = true;
            gcr.OneByOnePostSelect          = false;
            gcr.GetMultiple(1, 0);

            for (int ie = 0; ie < gcr.ObjectCount; ie++)
            {
                Rhino.DocObjects.ObjRef      objref = gcr.Object(ie);
                Rhino.DocObjects.RhinoObject obj    = objref.Object();
                if (obj == null)
                {
                    return(Result.Failure);
                }
                Curve refcr = objref.Curve();
                if (refcr == null)
                {
                    return(Result.Failure);
                }
                obj.Select(false);

                icur.Add(refcr);
            }

            while (true)
            {
                m_escape_key_pressed       = false;
                RhinoApp.EscapeKeyPressed += RhinoApp_EscapeKeyPressed;


                List <Curve> curveDrill = new List <Curve>();

                Point3d centerTop = new Point3d(0, 0, (headDrill + topDrill) * drillScale);
                Circle  circleTop = new Circle(centerTop, ancheadDrill / 2 * drillScale);
                Curve   curveTop  = circleTop.ToNurbsCurve();
                curveDrill.Add(curveTop);
                Point3d centerMid = new Point3d(0, 0, topDrill * drillScale);
                Circle  circleMid = new Circle(centerMid, drillScale / 2);
                Curve   curveMid  = circleMid.ToNurbsCurve();
                curveDrill.Add(curveMid);
                Circle circleBase = new Circle(drillScale / 2);
                Curve  curveBase  = circleBase.ToNurbsCurve();
                curveDrill.Add(curveBase);
                Point3d centerLow = new Point3d(0, 0, -midDrill * drillScale);
                Circle  circleLow = new Circle(centerLow, ancDrill / 2 * drillScale);
                Curve   curveLow  = circleLow.ToNurbsCurve();
                curveDrill.Add(curveLow);
                if (bottDrill != 0)
                {
                    Point3d centerBot = new Point3d(0, 0, (-midDrill - bottDrill) * drillScale);
                    Circle  circleBot = new Circle(centerBot, ancDrill / 2 * drillScale);
                    Curve   curveBot  = circleBot.ToNurbsCurve();
                    curveDrill.Add(curveBot);
                }


                Brep[] cylBrep1     = Brep.CreateFromLoft(curveDrill, Point3d.Unset, Point3d.Unset, LoftType.Straight, false);
                Brep[] cylBrep2     = Brep.CreateBooleanUnion(cylBrep1, tolerance);
                Brep   cylBrepFinal = cylBrep1[0];
                cylBrepFinal = cylBrepFinal.CapPlanarHoles(tolerance);


                string instDefCount = DateTime.Now.ToString("ddMMyyyyHHmmss");
                Brep[] brepArray    = new Brep[1] {
                    cylBrepFinal
                };
                var drillIndex = doc.InstanceDefinitions.Add("Drill" + instDefCount, "RefDrill 1mm", Point3d.Origin, brepArray);

                foreach (Curve c in icur)
                {
                    Circle circleDrill = new Circle();
                    c.TryGetCircle(out circleDrill, tolerance);

                    double   radiusDrill = circleDrill.Diameter;
                    Point3d  center      = circleDrill.Center;
                    Vector3d moveV       = new Vector3d(center);
                    Vector3d zaxis       = new Vector3d(0.0, 0.0, 1.0);
                    Plane    planeOr     = new Plane(center, zaxis);
                    Plane    planeNew    = circleDrill.Plane;
                    var      transform1  = Transform.Translation(moveV);
                    var      transform2  = Transform.Scale(center, radiusDrill);
                    var      transform3  = Transform.PlaneToPlane(planeOr, planeNew);

                    var stoneA = doc.Objects.AddInstanceObject(drillIndex, transform1);
                    var stoneB = doc.Objects.Transform(stoneA, transform2, true);
                    var stoneC = doc.Objects.Transform(stoneB, transform3, true);

                    ids.Add(stoneC);

                    doc.Views.Redraw();
                }


                GetOption go = new Rhino.Input.Custom.GetOption();
                go.SetCommandPrompt("Set drill parameters.");
                go.AcceptNothing(true);

                var drillHead    = new Rhino.Input.Custom.OptionDouble(headDrill);
                var drillAncHead = new Rhino.Input.Custom.OptionDouble(ancheadDrill);
                var drillTop     = new Rhino.Input.Custom.OptionDouble(topDrill);
                var drillMid     = new Rhino.Input.Custom.OptionDouble(midDrill);
                var drillAnc     = new Rhino.Input.Custom.OptionDouble(ancDrill);
                var drillBott    = new Rhino.Input.Custom.OptionDouble(bottDrill);
                var scaleDrill   = new Rhino.Input.Custom.OptionDouble(drillScale);
                go.AddOptionDouble("Top", ref drillHead);
                go.AddOptionDouble("TopAngle", ref drillAncHead);
                go.AddOptionDouble("Mid", ref drillTop);
                go.AddOptionDouble("Bottom", ref drillMid);
                go.AddOptionDouble("BottomAngle", ref drillAnc);
                go.AddOptionDouble("Tail", ref drillBott);
                go.AddOptionDouble("Scale", ref scaleDrill);


                GetResult res = go.Get();

                if (m_escape_key_pressed)
                {
                    break;
                }



                topDrill     = drillTop.CurrentValue;
                midDrill     = drillMid.CurrentValue;
                ancDrill     = drillAnc.CurrentValue;
                bottDrill    = drillBott.CurrentValue;
                drillScale   = scaleDrill.CurrentValue;
                headDrill    = drillHead.CurrentValue;
                ancheadDrill = drillAncHead.CurrentValue;


                if (res == GetResult.Nothing)
                {
                    break;
                }

                doc.Objects.Delete(ids, true);
            }
            RhinoApp.EscapeKeyPressed -= RhinoApp_EscapeKeyPressed;

            doc.Groups.Add(ids);

            return(Result.Success);
        }
コード例 #56
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;
    }
コード例 #57
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            int currIntOption = 0;
            var gi            = new GetOption();

            gi.SetCommandPrompt("Material Index");
            gi.AcceptNumber(true, true);
            var resgi = gi.Get();

            if (resgi == GetResult.Number)
            {
                currIntOption = Convert.ToInt32(gi.Number());
            }

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select objects to apply material");
            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.GetMultiple(1, 0);


            //Nothing to do - get out quick.
            if (go.ObjectCount == 0)
            {
                return(Result.Success);
            }

            var rm = FindMaterial(doc, matName[currIntOption]);

            if (null == rm)
            {
                //Didn't find the material - create one and carry on.

                //Create a basic material
                var custom = new Rhino.DocObjects.Material();
                custom.Name = matName[currIntOption];

                if (currIntOption == 13)
                {
                    custom.SetEnvironmentTexture(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/Free Jewels Rhino Plug-Ins/Dia3.jpg");
                }
                custom.CommitChanges();

                rm = RenderMaterial.CreateBasicMaterial(custom);
                rm.BeginChange(RenderContent.ChangeContexts.Program);
                rm.SetParameter("diffuse", System.Drawing.Color.Black);
                rm.SetParameter("reflectivity", 1.0);
                rm.SetParameter("reflectivity-color", System.Drawing.Color.FromArgb(r[currIntOption], g[currIntOption], b[currIntOption]));
                rm.SetParameter("transparency", fjMatTrans[currIntOption]);
                rm.SetParameter("shine", fjMatShine[currIntOption]);
                rm.SetParameter("polish-amount", fjMatShine[currIntOption]);
                rm.EndChange();

                var docMats = doc.RenderMaterials;

                docMats.Add(rm);
            }

            //Now we always have a material to assign, this part is easy
            for (int i = 0; i < go.ObjectCount; i++)
            {
                var obj = go.Object(i).Object();

                obj.RenderMaterial = rm;
                obj.CommitChanges();
            }

            doc.Views.Redraw();
            return(Result.Success);
        }
コード例 #58
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Mesh        meshSurf;
            List <Guid> ids       = new List <Guid>();
            double      tolerance = doc.ModelAbsoluteTolerance;
            const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Surface |
                                                               Rhino.DocObjects.ObjectType.PolysrfFilter |
                                                               Rhino.DocObjects.ObjectType.Mesh;

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

            gs.SetCommandPrompt("Surface to orient on");
            gs.GeometryFilter              = geometryFilter;
            gs.SubObjectSelect             = true;
            gs.DeselectAllBeforePostSelect = true;
            gs.OneByOnePostSelect          = true;
            gs.Get();
            if (gs.CommandResult() != Result.Success)
            {
                return(gs.CommandResult());
            }

            Rhino.DocObjects.ObjRef      objref = gs.Object(0);
            Rhino.DocObjects.RhinoObject obj    = objref.Object();
            if (obj == null)
            {
                return(Result.Failure);
            }

            brepSurf = objref.Brep();
            if (brepSurf == null)
            {
                meshSurf = objref.Mesh();
                brepSurf = Brep.CreateFromMesh(meshSurf, true);
            }
            if (brepSurf == null)
            {
                return(Result.Failure);
            }
            obj.Select(false);


            while (true)
            {
                w_key_pressed = false;
                s_key_pressed = false;
                a_key_pressed = false;
                d_key_pressed = false;

                m_escape_key_pressed = false;

                RhinoApp.EscapeKeyPressed += RhinoApp_EscapeKeyPressed;
                RhinoApp.KeyboardEvent    += OnRhinoKeyboardEvent;

                Point3d  pt0;
                GetPoint getPointAction = new GetPoint();
                getPointAction.SetCommandPrompt("Please select insert point(s) on surface.");
                getPointAction.Constrain(brepSurf, -1, -1, false);

                var stoneDiam  = new Rhino.Input.Custom.OptionDouble(diamStone);
                var stoneOff   = new Rhino.Input.Custom.OptionDouble(offSetStone);
                var boolOption = new Rhino.Input.Custom.OptionToggle(false, "Off", "On");
                var moveOption = new Rhino.Input.Custom.OptionToggle(false, "Off", "On");

                getPointAction.AddOptionDouble("StoneDiam", ref stoneDiam);
                getPointAction.AddOptionDouble("Offset", ref stoneOff);
                getPointAction.AddOptionToggle("Delete", ref boolOption);
                getPointAction.AddOptionToggle("Move", ref moveOption);
                getPointAction.DynamicDraw += RefCircleDraw;
                getPointAction.Tag          = obj;
                getPointAction.AcceptString(false);
                getPointAction.AcceptNothing(true);
                var res = getPointAction.Get();


                if (w_key_pressed || s_key_pressed)
                {
                    RhinoApp.KeyboardEvent -= OnRhinoKeyboardEvent;
                    w_key_pressed           = false;
                    s_key_pressed           = false;
                    stoneDiam.CurrentValue  = diamStone;
                }
                if (a_key_pressed || d_key_pressed)
                {
                    RhinoApp.KeyboardEvent -= OnRhinoKeyboardEvent;
                    a_key_pressed           = false;
                    d_key_pressed           = false;
                    stoneOff.CurrentValue   = offSetStone;
                }

                if (res == GetResult.Nothing)
                {
                    break;
                }
                if (m_escape_key_pressed)
                {
                    break;
                }

                diamStone   = stoneDiam.CurrentValue;
                offSetStone = stoneOff.CurrentValue;
                optionBool  = boolOption.CurrentValue;
                moveBool    = moveOption.CurrentValue;

                RhinoApp.KeyboardEvent -= OnRhinoKeyboardEvent;

                if (moveBool == true)
                {
                    RhinoApp.KeyboardEvent -= OnRhinoKeyboardEvent;
                    while (true)
                    {
                        GetObject gcd = new Rhino.Input.Custom.GetObject();
                        gcd.SetCommandPrompt("Select circle(s) to move. Press enter when done");
                        gcd.GeometryFilter              = Rhino.DocObjects.ObjectType.Curve;
                        gcd.SubObjectSelect             = false;
                        gcd.DeselectAllBeforePostSelect = true;
                        gcd.AcceptNothing(true);
                        if (gcd.Get() == GetResult.Nothing)
                        {
                            break;
                        }
                        gcd.Get();
                        Rhino.DocObjects.ObjRef      delobjref = gcd.Object(0);
                        Rhino.DocObjects.RhinoObject delobj    = delobjref.Object();
                        Curve  curveRadius  = delobjref.Curve();
                        Circle circleRadius = new Circle();
                        curveRadius.TryGetCircle(out circleRadius, tolerance);
                        diamStone = circleRadius.Diameter;
                        doc.Objects.Delete(delobj, true);
                        doc.Views.Redraw();

                        getPointAction.Get();
                        pt0 = getPointAction.Point();
                        Point3d        closestPoint;
                        ComponentIndex compIndex;
                        double         u, v;
                        Vector3d       vt1;

                        brepSurf.ClosestPoint(pt0, out closestPoint, out compIndex, out u, out v, 0.01, out vt1);
                        Plane  pl1  = new Plane(pt0, vt1);
                        Circle cr1  = new Circle(pl1, pt0, diamStone / 2);
                        var    crgu = doc.Objects.AddCircle(cr1);
                        ids.Add(crgu);
                        doc.Views.Redraw();
                    }
                    moveBool = false;
                }
                if (optionBool == true)
                {
                    RhinoApp.KeyboardEvent -= OnRhinoKeyboardEvent;
                    while (true)
                    {
                        GetObject gcd = new Rhino.Input.Custom.GetObject();
                        gcd.SetCommandPrompt("Select circle(s) to delete. Press enter when done");
                        gcd.GeometryFilter              = Rhino.DocObjects.ObjectType.Curve;
                        gcd.SubObjectSelect             = false;
                        gcd.DeselectAllBeforePostSelect = true;
                        gcd.AcceptNothing(true);
                        if (gcd.Get() == GetResult.Nothing)
                        {
                            break;
                        }
                        gcd.Get();
                        Rhino.DocObjects.ObjRef      delobjref = gcd.Object(0);
                        Rhino.DocObjects.RhinoObject delobj    = delobjref.Object();
                        Curve  curveRadius  = delobjref.Curve();
                        Circle circleRadius = new Circle();
                        curveRadius.TryGetCircle(out circleRadius, tolerance);
                        diamStone = circleRadius.Diameter;
                        doc.Objects.Delete(delobj, true);
                        doc.Views.Redraw();
                    }
                    optionBool = false;
                }

                if (res == GetResult.Point)
                {
                    pt0 = getPointAction.Point();
                    Point3d        closestPoint;
                    ComponentIndex compIndex;
                    double         u, v;
                    Vector3d       vt1;
                    brepSurf.ClosestPoint(pt0, out closestPoint, out compIndex, out u, out v, 0.01, out vt1);
                    Plane  pl1  = new Plane(pt0, vt1);
                    Circle cr1  = new Circle(pl1, pt0, diamStone / 2);
                    var    crgu = doc.Objects.AddCircle(cr1);
                    ids.Add(crgu);
                    doc.Views.Redraw();
                }
            }
            RhinoApp.KeyboardEvent    -= OnRhinoKeyboardEvent;
            RhinoApp.EscapeKeyPressed -= RhinoApp_EscapeKeyPressed;
            doc.Groups.Add(ids);
            return(Result.Success);
        }
コード例 #59
0
    public static Rhino.Commands.Result CreateBlock(Rhino.RhinoDoc doc)
    {
        // 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.
        const ObjectType forbidden_geometry_filter = Rhino.DocObjects.ObjectType.Light |
                                                     Rhino.DocObjects.ObjectType.Grip | Rhino.DocObjects.ObjectType.Phantom;
        const ObjectType 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.Failure);
    }
コード例 #60
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            double tolerance = doc.ModelAbsoluteTolerance;

            List <Curve> icur = new List <Curve>();

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

            gcr.SetCommandPrompt("Select reference circles for stones. (No curves)");
            gcr.GeometryFilter              = Rhino.DocObjects.ObjectType.Curve;
            gcr.GroupSelect                 = true;
            gcr.SubObjectSelect             = true;
            gcr.DeselectAllBeforePostSelect = true;
            gcr.OneByOnePostSelect          = false;
            gcr.GetMultiple(1, 0);

            for (int ie = 0; ie < gcr.ObjectCount; ie++)
            {
                Rhino.DocObjects.ObjRef      objref = gcr.Object(ie);
                Rhino.DocObjects.RhinoObject obj    = objref.Object();
                if (obj == null)
                {
                    return(Result.Failure);
                }
                Curve refcr = objref.Curve();
                if (refcr == null)
                {
                    return(Result.Failure);
                }
                obj.Select(false);

                icur.Add(refcr);
            }
            var rm = FindMaterial(doc, "Diamond");

            if (null == rm)
            {
                //Didn't find the material - create one and carry on.

                //Create a basic material
                var custom = new Rhino.DocObjects.Material();
                custom.Reflectivity = 1;
                custom.Transparency = 0.2;
                custom.SetEnvironmentTexture(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/Free Jewels Rhino Plug-Ins/Dia3.jpg");
                custom.Name = "Diamond";
                custom.CommitChanges();

                rm = RenderMaterial.CreateBasicMaterial(custom);

                var docMats = doc.RenderMaterials;

                //docMats.BeginChange(RenderContent.ChangeContexts.Program);
                docMats.Add(rm);
                //docMats.EndChange();
            }



            // Create Stone Mesh
            Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh();


            mesh.Vertices.Add(0.0, 0.0, -0.44);      //0

            mesh.Vertices.Add(0.0, 0.097, -0.363);   //1
            mesh.Vertices.Add(0.069, 0.069, -0.363); //2
            mesh.Vertices.Add(0.097, 0.0, -0.363);   //3

            mesh.Vertices.Add(0.0, 0.5, -0.013);     //4
            mesh.Vertices.Add(0.098, 0.49, -0.005);  //5
            mesh.Vertices.Add(0.191, 0.462, -0.013); //6
            mesh.Vertices.Add(0.278, 0.416, -0.005); //7
            mesh.Vertices.Add(0.354, 0.354, -0.013); //8
            mesh.Vertices.Add(0.416, 0.278, -0.005); //9
            mesh.Vertices.Add(0.462, 0.191, -0.013); //10
            mesh.Vertices.Add(0.49, 0.098, -0.005);  //11
            mesh.Vertices.Add(0.5, 0.0, -0.013);     //12

            mesh.Vertices.Add(0.0, 0.5, 0.013);      //13
            mesh.Vertices.Add(0.098, 0.49, 0.005);   //14
            mesh.Vertices.Add(0.191, 0.462, 0.013);  //15
            mesh.Vertices.Add(0.278, 0.416, 0.005);  //16
            mesh.Vertices.Add(0.354, 0.354, 0.013);  //17
            mesh.Vertices.Add(0.416, 0.278, 0.005);  //18
            mesh.Vertices.Add(0.462, 0.191, 0.013);  //19
            mesh.Vertices.Add(0.49, 0.098, 0.005);   //20
            mesh.Vertices.Add(0.5, 0.0, 0.013);      //21

            mesh.Vertices.Add(0.0, 0.372, 0.12);     //22
            mesh.Vertices.Add(0.263, 0.263, 0.12);   //23
            mesh.Vertices.Add(0.372, 0.0, 0.12);     //24
            mesh.Vertices.Add(0.263, -0.263, 0.12);  //25
            mesh.Vertices.Add(0.0, -0.372, 0.12);    //26
            mesh.Vertices.Add(-0.263, -0.263, 0.12); //27
            mesh.Vertices.Add(-0.372, 0.0, 0.12);    //28
            mesh.Vertices.Add(-0.263, 0.263, 0.12);  //29

            mesh.Vertices.Add(0.109, 0.263, 0.16);   //30
            mesh.Vertices.Add(0.263, 0.109, 0.16);   //31
            mesh.Vertices.Add(0.263, -0.109, 0.16);  //32
            mesh.Vertices.Add(0.109, -0.263, 0.16);  //33
            mesh.Vertices.Add(-0.109, -0.263, 0.16); //34
            mesh.Vertices.Add(-0.263, -0.109, 0.16); //35
            mesh.Vertices.Add(-0.263, 0.109, 0.16);  //36
            mesh.Vertices.Add(-0.109, 0.263, 0.16);  //37

            mesh.Vertices.Add(0.0, 0.0, 0.16);       //38

            mesh.Faces.AddFace(0, 1, 6, 2);
            mesh.Faces.AddFace(0, 2, 10, 3);

            mesh.Faces.AddFace(1, 4, 5, 6);
            mesh.Faces.AddFace(2, 6, 7, 8);
            mesh.Faces.AddFace(2, 8, 9, 10);
            mesh.Faces.AddFace(3, 10, 11, 12);

            mesh.Faces.AddFace(4, 13, 14, 5);
            mesh.Faces.AddFace(5, 14, 15, 6);
            mesh.Faces.AddFace(6, 15, 16, 7);
            mesh.Faces.AddFace(7, 16, 17, 8);
            mesh.Faces.AddFace(8, 17, 18, 9);
            mesh.Faces.AddFace(9, 18, 19, 10);
            mesh.Faces.AddFace(10, 19, 20, 11);
            mesh.Faces.AddFace(11, 20, 21, 12);

            mesh.Faces.AddFace(13, 22, 15, 14);
            mesh.Faces.AddFace(15, 23, 17, 16);
            mesh.Faces.AddFace(17, 23, 19, 18);
            mesh.Faces.AddFace(19, 24, 21, 20);

            mesh.Faces.AddFace(15, 22, 30, 23);
            mesh.Faces.AddFace(19, 23, 31, 24);

            mesh.Faces.AddFace(23, 30, 31);
            mesh.Faces.AddFace(24, 31, 32);

            mesh.Faces.AddFace(32, 31, 30, 38);

            mesh.Unweld(0.001, false);

            Mesh meshAll = new Mesh();

            for (int i = 0; i < 4; i++)
            {
                meshAll.Append(mesh);
                Point3d  center = new Point3d(0.0, 0.0, 0.0);
                Vector3d rotVec = new Vector3d(0.0, 0.0, 1.0);
                mesh.Rotate(Math.PI / 2, rotVec, center);
            }
            meshAll.Compact();
            meshAll.Weld(0.001);

            //Get object Guid to apply render material
            var         meshGuid = doc.Objects.AddMesh(meshAll);
            ObjRef      objre    = new ObjRef(meshGuid);
            RhinoObject obje     = objre.Object();

            obje.RenderMaterial = rm;
            obje.CommitChanges();

            //Make InstanceDefinition
            string instDefCount = DateTime.Now.ToString("ddMMyyyyHHmmss");

            var geometry = new System.Collections.Generic.List <Rhino.Geometry.GeometryBase>()
            {
                obje.Geometry
            };
            var attributes = new System.Collections.Generic.List <Rhino.DocObjects.ObjectAttributes>()
            {
                obje.Attributes
            };


            var stoneIndex = doc.InstanceDefinitions.Add("Stone" + instDefCount, "StoneMesh 1mm", Point3d.Origin, geometry, attributes);

            List <InstanceReferenceGeometry> meshPave = new List <InstanceReferenceGeometry>();


            foreach (Curve c in icur)
            {
                Circle circle1 = new Circle();
                c.TryGetCircle(out circle1, tolerance);
                double   radius     = circle1.Diameter;
                Point3d  center     = circle1.Center;
                Vector3d moveV      = new Vector3d(center);
                Vector3d zaxis      = new Vector3d(0.0, 0.0, 1.0);
                Plane    planeOr    = new Plane(center, zaxis);
                Plane    planeNew   = circle1.Plane;
                var      transform1 = Transform.Translation(moveV);
                var      transform2 = Transform.Scale(center, radius);
                var      transform3 = Transform.PlaneToPlane(planeOr, planeNew);

                var stoneA = doc.Objects.AddInstanceObject(stoneIndex, transform1);
                var stoneB = doc.Objects.Transform(stoneA, transform2, true);
                var stoneC = doc.Objects.Transform(stoneB, transform3, true);

                ids.Add(stoneC);
            }
            doc.Groups.Add(ids);
            doc.Objects.Delete(obje);
            doc.Views.Redraw();

            return(Result.Success);
        }