GetElementProperties() public static method

Return a dictionary of all the given element parameter names and values.
public static GetElementProperties ( Element e ) : string>.Dictionary
e Element
return string>.Dictionary
コード例 #1
0
ファイル: DbUpload.cs プロジェクト: vdubya/RoomEditorApp
        /// <summary>
        /// Upload model, level, room and furniture data
        /// to an IrisCouch hosted CouchDB data repository.
        /// </summary>
        static public void DbUploadRoom(
            Room room,
            List <Element> furniture,
            JtLoops roomLoops,
            Dictionary <string, JtLoop> furnitureLoops)
        {
            CouchDatabase db = new RoomEditorDb().Db;

            Document doc = room.Document;

            Element projectInfo = GetProjectInfo(doc);

            DbModel dbModel = GetDbModel(db, projectInfo);

            Element level = doc.GetElement(room.LevelId);

            string uid = level.UniqueId;

            DbLevel dbLevel;

            if (db.DocumentExists(uid))
            {
                dbLevel = db.GetDocument <DbLevel>(uid);

                Debug.Assert(
                    dbLevel.Id.Equals(level.UniqueId),
                    "expected equal ids");

                dbLevel.Description = Util.ElementDescription(
                    level);

                dbLevel.Name    = level.Name;
                dbLevel.ModelId = projectInfo.UniqueId;

                dbLevel = db.UpdateDocument <DbLevel>(
                    dbLevel);
            }
            else
            {
                dbLevel = new DbLevel(uid);

                dbLevel.Description = Util.ElementDescription(
                    level);

                dbLevel.Name    = level.Name;
                dbLevel.ModelId = projectInfo.UniqueId;

                dbLevel = db.CreateDocument <DbLevel>(
                    dbLevel);
            }

            uid = room.UniqueId;

            DbRoom dbRoom;

            if (db.DocumentExists(uid))
            {
                dbRoom = db.GetDocument <DbRoom>(uid);

                Debug.Assert(
                    dbRoom.Id.Equals(room.UniqueId),
                    "expected equal ids");

                dbRoom.Description = Util.ElementDescription(
                    room);

                dbRoom.Name    = room.Name;
                dbRoom.LevelId = level.UniqueId;
                dbRoom.Loops   = roomLoops.SvgPath;
                dbRoom.ViewBox = roomLoops.BoundingBox.SvgViewBox;

                dbRoom = db.UpdateDocument <DbRoom>(dbRoom);
            }
            else
            {
                dbRoom = new DbRoom(uid);

                dbRoom.Description = Util.ElementDescription(
                    room);

                dbRoom.Name    = room.Name;
                dbRoom.LevelId = level.UniqueId;
                dbRoom.Loops   = roomLoops.SvgPath;
                dbRoom.ViewBox = roomLoops.BoundingBox.SvgViewBox;

                dbRoom = db.CreateDocument <DbRoom>(dbRoom);
            }

            foreach (KeyValuePair <string, JtLoop> p in furnitureLoops)
            {
                uid = p.Key;
                Element e = doc.GetElement(uid);
                if (db.DocumentExists(uid))
                {
                    DbSymbol symbol = db.GetDocument <DbSymbol>(
                        uid);

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

                    symbol = db.UpdateDocument <DbSymbol>(symbol);
                }
                else
                {
                    DbSymbol symbol = new DbSymbol(uid);

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

                    symbol = db.CreateDocument <DbSymbol>(symbol);
                }
            }

            foreach (FamilyInstance f in furniture)
            {
                uid = f.UniqueId;
                if (db.DocumentExists(uid))
                {
                    DbFurniture dbf = db.GetDocument <DbFurniture>(
                        uid);

                    dbf.Description = Util.ElementDescription(f);
                    dbf.Name        = f.Name;
                    dbf.RoomId      = room.UniqueId;
                    dbf.Properties  = Util.GetElementProperties(f);
                    dbf.SymbolId    = f.Symbol.UniqueId;
                    dbf.Transform   = new JtPlacement2dInt(f)
                                      .SvgTransform;

                    dbf = db.UpdateDocument <DbFurniture>(dbf);
                }
                else
                {
                    DbFurniture dbf = new DbFurniture(uid);

                    dbf.Description = Util.ElementDescription(f);
                    dbf.Name        = f.Name;
                    dbf.RoomId      = room.UniqueId;
                    dbf.Properties  = Util.GetElementProperties(f);
                    dbf.SymbolId    = f.Symbol.UniqueId;
                    dbf.Transform   = new JtPlacement2dInt(f)
                                      .SvgTransform;

                    dbf = db.CreateDocument <DbFurniture>(dbf);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Update a piece of furniture.
        /// Return true if anything was changed.
        /// </summary>
        bool UpdateBimFurniture(
            DbFurniture f)
        {
            Document doc = _uiapp.ActiveUIDocument.Document;

            bool rc = false;

            if (!_roomUniqueIdDict.ContainsKey(f.RoomId))
            {
                Debug.Print("Furniture instance '{0}' '{1}'"
                            + " with UniqueId {2} belong to a room from"
                            + " a different model, so ignore it.",
                            f.Name, f.Description, f.Id);

                return(rc);
            }

            Element e = doc.GetElement(f.Id);

            if (null == e)
            {
                Util.ErrorMsg(string.Format(
                                  "Unable to retrieve element '{0}' '{1}' "
                                  + "with UniqueId {2}. Are you in the right "
                                  + "Revit model?", f.Name,
                                  f.Description, f.Id));

                return(rc);
            }

            if (!(e is FamilyInstance))
            {
                Debug.Print("Strange, we received an "
                            + "updated '{0}' '{1}' with UniqueId {2}, "
                            + "which we ignore.", f.Name,
                            f.Description, f.Id);

                return(rc);
            }

            // Convert SVG transform from string to int
            // to XYZ point and rotation in radians
            // including flipping of Y coordinates.

            string svgTransform = f.Transform;

            char[]   separators = new char[] { ',', 'R', 'T' };
            string[] a          = svgTransform.Substring(1).Split(separators);
            int[]    trxy       = a.Select <string, int>(s => int.Parse(s)).ToArray();

            double r = Util.ConvertDegreesToRadians(
                Util.SvgFlipY(trxy[0]));

            XYZ p = new XYZ(
                Util.ConvertMillimetresToFeet(trxy[1]),
                Util.ConvertMillimetresToFeet(Util.SvgFlipY(trxy[2])),
                0.0);

            // Check for modified transform

            LocationPoint lp = e.Location as LocationPoint;

            XYZ    translation = p - lp.Point;
            double rotation    = r - lp.Rotation;

            bool modifiedTransform = (0.01 < translation.GetLength()) ||
                                     (0.01 < Math.Abs(rotation));

            // Check for modified properties

            List <string> modifiedPropertyKeys = new List <string>();

            Dictionary <string, string> dbdict
                = f.Properties;

            Dictionary <string, string> eldict
                = Util.GetElementProperties(e);

            Debug.Assert(dbdict.Count == eldict.Count,
                         "expected equal dictionary length");

            string key_db; // JavaScript lowercases first char
            string val_db; // remove prepended "r " or "w "
            string val_el;

            foreach (string key in eldict.Keys)
            {
                Parameter pa = e.LookupParameter(key);

                Debug.Assert(null != pa, "expected valid parameter");

                if (Util.IsModifiable(pa))
                {
                    key_db = Util.Uncapitalise(key);

                    Debug.Assert(dbdict.ContainsKey(key_db),
                                 "expected same keys in Revit model and cloud database");

                    val_db = dbdict[key_db].Substring(2);

                    if (StorageType.String == pa.StorageType)
                    {
                        val_el = pa.AsString() ?? string.Empty;
                    }
                    else
                    {
                        Debug.Assert(StorageType.Integer == pa.StorageType,
                                     "expected only string and integer parameters");

                        val_el = pa.AsInteger().ToString();
                    }

                    if (!val_el.Equals(val_db))
                    {
                        modifiedPropertyKeys.Add(key);
                    }
                }
            }

            if (modifiedTransform || 0 < modifiedPropertyKeys.Count)
            {
                using (Transaction tx = new Transaction(
                           doc))
                {
                    tx.Start("Update Furniture and "
                             + "Equipmant Instance Placement");

                    if (.01 < translation.GetLength())
                    {
                        ElementTransformUtils.MoveElement(
                            doc, e.Id, translation);
                    }
                    if (.01 < Math.Abs(rotation))
                    {
                        Line axis = Line.CreateBound(lp.Point,
                                                     lp.Point + XYZ.BasisZ);

                        ElementTransformUtils.RotateElement(
                            doc, e.Id, axis, rotation);
                    }
                    foreach (string key in modifiedPropertyKeys)
                    {
                        Parameter pa = e.LookupParameter(key);

                        key_db = Util.Uncapitalise(key);
                        val_db = dbdict[key_db].Substring(2);

                        if (StorageType.String == pa.StorageType)
                        {
                            pa.Set(val_db);
                        }
                        else
                        {
                            try
                            {
                                int i = int.Parse(val_db);
                                pa.Set(i);
                            }
                            catch (System.FormatException)
                            {
                            }
                        }
                    }
                    tx.Commit();
                    rc = true;
                }
            }
            return(rc);
        }
コード例 #3
0
ファイル: DbUpload.cs プロジェクト: vdubya/RoomEditorApp
        /// <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);
                    }
                }
            }
        }