コード例 #1
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var go = new Rhino.Input.Custom.GetObject();

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

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

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

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

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

            return(Result.Success);
        }
コード例 #2
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);
    }
コード例 #3
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Select objects to define block
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select surface or polysurface to box morph");
            go.GeometryFilter  = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.Brep;
            go.SubObjectSelect = false;
            go.Get();
            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }

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

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

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

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

            BoxMorph box_morph = new BoxMorph(box, corners);

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

            return(Result.Success);
        }
コード例 #4
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);
    }
コード例 #5
0
        protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
        {
            Mesh meshObj;
            Point3d pointObj = new Point3d(0.0,0.0,0.0);

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

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

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

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

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

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

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

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

            double p  = Intersection.MeshRay(meshObj, rayObj);
            string a = string.Format("mesh ray gives {0:0.00}",p);
            doc.Objects.AddPoint(rayObj.PointAt(p));
            RhinoApp.WriteLine(a);
            return Rhino.Commands.Result.Success;
        }
コード例 #6
0
ファイル: Get_mesh.cs プロジェクト: TianyiWang3259/Overpaint
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: complete command.
            RhinoApp.WriteLine("The {0} command is under construction.", EnglishName);

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

            MeshTextureCoordinateList texture_list = mesh.TextureCoordinates;

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

            p.painted_object_        = mesh;
            p.if_painted_object_set_ = true;
            mesh.UserDictionary.Set("name", "myMesh");
            mesh.UserDictionary.Set("isMovable", false);
            p.graph = new DijkstraGraph(10);
            RhinoApp.WriteLine("Mesh Got");
            return(Result.Success);
        }
コード例 #7
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);
    }
コード例 #8
0
    public static Rhino.Commands.Result ExtrudeBrepFace(Rhino.RhinoDoc doc)
    {
        Rhino.Input.Custom.GetObject go0 = new Rhino.Input.Custom.GetObject();
        go0.SetCommandPrompt("Select surface to extrude");
        go0.GeometryFilter  = Rhino.DocObjects.ObjectType.Surface;
        go0.SubObjectSelect = true;
        go0.Get();
        if (go0.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go0.CommandResult());
        }

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

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

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

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

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

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

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

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

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

            doc.Views.Redraw();

            return(Rhino.Commands.Result.Success);
        }
コード例 #11
0
    public static Rhino.Commands.Result ExtrudeBrepFace(Rhino.RhinoDoc doc)
    {
        Rhino.Input.Custom.GetObject go0 = new Rhino.Input.Custom.GetObject();
        go0.SetCommandPrompt("Select surface to extrude");
        go0.GeometryFilter = Rhino.DocObjects.ObjectType.Surface;
        go0.SubObjectSelect = true;
        go0.Get();
        if (go0.CommandResult() != Rhino.Commands.Result.Success)
          return go0.CommandResult();

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

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

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

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

        return Rhino.Commands.Result.Success;
    }
コード例 #12
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;
  }
コード例 #13
0
    public static Rhino.Commands.Result OrientOnSrf(Rhino.RhinoDoc doc)
    {
        // Select objects to orient
        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select objects to orient");
        go.SubObjectSelect = false;
        go.GroupSelect     = true;
        go.GetMultiple(1, 0);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

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

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

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

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

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

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

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

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

                doc.Views.Redraw();
                rc = Rhino.Commands.Result.Success;
            }
        }
        return(rc);
    }
コード例 #14
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select sphere");
            go.GeometryFilter          = Rhino.DocObjects.ObjectType.Surface;
            go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedSurface;
            go.SubObjectSelect         = false;
            go.Get();
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

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

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

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

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

            sphere.Radius = gn.Number();

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

            sphere.EquitorialPlane = plane;

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

            return(Result.Success);
        }
コード例 #15
0
 /// <summary>
 /// Select object for which an area value can be calculated
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void GetObjectForArea(object sender, EventArgs e)
 {
   using (Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject())
   {
     go.SetCommandPrompt(Rhino.UI.Localization.LocalizeString("Select closed curve, hatch, surface, or mesh", 359));
     go.AcceptNothing(true);
     go.SubObjectSelect = false;
     go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve | Rhino.DocObjects.ObjectType.Hatch | Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.Brep | Rhino.DocObjects.ObjectType.Mesh;
     go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve;
     go.DisablePreSelect();
     go.Get();
     if (go.CommandResult() == Rhino.Commands.Result.Success)
     {
       Rhino.DocObjects.ObjRef objref = go.Object(0);
       if (objref != null)
       {
         SelectedObjectId = objref.ObjectId;
         objref.Dispose();
       }
     }
   }
 }
コード例 #16
0
  public static Rhino.Commands.Result OrientOnSrf(Rhino.RhinoDoc doc)
  {
    // Select objects to orient
    Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
    go.SetCommandPrompt("Select objects to orient");
    go.SubObjectSelect = false;
    go.GroupSelect = true;
    go.GetMultiple(1, 0);
    if (go.CommandResult() != Rhino.Commands.Result.Success)
      return go.CommandResult();

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

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

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

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

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

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

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

        doc.Views.Redraw();
        rc = Rhino.Commands.Result.Success;
      }
    }
    return rc;
  }
コード例 #17
0
ファイル: Text.cs プロジェクト: panhao4812/ClassLibrary1
        private void RunScript(object x, object y, ref object A)
        {
            try
            {
                if (sign)
                {
                    sign = false;
                    Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
                    go.Get();
                    Rhino.DocObjects.ObjRef or = go.Object(0);
                    ID = or.ObjectId;

                    Rhino.DocObjects.RhinoObject obj = RhinoDoc.ActiveDoc.Objects.Find(ID);
                    TextObject T = (TextObject)obj;
                    TextEntity t = T.TextGeometry;
                    m_tags = new Rhino.Display.Text3d(t.Text, t.Plane, t.TextHeight + 1);
                }
            }
            catch (Exception ex) { Print(ex.ToString()); }
        }
コード例 #18
0
ファイル: rhinosdkget.cs プロジェクト: austinlaw/rhinocommon
 static Commands.Result GetGripsHelper(out Rhino.DocObjects.GripObject[] grips, string prompt, bool singleGrip)
 {
   grips = null;
   using (Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject())
   {
     if (!string.IsNullOrEmpty(prompt))
       go.SetCommandPrompt(prompt);
     go.SubObjectSelect = false;
     go.GeometryFilter = Rhino.DocObjects.ObjectType.Grip;
     go.GroupSelect = false;
     go.AcceptNothing(true);
     if (singleGrip)
       go.Get();
     else
       go.GetMultiple(1, 0);
     Commands.Result rc = go.CommandResult();
     if (Rhino.Commands.Result.Success == rc)
     {
       Rhino.DocObjects.ObjRef[] objrefs = go.Objects();
       if (null != objrefs && objrefs.Length > 0)
       {
         System.Collections.Generic.List<Rhino.DocObjects.GripObject> griplist = new System.Collections.Generic.List<Rhino.DocObjects.GripObject>();
         for (int i = 0; i < objrefs.Length; i++)
         {
           Rhino.DocObjects.ObjRef ob = objrefs[i];
           if (null == ob)
             continue;
           Rhino.DocObjects.GripObject grip = ob.Object() as Rhino.DocObjects.GripObject;
           if (grip != null)
             griplist.Add(grip);
           ob.Dispose();
         }
         if (griplist.Count > 0)
           grips = griplist.ToArray();
       }
     }
     return rc;
   }
 }
コード例 #19
0
ファイル: rhinosdkget.cs プロジェクト: austinlaw/rhinocommon
 public static Commands.Result GetOneObject(string prompt, bool acceptNothing, Rhino.DocObjects.ObjectType filter, out Rhino.DocObjects.ObjRef rhObject)
 {
   rhObject = null;
   Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
   go.SetCommandPrompt(prompt);
   go.AcceptNothing(acceptNothing);
   go.GeometryFilter = filter;
   go.Get();
   Commands.Result rc = go.CommandResult();
   if (rc == Rhino.Commands.Result.Success && go.ObjectCount > 0)
   {
     rhObject = go.Object(0);
   }
   go.Dispose();
   return rc;
 }
コード例 #20
0
 /// <summary>
 /// Select an object which will be used for the user text list
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void GetObjectForUserText(object sender, EventArgs e)
 {
   using (Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject())
   {
     go.SetCommandPrompt(Rhino.UI.Localization.LocalizeString("Select object", 361));
     go.AcceptNothing(true);
     go.DisablePreSelect();
     go.Get();
     if (go.CommandResult() == Rhino.Commands.Result.Success)
     {
       Rhino.DocObjects.ObjRef objref = go.Object(0);
       if (objref != null)
       {
         SelectedObjectId = objref.ObjectId;
         SetupSelectObjectPanelHelper(TextFieldType.usertext, false);
         objref.Dispose();
       }
     }
   }
 }
コード例 #21
0
 /// <summary>
 /// Select an object for object name display
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void GetObjectForName(object sender, EventArgs e)
 {
   using (Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject())
   {
     go.SetCommandPrompt(Rhino.UI.Localization.LocalizeString("Select object", 384));
     go.AcceptNothing(true);
     go.SubObjectSelect = false;
     go.DisablePreSelect();
     go.Get();
     if (go.CommandResult() == Rhino.Commands.Result.Success)
     {
       Rhino.DocObjects.ObjRef objref = go.Object(0);
       if (objref != null)
       {
         SelectedObjectId = objref.ObjectId;
         objref.Dispose();
       }
     }
   }
 }
コード例 #22
0
ファイル: print.cs プロジェクト: pragun/rhino5plugin
        protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
        {
            pluginObj = ((nishanchiPlugin)this.PlugIn);
            RhinoView viewObj = doc.Views.ActiveView;
            RhinoViewport viewPortObj = viewObj.ActiveViewport;
            Vector3d originalCameraVector = viewPortObj.CameraDirection;
            Point3d originalCameraLocation = viewPortObj.CameraLocation;
            Mesh meshObj;

            Boolean logging = false;
            StreamWriter logWriter = null;

            String reportString;
            String logString;
            String printCommandStr;

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

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

            connectKbEvt();

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

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

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

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

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

            Boolean retval;

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

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

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

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

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

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

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

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

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

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

            running = false;

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

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

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

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

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

                //Rhino.DocObjects.ObjRef location;

                string type = "custom";

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                            m_source_conduit.SetSource(rhObj);
                        }

                        doc.Views.Redraw();
                        return Result.Success;
                    }
                    else return Result.Cancel;
                } while (true);
            }
コード例 #24
0
    public static Result ExtendSurface(RhinoDoc doc)
    {
        var go = new Rhino.Input.Custom.GetObject();

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

        var surface = obj_ref.Surface();

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

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

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

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

        var curve = obj_ref.Curve();

        var trim = obj_ref.Trim();

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

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

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

        if (extended_surface != null)
        {
            var mybrep = Brep.CreateFromSurface(extended_surface);
            doc.Objects.Replace(obj_ref.ObjectId, mybrep);
            doc.Views.Redraw();
        }
        return(Result.Success);
    }