SheetDescription() публичный статический Метод

Return a string describing the given sheet: sheet number and name.
public static SheetDescription ( Element e ) : string
e Element
Результат string
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            //IWin32Window revit_window
            //  = new JtWindowHandle(
            //    ComponentManager.ApplicationWindow ); // pre-2020

            IWin32Window revit_window
                = new JtWindowHandle(uiapp.MainWindowHandle); // 2020

            if (null == doc)
            {
                Util.ErrorMsg("Please run this command in a valid"
                              + " Revit project document.");
                return(Result.Failed);
            }

            // Interactive sheet selection.

            FrmSelectSheets form = new FrmSelectSheets(doc);

            if (DialogResult.OK == form.ShowDialog(
                    revit_window))
            {
                List <ViewSheet> sheets
                    = form.GetSelectedSheets();

                int n = sheets.Count;

                string caption = Util.PluralString(
                    n, "Sheet") + " Selected";

                string msg = string.Join(", ",
                                         sheets.Select <Element, string>(
                                             e => Util.SheetDescription(e))) + ".";

                // Determine all floor plan views displayed
                // in the selected sheets.

                Dictionary <View, int> views
                    = new Dictionary <View, int>(
                          new ElementEqualityComparer());

                int nFloorPlans = 0;

                foreach (ViewSheet sheet in sheets)
                {
                    foreach (View v in sheet.GetAllPlacedViews()
                             .Select <ElementId, View>(id =>
                                                       doc.GetElement(id) as View))
                    {
                        if (!views.ContainsKey(v))
                        {
                            if (IsFloorPlan(v))
                            {
                                ++nFloorPlans;
                            }
                            views.Add(v, 0);
                        }
                        ++views[v];
                    }
                }

                msg += (1 == n)
          ? "\nIt contains"
          : "\nThey contain";

                n = views.Count;

                msg += string.Format(
                    " {0} including {1}: ",
                    Util.PluralString(n, "view"),
                    Util.PluralString(nFloorPlans,
                                      "floor plan"));

                msg += string.Join(", ",
                                   views.Keys.Select <Element, string>(
                                       e => e.Name)) + ".";

                Util.InfoMsg2(caption, msg, false);

                // Determine all categories occurring
                // in the views displayed by the sheets.

                List <Category> categories
                    = new List <Category>(
                          new CategoryCollector(views.Keys).Keys);

                // Sort categories alphabetically by name
                // to display them in selection form.

                categories.Sort(
                    delegate(Category c1, Category c2)
                {
                    return(string.Compare(c1.Name, c2.Name));
                });

                // Interactive category selection.

                FrmSelectCategories form2
                    = new FrmSelectCategories(categories);

                if (DialogResult.OK == form2.ShowDialog(
                        revit_window))
                {
                    categories = form2.GetSelectedCategories();

                    n = categories.Count;

                    caption = Util.PluralString(n, "Category")
                              + " Selected";

                    msg = string.Join(", ",
                                      categories.Select <Category, string>(
                                          e => e.Name)) + ".";

                    Util.InfoMsg2(caption, msg, false);

                    // Convert category list to a dictionary for
                    // more effective repeated lookup.
                    //
                    //Dictionary<ElementId, Category> catLookup =
                    //  categories.ToDictionary<Category, ElementId>(
                    //    c => c.Id );
                    //
                    // No, much better: set up a reusable element
                    // filter for the categories of interest:

                    ElementFilter categoryFilter
                        = new LogicalOrFilter(categories
                                              .Select <Category, ElementCategoryFilter>(
                                                  c => new ElementCategoryFilter(c.Id))
                                              .ToList <ElementFilter>());

                    // Instantiate a container for all
                    // cloud data repository content.

                    SheetModelCollections modelCollections
                        = new SheetModelCollections(
                              DbUpload.GetProjectInfo(doc).Id);

                    foreach (ViewSheet sheet in sheets)
                    {
                        // Define preview form caption.

                        caption = "Sheet and Viewport Loops - "
                                  + Util.SheetDescription(sheet);

                        // This is currently not used for anything.

                        ListSheetAndViewTransforms(sheet);

                        // Determine the polygon loops representing
                        // the size and location of given sheet and
                        // the viewports it contains.

                        JtLoops sheetViewportLoops
                            = GetSheetViewportLoops(
                                  modelCollections, sheet);

                        // Determine graphics for family instances,
                        // their symbols and other BIM parts.

                        GetBimGraphics(modelCollections,
                                       sheet, categoryFilter);

                        // Display sheet and viewports with the
                        // geometry retrieved in a temporary GeoSnoop
                        // form generated on the fly for debugging
                        // purposes.

                        Bitmap bmp = GeoSnoop.DisplaySheet(
                            sheet.Id, sheetViewportLoops,
                            modelCollections);

                        GeoSnoop.DisplayImageInForm(
                            revit_window, caption, false, bmp);

                        // Upload data to the cloud database.

                        DbUpload.DbUploadSheet(sheet,
                                               sheetViewportLoops, modelCollections);
                    }
                    DbUpdater.SetLastSequence();
                }
            }
            return(Result.Succeeded);
        }
Пример #2
0
        /// <summary>
        /// Upload model, sheet, views it contains and
        /// their BIM elements to a CouchDB data repository.
        /// </summary>
        static public void DbUploadSheet(
            ViewSheet sheet,
            JtLoops sheetViewportLoops,
            SheetModelCollections modelCollections)
        {
            bool pre_existing = false;

            RoomEditorDb  rdb = new RoomEditorDb();
            CouchDatabase db  = rdb.Db;

            // Sheet

            Document doc = sheet.Document;

            Element e = GetProjectInfo(doc);

            DbModel dbModel = GetDbModel(db, e);

            DbSheet dbSheet = rdb.GetOrCreate <DbSheet>(
                ref pre_existing, sheet.UniqueId);

            dbSheet.Description = Util.SheetDescription(sheet);
            dbSheet.Name        = sheet.Name;
            dbSheet.ModelId     = e.UniqueId;
            dbSheet.Width       = sheetViewportLoops[0].BoundingBox.Width;
            dbSheet.Height      = sheetViewportLoops[0].BoundingBox.Height;

            dbSheet = pre_existing
        ? db.UpdateDocument <DbSheet>(dbSheet)
        : db.CreateDocument <DbSheet>(dbSheet);

            // Symbols

            Dictionary <ElementId, GeomData> geometryLookup
                = modelCollections.Symbols;

            foreach (KeyValuePair <ElementId, GeomData> p
                     in geometryLookup)
            {
                ElementId id = p.Key;

                e = doc.GetElement(id);

                DbSymbol symbol = rdb.GetOrCreate <DbSymbol>(
                    ref pre_existing, e.UniqueId);

                symbol.Description = Util.ElementDescription(e);
                symbol.Name        = e.Name;
                symbol.Loop        = p.Value.Loop.SvgPath;

                symbol = pre_existing
          ? db.UpdateDocument <DbSymbol>(symbol)
          : db.CreateDocument <DbSymbol>(symbol);
            }

            // Views and BIM elements

            List <ViewData> views = modelCollections
                                    .ViewsInSheet[sheet.Id];

            View               view;
            DbView             dbView;
            DbBimel            dbBimel;
            DbInstance         dbInstance = null;
            DbPart             dbPart     = null;
            JtBoundingBox2dInt bbFrom;
            JtBoundingBox2dInt bbTo;

            foreach (ViewData viewData in views)
            {
                ElementId vid = viewData.Id;

                if (!modelCollections.BimelsInViews
                    .ContainsKey(vid))
                {
                    // This is not a floor plan view, so
                    // we have nothing to display in it.

                    continue;
                }

                view = doc.GetElement(vid) as View;

                dbView = rdb.GetOrCreate <DbView>(
                    ref pre_existing, view.UniqueId);

                dbView.Description = Util.ElementDescription(view);
                dbView.Name        = view.Name;
                dbView.SheetId     = dbSheet.Id;

                bbFrom = viewData.BimBoundingBox;
                bbTo   = viewData.ViewportBoundingBox;

                dbView.X      = bbTo.Min.X;
                dbView.Y      = bbTo.Min.Y;
                dbView.Width  = bbTo.Width;
                dbView.Height = bbTo.Height;

                dbView.BimX      = bbFrom.Min.X;
                dbView.BimY      = bbFrom.Min.Y;
                dbView.BimWidth  = bbFrom.Width;
                dbView.BimHeight = bbFrom.Height;

                dbView = pre_existing
          ? db.UpdateDocument <DbView>(dbView)
          : db.CreateDocument <DbView>(dbView);

                // Retrieve the list of BIM elements
                // displayed in this view.

                List <ObjData> bimels = modelCollections
                                        .BimelsInViews[vid];

                foreach (ObjData bimel in bimels)
                {
                    e = doc.GetElement(bimel.Id);

                    InstanceData inst = bimel as InstanceData;

                    if (null != inst)
                    {
                        dbInstance = rdb.GetOrCreate <DbInstance>(
                            ref pre_existing, e.UniqueId);

                        dbInstance.SymbolId = doc.GetElement(
                            inst.Symbol).UniqueId;

                        dbInstance.Transform = inst.Placement
                                               .SvgTransform;

                        dbBimel = dbInstance;
                    }
                    else
                    {
                        Debug.Assert(bimel is GeomData,
                                     "expected part with geometry");

                        dbPart = rdb.GetOrCreate <DbPart>(
                            ref pre_existing, e.UniqueId);

                        dbPart.Loop = ((GeomData)bimel).Loop
                                      .SvgPath;

                        dbBimel = dbPart;
                    }
                    dbBimel.Description = Util.ElementDescription(e);
                    dbBimel.Name        = e.Name;
                    JtUidSet uids = new JtUidSet(dbBimel.ViewIds);
                    uids.Add(view.UniqueId);
                    dbBimel.ViewIds    = uids.Uids;
                    dbBimel.Properties = Util.GetElementProperties(e);

                    if (null != inst)
                    {
                        dbInstance = pre_existing
              ? db.UpdateDocument <DbInstance>(dbInstance)
              : db.CreateDocument <DbInstance>(dbInstance);
                    }
                    else
                    {
                        dbPart = pre_existing
              ? db.UpdateDocument <DbPart>(dbPart)
              : db.CreateDocument <DbPart>(dbPart);
                    }
                }
            }
        }