DynamicDraw not showing up


I am building a command to raise/lower vertices of a mesh on every mouse click. I would like to visualize the region which includes the selected vertices using a circle. I thought DynamicDraw would do this by actively drawing a circle as I hover over various regions, but for some reason it doesn’t work. Does anyone know what I’m doing wrong in this code?

Thank you in advance!


 protected override Result RunCommand(RhinoDoc doc, RunMode mode)
            var go = new GetObject();
            var brush = new GetNumber();
            var height = new GetNumber();
            bool pushUp = true;
            go.SetCommandPrompt("Select mesh to modify");
            go.GeometryFilter = ObjectType.Mesh;
            RhinoGet.GetBool("Push up or push down the vertices?", true, "down", "up", ref pushUp);         
            if (go.Result() != GetResult.Object)
                return Result.Cancel;

            brush.SetCommandPrompt("Set brush radius");
            if (brush.CommandResult() != Result.Success)
                return Result.Cancel;

            height.SetCommandPrompt("Set movement height");
            if (height.CommandResult() != Result.Success)
                return Result.Cancel;
            double radius = brush.Number();
            double myHeight = height.Number();

            var rhino_object = go.Object(0).Object();
            if (!(rhino_object is MeshObject mesh_object))
                return Result.Cancel;

            Mesh[] m = mesh_object.GetMeshes(MeshType.Any);
            Mesh myMesh = new Mesh();
            Point3d[] verts = myMesh.Vertices.ToPoint3dArray();
            while (true)
                var gp = new GetPoint();
                gp.DynamicDraw += (sender, e) => e.Display.DrawCircle(new Circle(e.CurrentPoint, radius), Color.Red);

                if (gp.CommandResult() != Result.Success)
                    return gp.CommandResult();
                Point3d currentPt = gp.Point();

                Sphere myActiveSphere = new Sphere(currentPt, radius);
                Brep sBrep = myActiveSphere.ToBrep();
                Dictionary<int, Point3d> selectedPts = new Dictionary<int, Point3d>();
                for (int i = 0; i < verts.Length; i++)
                    if (sBrep.IsPointInside(verts[i], 0.01, true))
                        if (pushUp)
                            verts[i].Z += myHeight;
                            verts[i].Z -= myHeight;
                        selectedPts.Add(i, verts[i]);

                foreach (var key in selectedPts.Keys)
                    Point3d pt = selectedPts[key];
                    myMesh.Vertices.SetVertex(key, pt);
                Guid mesh_guid = rhino_object.Id;
                doc.Objects.Replace(mesh_guid, myMesh); 

I think you need to change the order of Get() and DynamicDraw(). First register the event callback, the ask the user for the point.

Yes, that worked! Thank you very much.