protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: complete command.
            MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance;

            if (p.if_painted_object_set_ == false)
            {
                RhinoApp.WriteLine("No mesh");
                return(Result.Failure);
            }
            Mesh my_mesh = p.painted_object_;

            GetObject gbrep = new GetObject();

            gbrep.SetCommandPrompt("get the brep");
            gbrep.GeometryFilter  = Rhino.DocObjects.ObjectType.Brep;
            gbrep.SubObjectSelect = false;
            gbrep.Get();
            if (gbrep.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gbrep.CommandResult());
            }
            ObjRef      my_objref = gbrep.Object(0);
            RhinoObject my_obj    = my_objref.Object();

            if (my_obj == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            Brep brep = my_objref.Brep();

            if (brep == null)
            {
                return(Result.Failure);
            }
            my_obj.Select(false);

            int brep_number = 0;

            for (int i = 0; i < p.my_objects_list.Count; i++)
            {
                Brep an_object = p.my_objects_list[i];
                if (My_object_functions.GetComponentID(brep) == My_object_functions.GetComponentID(an_object))
                {
                    brep_number = i;
                    break;
                }
            }

            Point3d  position         = My_object_functions.GetPosition(brep);
            Vector3d normal_direction = My_object_functions.GetZ(brep);
            Plane    plane            = new Plane(position, normal_direction);

            /*
             * GetPoint gp = new GetPoint();
             * gp.Constrain(plane, false);
             * gp.Get();
             * if (gp.CommandResult() != Result.Success)
             *  return gp.CommandResult();
             * var start_point = gp.Point();
             * if (start_point == Point3d.Unset)
             *  return Result.Failure;
             */

            Vector3d horizontal_direction = My_object_functions.GetY(brep);
            Point3d  start_point          = position + 10 * horizontal_direction;

            GetRotationAngle gr = new GetRotationAngle(brep, my_mesh, start_point);

            gr.SetCommandPrompt("Get the rotation angle");
            gr.Constrain(plane, false);
            gr.Get();
            if (gr.CommandResult() != Result.Success)
            {
                return(gr.CommandResult());
            }

            Point3d end_point = gr.Point();
            Brep    new_brep  = GetRotationAngle.RotateBrep(brep, my_mesh, end_point, start_point);

            ObjectAttributes path_attributes = new ObjectAttributes();

            path_attributes.ObjectColor      = Color.Yellow;
            path_attributes.ColorSource      = ObjectColorSource.ColorFromObject;
            path_attributes.PlotWeightSource = ObjectPlotWeightSource.PlotWeightFromObject;
            path_attributes.PlotWeight       = 2.0;

            ObjectAttributes my_attributes = new ObjectAttributes();

            my_attributes.ObjectColor = My_object_functions.GetColor(new_brep);
            my_attributes.ColorSource = ObjectColorSource.ColorFromObject;

            int new_pin_number = My_object_functions.GetPinQuantity(new_brep);
            List <NurbsCurve> new_path_list = new List <NurbsCurve>();

            for (int i = 0; i < new_pin_number; i++)
            {
                Guid      pin_id       = My_object_functions.GetPinGuid(new_brep, i);
                Point3d   pin_position = My_object_functions.GetPinPosition(new_brep, i);
                MeshPoint pin_on_mesh  = my_mesh.ClosestMeshPoint(pin_position, 0);
                new_path_list = p.graph.DijkstraPath_Change(pin_id, pin_on_mesh);
            }

            IEnumerable <RhinoObject> path_objref = doc.Objects.GetObjectList(ObjectType.Curve);

            foreach (RhinoObject path in path_objref)
            {
                doc.Objects.Delete(path, true);
            }

            for (int i = 0; i < new_path_list.Count; i++)
            {
                Guid path_id = new_path_list[i].UserDictionary.GetGuid("PathID");
                path_attributes.ObjectId = path_id;
                doc.Objects.AddCurve(new_path_list[i], path_attributes);
            }

            doc.Objects.Delete(my_objref, true);
            doc.Objects.AddBrep(new_brep, my_attributes);
            p.my_objects_list[brep_number] = new_brep;
            doc.Views.Redraw();


            return(Result.Success);
        }