コード例 #1
0
        /// <summary>
        /// Hide the LightingFixtures category
        /// Hosts subcategory in the given view, cf.
        /// http://forums.autodesk.com/t5/revit-api/how-to-get-image-of-a-family-model-without-showing-host-element/td-p/5526085
        /// http://forums.autodesk.com/t5/revit-api/how-to-change-visibility-setting/td-p/5526076
        /// http://forums.autodesk.com/t5/revit-api/how-to-get-family-model-image/td-p/5494839
        /// </summary>
        void HideLightingFixtureHosts(View view)
        {
            Document doc = view.Document;

            Categories categories = doc.Settings.Categories;

            Category catLightingFixtures
                = categories.get_Item(
                      BuiltInCategory.OST_LightingFixtures);

            CategoryNameMap subcats
                = catLightingFixtures.SubCategories;

            Category catHosts = subcats.get_Item("Hosts");

            view.SetVisibility(catHosts, false);
        }
コード例 #2
0
 private void CategorySetup(CC_Category cat)
 {
     if (cat.BuiltInCategory > 0)
     {
         Category bic = GetBuiltInCategory(currentDoc, cat.BuiltInCategory);
         setCategoryStyles(bic, cat);
     }
     else
     {
         CC_Category     parentcat = CategoryCalls.getCategory(cat.Name);
         Category        parent    = GetBuiltInCategory(currentDoc, parentcat.BuiltInCategory);
         CategoryNameMap map       = parent.SubCategories;
         if (!map.Contains(cat.Name))
         {
             Category subcat = currentDoc.Settings.Categories.NewSubcategory(parent, cat.Name);
             setCategoryStyles(subcat, cat);
         }
         else
         {
             Category subcat = map.get_Item(cat.Name);
             setCategoryStyles(subcat, cat);
         }
     }
 }
コード例 #3
0
        private static ElementId CategorySetup(Document doc)
        {
            string name = "View Outline";

            var             parent = Category.GetCategory(doc, BuiltInCategory.OST_CLines);
            CategoryNameMap map    = parent.SubCategories;
            var             subcat = !map.Contains(name) ? doc.Settings.Categories.NewSubcategory(parent, name) : map.get_Item(name);

            subcat.SetLineWeight(1, GraphicsStyleType.Projection);
            subcat.LineColor = new Color(255, 128, 0);
            subcat.SetLinePatternId(doc.GetDash(), GraphicsStyleType.Projection);
            return(subcat.Id);
        }
コード例 #4
0
        /// <summary>
        /// The method is used to collect template information, specifying the New Window Parameters
        /// </summary>
        private void CollectTemplateInfo()
        {
            List <Wall> walls = Utility.GetElements <Wall>(m_application, m_document);

            m_wallThickness = walls[0].Width;
            ParameterMap paraMap        = walls[0].ParametersMap;
            Parameter    wallheightPara = paraMap.get_Item("Unconnected Height");

            if (wallheightPara != null)
            {
                m_wallHeight = wallheightPara.AsDouble();
            }
            Parameter wallwidthPara = paraMap.get_Item("Length");

            if (wallwidthPara != null)
            {
                m_wallWidth = wallwidthPara.AsDouble();
            }
            m_windowInset = m_wallThickness / 10;
            FamilyType      type           = m_familyManager.CurrentType;
            FamilyParameter heightPara     = m_familyManager.get_Parameter(BuiltInParameter.WINDOW_HEIGHT);
            FamilyParameter widthPara      = m_familyManager.get_Parameter(BuiltInParameter.WINDOW_WIDTH);
            FamilyParameter sillHeightPara = m_familyManager.get_Parameter("Default Sill Height");

            if (type.HasValue(heightPara))
            {
                switch (heightPara.StorageType)
                {
                case StorageType.Double:
                    m_height = type.AsDouble(heightPara).Value;
                    break;

                case StorageType.Integer:
                    m_height = type.AsInteger(heightPara).Value;
                    break;
                }
            }
            if (type.HasValue(widthPara))
            {
                switch (widthPara.StorageType)
                {
                case StorageType.Double:
                    m_width = type.AsDouble(widthPara).Value;
                    break;

                case StorageType.Integer:
                    m_width = type.AsDouble(widthPara).Value;
                    break;
                }
            }
            if (type.HasValue(sillHeightPara))
            {
                switch (sillHeightPara.StorageType)
                {
                case StorageType.Double:
                    m_sillHeight = type.AsDouble(sillHeightPara).Value;
                    break;

                case StorageType.Integer:
                    m_sillHeight = type.AsDouble(sillHeightPara).Value;
                    break;
                }
            }

            //set the height,width and sillheight parameter of the opening
            m_familyManager.Set(m_familyManager.get_Parameter(BuiltInParameter.WINDOW_HEIGHT),
                                m_height);
            m_familyManager.Set(m_familyManager.get_Parameter(BuiltInParameter.WINDOW_WIDTH),
                                m_width);
            m_familyManager.Set(m_familyManager.get_Parameter("Default Sill Height"), m_sillHeight);

            //get materials

            FilteredElementCollector elementCollector = new FilteredElementCollector(m_document);

            elementCollector.WherePasses(new ElementClassFilter(typeof(Material)));
            IList <Element> materials = elementCollector.ToElements();

            foreach (Element materialElement in materials)
            {
                Material material = materialElement as Material;
                m_para.GlassMaterials.Add(material.Name);
                m_para.FrameMaterials.Add(material.Name);
            }

            //get categories
            Categories      categories = m_document.Settings.Categories;
            Category        category   = categories.get_Item(BuiltInCategory.OST_Windows);
            CategoryNameMap cnm        = category.SubCategories;

            if (cnm.Contains("Frame/Mullion"))
            {
                m_frameCat = cnm.get_Item("Frame/Mullion");
            }
            if (cnm.Contains("Glass"))
            {
                m_glassCat = cnm.get_Item("Glass");
            }

            //get referenceplanes
            List <ReferencePlane> planes = Utility.GetElements <ReferencePlane>(m_application, m_document);

            foreach (ReferencePlane p in planes)
            {
                if (p.Name.Equals("Sash"))
                {
                    m_sashPlane = p;
                }
                if (p.Name.Equals("Exterior"))
                {
                    m_exteriorPlane = p;
                }
                if (p.Name.Equals("Center (Front/Back)"))
                {
                    m_centerPlane = p;
                }
                if (p.Name.Equals("Top") || p.Name.Equals("Head"))
                {
                    m_topPlane = p;
                }
                if (p.Name.Equals("Sill") || p.Name.Equals("Bottom"))
                {
                    m_sillPlane = p;
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Get the top-level Built-in category id for an IFC entity.
        /// </summary>
        /// <param name="doc">The doument.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="gstyleId">The graphics style, if the returned category is not top level.  This allows shapes to have their visibility controlled by the sub-category.</param>
        /// <returns>The element id for the built-in category.</returns>
        public static ElementId GetCategoryIdForEntity(Document doc, IFCObjectDefinition entity, out ElementId gstyleId)
        {
            gstyleId = ElementId.InvalidElementId;

            IFCEntityType entityType = entity.EntityType;

            IFCEntityType?typeEntityType = null;
            string        typeShapeType  = null;

            GetAssociatedTypeEntityInfo(entity, out typeEntityType, out typeShapeType);

            // Use the IfcTypeObject shape type if the IfcElement shape type is either null, empty, white space, or not defined.
            string shapeType = entity.ShapeType;

            if ((string.IsNullOrWhiteSpace(shapeType) || (string.Compare(shapeType, "NOTDEFINED", true) == 0)) &&
                !string.IsNullOrWhiteSpace(typeShapeType))
            {
                shapeType = typeShapeType;
            }

            // Set "special" shape types
            switch (entityType)
            {
            case IFCEntityType.IfcColumn:
            case IFCEntityType.IfcColumnType:
                if (IsColumnLoadBearing(entity))
                {
                    shapeType = "[LoadBearing]";
                }
                break;
            }

            ElementId catElemId = GetCategoryElementId(entityType, shapeType);

            // If we didn't find a category, or if we found the generic model category, try again with the IfcTypeObject, if there is one.
            if (catElemId == ElementId.InvalidElementId || catElemId.IntegerValue == (int)BuiltInCategory.OST_GenericModel)
            {
                if (typeEntityType.HasValue)
                {
                    catElemId = GetCategoryElementId(typeEntityType.Value, shapeType);
                }
            }

            Category subCategory = null;

            if (catElemId.IntegerValue == (int)BuiltInCategory.OST_GenericModel)
            {
                string subCategoryName = GetCustomCategoryName(entity);
                if (!string.IsNullOrWhiteSpace(subCategoryName))
                {
                    IDictionary <string, Category> createdSubcategories = Importer.TheCache.CreatedSubcategories;
                    if (!createdSubcategories.TryGetValue(subCategoryName, out subCategory))
                    {
                        // Category may have been created by a previous action (probably a previous import).  Look first.
                        try
                        {
                            CategoryNameMap subCategories = Importer.TheCache.GenericModelsCategory.SubCategories;
                            subCategory = subCategories.get_Item(subCategoryName);
                        }
                        catch
                        {
                            subCategory = null;
                        }

                        if (subCategory == null)
                        {
                            subCategory = Importer.TheCache.DocumentCategories.NewSubcategory(Importer.TheCache.GenericModelsCategory, subCategoryName);
                            SetMaterialForSpacesAndOpenings(doc, entity.Id, subCategory, subCategoryName);
                        }

                        createdSubcategories[subCategoryName] = subCategory;
                    }

                    GraphicsStyle graphicsStyle = subCategory.GetGraphicsStyle(GraphicsStyleType.Projection);
                    if (graphicsStyle != null)
                    {
                        gstyleId = graphicsStyle.Id;
                    }
                }
            }
            else if (catElemId == ElementId.InvalidElementId)
            {
                catElemId = new ElementId(BuiltInCategory.OST_GenericModel);

                // Top level entities that are OK to be here.
                if (entityType != IFCEntityType.IfcProject &&
                    entityType != IFCEntityType.IfcBuilding &&
                    entityType != IFCEntityType.IfcBuildingStorey &&
                    entityType != IFCEntityType.IfcElementAssembly)
                {
                    string msg = "Setting IFC entity ";
                    if (string.IsNullOrWhiteSpace(shapeType))
                    {
                        msg = entityType.ToString();
                    }
                    else
                    {
                        msg = entityType.ToString() + "." + shapeType;
                    }

                    if (typeEntityType.HasValue)
                    {
                        msg += " (" + typeEntityType.Value.ToString() + ")";
                    }

                    msg += " to Generic Models.";
                    IFCImportFile.TheLog.LogWarning(entity.Id, msg, true);
                }
            }

            Category categoryToCheck = null;

            if (catElemId.IntegerValue < 0)
            {
                categoryToCheck = Importer.TheCache.DocumentCategories.get_Item((BuiltInCategory)catElemId.IntegerValue);
            }
            else
            {
                categoryToCheck = subCategory;
            }

            if (categoryToCheck != null)
            {
                // We'll assume that a negative value means a built-in category.  It may still be a sub-category, in which case we need to get the parent category and assign the gstyle.
                // We could optimize this, but this is safer.
                Category parentCategory = categoryToCheck.Parent;
                if (parentCategory != null)
                {
                    catElemId = parentCategory.Id;
                }

                // Not already set by subcategory.
                if (gstyleId == ElementId.InvalidElementId)
                {
                    GraphicsStyle graphicsStyle = categoryToCheck.GetGraphicsStyle(GraphicsStyleType.Projection);
                    if (graphicsStyle != null)
                    {
                        gstyleId = graphicsStyle.Id;
                    }
                }
            }

            return(catElemId);
        }
コード例 #6
0
        private static bool InitFromFile()
        {
            string       fileName = IFCImportFile.TheFile.Document.Application.ImportIFCCategoryTable;
            StreamReader inFile   = null;

            if (!string.IsNullOrWhiteSpace(fileName))
            {
                try
                {
                    inFile = new StreamReader(fileName);
                }
                catch
                {
                    return(false);
                }
            }

            if (inFile == null)
            {
                return(false);
            }

            IDictionary <string, Category> createdSubcategories = Importer.TheCache.CreatedSubcategories;

            while (true)
            {
                string nextLine = inFile.ReadLine();
                if (nextLine == null)
                {
                    break;
                }

                // Skip empty line.
                if (string.IsNullOrWhiteSpace(nextLine))
                {
                    continue;
                }

                // Skip comment.
                if (nextLine.First() == '#')
                {
                    continue;
                }

                string[] fields    = nextLine.Split('\t');
                int      numFields = fields.Count();

                // Too few fields, ignore.
                if (numFields < 3)
                {
                    continue;
                }

                string ifcClassName = fields[0];
                if (string.IsNullOrWhiteSpace(ifcClassName))
                {
                    continue;
                }
                IFCEntityType ifcClassType;
                if (!Enum.TryParse <IFCEntityType>(ifcClassName, true, out ifcClassType))
                {
                    IFCImportFile.TheLog.LogWarning(-1, "Unknown class name in IFC entity to category mapping file: " + ifcClassName, true);
                    continue;
                }

                bool   hasTypeName = (numFields == 4);
                string ifcTypeName = null;
                if (hasTypeName)
                {
                    ifcTypeName = fields[1];
                }

                // Skip entries we have already seen
                bool alreadyPresent = false;
                if (string.IsNullOrWhiteSpace(ifcTypeName))
                {
                    alreadyPresent = m_EntityTypeToCategory.ContainsKey(ifcClassType);
                }
                else
                {
                    alreadyPresent = m_EntityShapeTypeToCategory.ContainsKey(new KeyValuePair <IFCEntityType, string>(ifcClassType, ifcTypeName));
                }

                if (alreadyPresent)
                {
                    continue;
                }

                int categoryField    = hasTypeName ? 2 : 1;
                int subCategoryField = hasTypeName ? 3 : 2;

                // If set to "Don't Import", or some variant, ignore this entity.
                string categoryName = fields[categoryField];
                if (IsEqualIgnoringCaseSpacesApostrophe(categoryName, "DontImport"))
                {
                    if (string.IsNullOrWhiteSpace(ifcTypeName))
                    {
                        m_EntityDontImport.Add(ifcClassType);
                    }
                    else
                    {
                        m_EntityDontImportShapeType.Add(new KeyValuePair <IFCEntityType, string>(ifcClassType, ifcTypeName));
                    }
                    continue;
                }

                // TODO: Use enum name, not category name, in file.
                ElementId categoryId = ElementId.InvalidElementId;
                Category  category   = null;

                try
                {
                    category   = Importer.TheCache.DocumentCategories.get_Item(categoryName);
                    categoryId = category.Id;
                }
                catch
                {
                    IFCImportFile.TheLog.LogWarning(-1, "Unknown top-level category in IFC entity to category mapping file: " + categoryName, true);
                    continue;
                }

                string subCategoryName = null;
                if (numFields > 2)
                {
                    subCategoryName = fields[subCategoryField];
                    if (!string.IsNullOrWhiteSpace(subCategoryName))
                    {
                        CategoryNameMap subCategories = category.SubCategories;

                        try
                        {
                            Category subcategory = subCategories.get_Item(subCategoryName);
                            categoryId = subcategory.Id;
                        }
                        catch
                        {
                            if (category.CanAddSubcategory)
                            {
                                Category subcategory = null;
                                if (!createdSubcategories.TryGetValue(subCategoryName, out subcategory))
                                {
                                    subcategory = Importer.TheCache.DocumentCategories.NewSubcategory(category, subCategoryName);
                                    createdSubcategories[subCategoryName] = subcategory;
                                }
                                categoryId = subcategory.Id;
                            }
                            else
                            {
                                IFCImportFile.TheLog.LogWarning(-1, "Can't add sub-category " + subCategoryName + " to top-level category " + categoryName + " in IFC entity to category mapping file.", true);
                            }
                        }
                    }
                }

                if (string.IsNullOrWhiteSpace(ifcTypeName))
                {
                    m_EntityTypeToCategory[ifcClassType] = (BuiltInCategory)category.Id.IntegerValue;
                }
                else
                {
                    m_EntityShapeTypeToCategory[new KeyValuePair <IFCEntityType, string>(ifcClassType, ifcTypeName)] = (BuiltInCategory)category.Id.IntegerValue;
                }
            }

            return(true);
        }