Пример #1
0
        public static Element FromElement(DB.Element element)
        {
            if (element is null)
            {
                return(null);
            }

            for (var type = element.GetType(); type != typeof(DB.Element); type = type.BaseType)
            {
                if (ActivatorDictionary.TryGetValue(type, out var activator))
                {
                    return(activator(element));
                }
            }

            if (DocumentExtension.AsCategory(element) is DB.Category category)
            {
                return(new Category(category));
            }

            if (element is DB.PropertySetElement pset)
            {
                if (StructuralAssetElement.IsValidElement(element))
                {
                    return(new StructuralAssetElement(pset));
                }
                else if (ThermalAssetElement.IsValidElement(element))
                {
                    return(new ThermalAssetElement(pset));
                }
            }
            else if (GraphicalElement.IsValidElement(element))
            {
                if (InstanceElement.IsValidElement(element))
                {
                    if (Panel.IsValidElement(element))
                    {
                        return(new Panel(element as DB.FamilyInstance));
                    }

                    return(new InstanceElement(element));
                }

                if (GeometricElement.IsValidElement(element))
                {
                    return(new GeometricElement(element));
                }

                return(new GraphicalElement(element));
            }
            else
            {
                if (DesignOptionSet.IsValidElement(element))
                {
                    return(new DesignOptionSet(element));
                }
            }

            return(new Element(element));
        }
Пример #2
0
        public static Element FromElement(DB.Element element)
        {
            if (element is null)
            {
                return(null);
            }

            if (element.GetType() == typeof(DB.Element))
            {
                try
                {
                    if (DB.Category.GetCategory(element.Document, element.Id) is DB.Category category)
                    {
                        return(new Category(category));
                    }
                }
                catch (Autodesk.Revit.Exceptions.InternalException) { }
            }
            else if (ActivatorDictionary.TryGetValue(element.GetType(), out var activator))
            {
                return(activator(element));
            }

            if (GeometricElement.IsValidElement(element))
            {
                return(new GeometricElement(element));
            }

            return(new Element(element));
        }
Пример #3
0
        public static new bool IsValidElement(DB.Element element)
        {
            if (element.Category is null)
            {
                return(false);
            }

            return(GeometricElement.IsValidElement(element));
        }
Пример #4
0
        public static Element FromElement(DB.Element element)
        {
            if (element is null)
            {
                return(null);
            }

            if (element.GetType() == typeof(DB.Element))
            {
                try
                {
                    if (DB.Category.GetCategory(element.Document, element.Id) is DB.Category category)
                    {
                        return(new Category(category));
                    }
                }
                catch (Autodesk.Revit.Exceptions.InternalException) { }
            }
            else
            {
                for (var type = element.GetType(); type != typeof(DB.Element); type = type.BaseType)
                {
                    if (ActivatorDictionary.TryGetValue(type, out var activator))
                    {
                        return(activator(element));
                    }
                }
            }

            if (GraphicalElement.IsValidElement(element))
            {
                if (InstanceElement.IsValidElement(element))
                {
                    if (Panel.IsValidElement(element))
                    {
                        return(new Panel(element as DB.FamilyInstance));
                    }

                    return(new InstanceElement(element));
                }

                return(GeometricElement.IsValidElement(element) ?
                       new GeometricElement(element) :
                       new GraphicalElement(element));
            }

            return(new Element(element));
        }
Пример #5
0
        public static Element FromElement(DB.Element element)
        {
            if (element is null)
            {
                return(null);
            }

            for (var type = element.GetType(); type != typeof(DB.Element); type = type.BaseType)
            {
                if (ActivatorDictionary.TryGetValue(type, out var activator))
                {
                    return(activator(element));
                }
            }

            if (DocumentExtension.AsCategory(element) is DB.Category category)
            {
                return(new Category(category));
            }

            if (GraphicalElement.IsValidElement(element))
            {
                if (InstanceElement.IsValidElement(element))
                {
                    if (Panel.IsValidElement(element))
                    {
                        return(new Panel(element as DB.FamilyInstance));
                    }

                    return(new InstanceElement(element));
                }

                if (GeometricElement.IsValidElement(element))
                {
                    return(new GeometricElement(element));
                }

                return(new GraphicalElement(element));
            }

            return(new Element(element));
        }
Пример #6
0
        public static Element FromElement(DB.Element element)
        {
            if (element is null)
            {
                return(null);
            }

            if (element.GetType() == typeof(DB.Element))
            {
                try
                {
                    if (DB.Category.GetCategory(element.Document, element.Id) is DB.Category category)
                    {
                        return(new Category(category));
                    }
                }
                catch (Autodesk.Revit.Exceptions.InternalException) { }
            }
            else
            {
                if (element is DB.ParameterElement parameter)
                {
                    return(new ParameterKey(parameter));
                }

                if (element is DB.Material material)
                {
                    return(new Material(material));
                }

                if (element is DB.GraphicsStyle graphicsStyle)
                {
                    return(new GraphicsStyle(graphicsStyle));
                }

                if (element is DB.Family family)
                {
                    return(new Family(family));
                }

                if (element is DB.ElementType elementType)
                {
                    return(new ElementType(elementType));
                }

                if (element is DB.SketchPlane sketchPlane)
                {
                    return(new SketchPlane(sketchPlane));
                }

                if (element is DB.HostObject host)
                {
                    return(new HostObject(host));
                }

                if (element is DB.DatumPlane datumPlane)
                {
                    if (element is DB.Level level)
                    {
                        return(new Level(level));
                    }

                    if (element is DB.Grid grid)
                    {
                        return(new Grid(grid));
                    }

                    return(new DatumPlane(datumPlane));
                }
            }

            if (GeometricElement.IsValidElement(element))
            {
                return(new GeometricElement(element));
            }

            return(new Element(element));
        }