/// <summary>
      /// Remove an element from the GUID to element id map, if its GUID is found in the map.
      /// </summary>
      /// <param name="elem">The element.</param>
      public void UseElement(Element elem)
      {
         if (elem == null)
            return;

         string guid = IFCGUIDUtil.GetGUID(elem);
         if (string.IsNullOrWhiteSpace(guid))
            return;

         GUIDToElementMap.Remove(guid);
      }
示例#2
0
        /// <summary>
        /// Create the GUIDToElementMap and the GridNameToElementMap to reuse elements by GUID and Grid name.
        /// </summary>
        /// <param name="document">The document.</param>
        public void CreateExistingElementMaps(Document document)
        {
            FilteredElementCollector collector = new FilteredElementCollector(document);

            // These are the only element types currently created in .NET code.  This list needs to be updated when a new
            // type is created.
            List <Type> supportedElementTypes = new List <Type>();

            supportedElementTypes.Add(typeof(DirectShape));
            supportedElementTypes.Add(typeof(DirectShapeType));
            supportedElementTypes.Add(typeof(Level));
            supportedElementTypes.Add(typeof(Grid));

            ElementMulticlassFilter multiclassFilter = new ElementMulticlassFilter(supportedElementTypes);

            collector.WherePasses(multiclassFilter);

            foreach (Element elem in collector)
            {
                string guid = IFCGUIDUtil.GetGUID(elem);
                if (string.IsNullOrWhiteSpace(guid))
                {
                    continue; // This Element was generated by other means.
                }
                if (elem is Grid)
                {
                    string gridName = elem.Name;
                    if (GridNameToElementMap.ContainsKey(gridName))
                    {
                        // If the Grid has a duplicate grid name, assign an arbitrary one to add to the map.  This will mean
                        // that the Grid will be deleted at the end of reloading.
                        // TODO: warn the user about this, and/or maybe allow for some duplication based on category.
                        gridName = Guid.NewGuid().ToString();
                    }

                    GridNameToElementMap.Add(new KeyValuePair <string, ElementId>(gridName, elem.Id));
                }
                else
                {
                    if (GUIDToElementMap.ContainsKey(guid))
                    {
                        // If the Element contains a duplicate GUID, assign an arbitrary one to add to the map.  This will mean
                        // that the Element will be deleted at the end of reloading.
                        // TODO: warn the user about this, and/or maybe allow for some duplication based on category.
                        guid = Guid.NewGuid().ToString();
                    }

                    GUIDToElementMap.Add(new KeyValuePair <string, ElementId>(guid, elem.Id));
                }
            }
        }