protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Point3d base_pt;
            var     rc = RhinoGet.GetPoint("Start of line", false, out base_pt);

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

            var gp = new GetPoint();

            gp.SetCommandPrompt("End of line");
            gp.SetBasePoint(base_pt, true);
            gp.DrawLineFromPoint(base_pt, true);
            gp.DynamicDraw += gp_DynamicDraw;
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            var end_pt = gp.Point();
            var vector = end_pt - base_pt;

            if (vector.Length > doc.ModelAbsoluteTolerance)
            {
                var line = new Line(base_pt, end_pt);
                doc.Objects.AddLine(line);
                doc.Views.Redraw();
            }

            return(Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Point3d basePt;
            Result  rc = RhinoGet.GetPoint("Start of line", false, out basePt);

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

            GetPoint gp = new GetPoint();

            gp.SetCommandPrompt("End of line");
            gp.SetBasePoint(basePt, true);
            gp.DrawLineFromPoint(basePt, true);
            gp.DynamicDraw += new EventHandler <GetPointDrawEventArgs>(gp_DynamicDraw);
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            Point3d endPt = gp.Point();

            Rhino.Geometry.Vector3d vector = endPt - basePt;
            if (vector.Length > doc.ModelAbsoluteTolerance)
            {
                Line line = new Line(basePt, endPt);
                doc.Objects.AddLine(line);
                doc.Views.Redraw();
            }

            return(Result.Success);
        }
        protected void PickFunction()
        {
            Point3d point;

            if (Rhino.Commands.Result.Success == RhinoGet.GetPoint("Location for new point", false, out point))
            {
                MessageBox.Show(point.ToString(), Title, MessageBoxButtons.OK);
            }
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            ObjRef objref;
            var    rc = RhinoGet.GetOneObject("Select object to move", false, ObjectType.AnyObject, out objref);

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

            Point3d first_point;

            rc = RhinoGet.GetPoint("Point to move from", false, out first_point);
            if (rc != Result.Success)
            {
                return(rc);
            }

            var gp = new GetPoint();

            gp.SetCommandPrompt("Point to move to");
            gp.SetBasePoint(first_point, true);
            gp.DrawLineFromPoint(first_point, true);
            gp.Get();
            rc = gp.CommandResult();
            if (rc != Result.Success)
            {
                return(rc);
            }

            var second_point = gp.Point();

            var dir = second_point - first_point;

            if (dir.Length > RhinoMath.ZeroTolerance)
            {
                var xform = Transform.Translation(dir);
                doc.Objects.Transform(objref, xform, true);
                doc.Views.Redraw();
            }

            return(rc);
        }
Exemple #5
0
    public static Result OffsetCurve(RhinoDoc doc)
    {
        ObjRef obj_ref;
        var    rs = RhinoGet.GetOneObject(
            "Select Curve", false, ObjectType.Curve, out obj_ref);

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

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

        Point3d point;

        rs = RhinoGet.GetPoint("Select Side", false, out point);
        if (rs != Result.Success)
        {
            return(rs);
        }
        if (point == Point3d.Unset)
        {
            return(Result.Nothing);
        }

        var curves = curve.Offset(point, Vector3d.ZAxis, 1.0,
                                  doc.ModelAbsoluteTolerance, CurveOffsetCornerStyle.None);

        foreach (var offset_curve in curves)
        {
            doc.Objects.AddCurve(offset_curve);
        }

        doc.Views.Redraw();
        return(Result.Success);
    }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Select objects to define block
            var go = new 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 = ObjectType.Light | ObjectType.Grip | ObjectType.Phantom;
            var geometry_filter           = forbidden_geometry_filter ^ ObjectType.AnyObject;

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

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

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

            // Block definition name
            string idef_name = "";

            rc = RhinoGet.GetString("Block definition name", false, ref idef_name);
            if (rc != Result.Success)
            {
                return(rc);
            }

            // Validate block name
            idef_name = idef_name.Trim();
            if (string.IsNullOrEmpty(idef_name))
            {
                return(Result.Nothing);
            }

            // See if block name already exists
            InstanceDefinition existing_idef = doc.InstanceDefinitions.Find(idef_name);

            if (existing_idef != null)
            {
                RhinoApp.WriteLine("Block definition {0} already exists", idef_name);
                return(Result.Nothing);
            }

            // Gather all of the selected objects
            var geometry   = new List <GeometryBase>();
            var attributes = new List <ObjectAttributes>();

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

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

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

            return(Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // mimic the functionality of the contour command using a background threads
            // The tricky parts to the contour command are that it dynamically adds
            // sections as they are found
            const ObjectType filter = ObjectType.Brep | ObjectType.Extrusion | ObjectType.Mesh;

            ObjRef[] objrefs;
            var      rc = RhinoGet.GetMultipleObjects("Select objects for contours", false, filter, out objrefs);

            if (rc != Result.Success)
            {
                return(rc);
            }
            if (objrefs == null || objrefs.Length < 1)
            {
                return(Result.Failure);
            }

            Point3d base_point;

            rc = RhinoGet.GetPoint("Contour plane base point", false, out base_point);
            if (rc != Result.Success)
            {
                return(rc);
            }
            var gp = new Rhino.Input.Custom.GetPoint();

            gp.SetCommandPrompt("Direction perpendicular to contour planes");
            gp.DrawLineFromPoint(base_point, false);
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }
            Point3d end_point = gp.Point();

            double interval = 1;

            rc = RhinoGet.GetNumber("Distance between contours", true, ref interval, 0.001, 10000);
            if (rc != Result.Success)
            {
                return(rc);
            }

            // figure out the combined bounding box of all the selected geometry
            BoundingBox bounds     = BoundingBox.Unset;
            var         geometries = new List <GeometryBase>();

            foreach (var objref in objrefs)
            {
                var geometry  = objref.Geometry();
                var extrusion = geometry as Extrusion;
                if (extrusion != null)
                {
                    geometry = objref.Brep();
                }
                geometries.Add(geometry);
                var bbox = geometry.GetBoundingBox(false);
                bounds.Union(bbox);
            }

            Vector3d normal = end_point - base_point;

            normal.Unitize();
            var    curplane = new Plane(base_point, normal);
            double min_t, max_t;

            if (!curplane.DistanceTo(bounds, out min_t, out max_t))
            {
                return(Result.Failure);
            }

            min_t -= interval;
            max_t += interval;
            min_t  = Math.Floor(min_t / interval);
            max_t  = Math.Ceiling(max_t / interval);
            double tolerance = doc.ModelAbsoluteTolerance;

            var tasks = new List <Task <Curve[]> >();
            var gc    = new Rhino.Input.Custom.GetCancel();

            for (double t = min_t; t <= max_t; t += 1.0)
            {
                double offset = t * interval;
                var    point  = base_point + normal * offset;
                var    plane  = new Plane(point, normal);
                foreach (var geom in geometries)
                {
                    var geom1 = geom;
                    var task  = Task.Run(() => Section(plane, geom1, tolerance), gc.Token);
                    tasks.Add(task);
                }
            }
            gc.TaskCompleted += OnTaskCompleted;
            rc = gc.WaitAll(tasks, doc);
            return(rc);
        }
Exemple #8
0
 public static Result GetStartPosition()
 {
     return(RhinoGet.GetPoint("Please set a start position", true, out UserInput._startPos));
 }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            const ObjectType filter = ObjectType.Brep | ObjectType.Extrusion | ObjectType.Mesh;
            var rc = RhinoGet.GetMultipleObjects("Select objects to contour", false, filter, out var objrefs);

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

            if (objrefs == null || objrefs.Length < 1)
            {
                return(Result.Failure);
            }

            rc = RhinoGet.GetPoint("Contour plane base point", false, out var base_point);
            if (rc != Result.Success)
            {
                return(rc);
            }

            var gp = new Rhino.Input.Custom.GetPoint();

            gp.SetCommandPrompt("Direction perpendicular to contour planes");
            gp.DrawLineFromPoint(base_point, false);
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            var end_point = gp.Point();

            var interval = 1.0;

            rc = RhinoGet.GetNumber("Distance between contours", true, ref interval, 0.001, 10000);
            if (rc != Result.Success)
            {
                return(rc);
            }

            var bounds     = BoundingBox.Unset;
            var geometries = new List <GeometryBase>();

            foreach (var objref in objrefs)
            {
                var geometry = objref.Geometry();
                if (geometry is Extrusion)
                {
                    geometry = objref.Brep();
                }
                geometries.Add(geometry);
                var bbox = geometry.GetBoundingBox(false);
                bounds.Union(bbox);
            }

            var normal = end_point - base_point;

            normal.Unitize();
            var curplane = new Plane(base_point, normal);

            if (!curplane.DistanceTo(bounds, out var min_t, out var max_t))
            {
                return(Result.Failure);
            }

            min_t -= interval;
            max_t += interval;
            min_t  = Math.Floor(min_t / interval);
            max_t  = Math.Ceiling(max_t / interval);
            var tolerance = doc.ModelAbsoluteTolerance;

            var tasks = new List <Task <Curve[]> >();
            var gc    = new Rhino.Input.Custom.GetCancel();

            for (var t = min_t; t <= max_t; t += 1.0)
            {
                var offset = t * interval;
                var point  = base_point + normal * offset;
                var plane  = new Plane(point, normal);
                foreach (var geom in geometries)
                {
                    var geom1 = geom;
                    var task  = Task.Run(() => Section(plane, geom1, tolerance), gc.Token);
                    tasks.Add(task);
                }
            }
            gc.TaskCompleted += OnTaskCompleted;
            rc = gc.WaitAll(tasks, doc);
            return(rc);
        }