public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiApp      = commandData.Application;
            Document      currentDoc = uiApp.ActiveUIDocument.Document;
            UIDocument    uiDoc      = uiApp.ActiveUIDocument;
            View          av         = currentDoc.ActiveView;

            ViewFamilyType vft = GenerateViews.ViewTypeSetup(currentDoc);

            if (av.ViewType == ViewType.FloorPlan)
            {
                Selection sel = uiDoc.Selection;
                ICollection <ElementId> set = sel.GetElementIds();

                if (set.Count == 1)
                {
                    foreach (ElementId id in set)
                    {
                        Element e = currentDoc.GetElement(id);
                        Room    r = e as Room;
                        if (null != r)
                        {
                            BoundaryData b = new BoundaryData(r);
                            GenerateViews.GenViews(vft, av, r);
                        }
                        else
                        {
                            TaskDialog.Show("Error", "Please select a room.");
                        }
                    }
                }
                else
                {
                    TaskDialog.Show("Error", "Please select a room.");
                }
            }
            else
            {
                TaskDialog.Show("Error", "Active a plan view!");
            }
            return(Result.Succeeded);
        }
        public static void GenViews(ViewFamilyType vft, View av, Room r)
        {
            Document currentDoc = r.Document;

            foreach (ElementId vtd in ViewsToDelete(r))
            {
                if (currentDoc.GetElement(vtd).IsValidObject)
                {
                    currentDoc.Delete(vtd);
                }
            }

            BoundingBoxXYZ bbse = r.get_BoundingBox(null);
            double         yMin = bbse.Min.Z;
            double         yMax = bbse.Max.Z;

            BoundaryData BData = new BoundaryData(r);

            if (null != BData.Edges())
            {
                foreach (KeyValuePair <Line, XYZ> kvp in BData.Edges())
                {
                    XYZ start  = kvp.Key.GetEndPoint(0);
                    XYZ end    = kvp.Key.GetEndPoint(1);
                    XYZ vector = end - start;
                    XYZ midpt  = start + (0.5 * vector);

                    double xsize  = kvp.Key.Length;
                    double height = yMax - yMin;

                    double minx = midpt.X - (xsize / 2) - offset;
                    double maxx = midpt.X + (xsize / 2) + offset;
                    double miny = yMin - offset;
                    double maxy = yMax + offset;
                    double minz = midpt.Z - offset / 2;
                    double maxz = midpt.Z + offset / 2;

                    XYZ minbound = new XYZ(minx, miny, minz);
                    XYZ maxbound = new XYZ(maxx, maxy, maxz);

                    BoundingBoxXYZ sectionBox = new BoundingBoxXYZ();
                    sectionBox.Min = minbound;
                    sectionBox.Max = maxbound;

                    ElevationMarker em = ElevationMarker.CreateElevationMarker(currentDoc, vft.Id, midpt, 48);
                    ViewSection     vs = em.CreateElevation(currentDoc, av.Id, 1);
                    vs.CropBox = sectionBox;

                    XYZ    baseangle = XYZ.BasisY;
                    double rotation  = kvp.Value.AngleTo(baseangle);
                    if (kvp.Value.X > 0)
                    {
                        rotation *= -1;
                    }

                    string dir = Direction(rotation);

                    Line axisline = Line.CreateBound(midpt, new XYZ(midpt.X, midpt.Y, midpt.Z + 1));
                    em.Location.Rotate(axisline, rotation);

                    em.Location.Move(-kvp.Value * offset);

                    int  j         = 1;
                    bool iscreated = false;
                    while (iscreated == false)
                    {
                        string viewname = r.Name + " - " + dir + " " + j;
                        FilteredElementCollector vfilter = new FilteredElementCollector(currentDoc).OfClass(typeof(View));
                        View testname = vfilter.FirstOrDefault <Element>(a => a.Name.Equals(viewname)) as View;
                        if (testname == null)
                        {
                            vs.Name   = viewname;
                            iscreated = true;
                        }
                        else
                        {
                            j++;
                        }
                    }
                }
            }
        }