Exemple #1
0
        public static Dictionary <string, object> ElementByCategoryFromDocument(Autodesk.Revit.DB.Document doc, Revit.Elements.Category category, Boolean refresh = false)
        {
            List <Revit.Elements.Element> elList = new List <Revit.Elements.Element>();

            if (refresh)
            {
                BuiltInCategory myCatEnum = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), category.Id.ToString());

                ElementCategoryFilter filter = new ElementCategoryFilter(myCatEnum);

                //Document doc = DocumentManager.Instance.CurrentDBDocument;
                //UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication;
                //Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
                //UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;

                FilteredElementCollector collector = new FilteredElementCollector(doc).WherePasses(filter).WhereElementIsNotElementType();
                foreach (Autodesk.Revit.DB.Element e in collector)
                {
                    DynaFunctions f = new DynaFunctions();
                    elList.Add(doc.GetElement(e.Id).ToDSType(true));
                }
            }

            return(new Dictionary <string, object>
            {
                { "Elements", elList },
            });
        }
Exemple #2
0
        public static Dictionary <string, object> IntoTable(string connectionString, List <string> fieldNames, List <List <string> > values, string tableName, string dbSchema = "dbo")
        {
            DynaFunctions f      = new DynaFunctions();
            string        result = "";
            string        names  = "";
            List <string> data   = new List <string>();

            foreach (string fN in fieldNames)
            {
                names += fN + ",";
            }
            names = names.Substring(0, names.Length - 1);
            data.Add(names);

            foreach (List <string> j in values)
            {
                string s = "";
                foreach (string k in j)
                {
                    s += "'" + k.ToString() + "',";
                }
                s = s.Substring(0, s.Length - 1);
                data.Add(s);
                string commandString = "INSERT INTO [" + dbSchema + "]." + tableName + " (" + names + ") VALUES (" + s + ");";
                result = f.executeSqlCommand(commandString, connectionString);
            }
            return(new Dictionary <string, object>
            {
                { "message", result },
                { "data", data },
            });
        }
Exemple #3
0
        public static Dictionary <string, object> getRebarCover(List <Revit.Elements.Element> elements)
        {
            string        message = "";
            Document      doc     = DocumentManager.Instance.CurrentDBDocument;
            DynaFunctions f       = new DynaFunctions();
            //UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication;
            //Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            //UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;
            List <double> topExterior    = new List <double>();
            List <double> bottomInterior = new List <double>();
            List <double> others         = new List <double>();

            Autodesk.Revit.DB.Element el;
            List <BuiltInParameter>   covers = new List <BuiltInParameter>
            {
                BuiltInParameter.CLEAR_COVER_EXTERIOR,
                BuiltInParameter.CLEAR_COVER_TOP,
                BuiltInParameter.CLEAR_COVER_INTERIOR,
                BuiltInParameter.CLEAR_COVER_BOTTOM,
                BuiltInParameter.CLEAR_COVER_OTHER,
                BuiltInParameter.CLEAR_COVER
            };

            foreach (Revit.Elements.Element e in elements)
            {
                el = doc.GetElement(e.UniqueId.ToString());
                List <double> coverValue = new List <double>();
                foreach (BuiltInParameter c in covers)
                {
                    try
                    {
                        ElementId      rctId = el.get_Parameter(c).AsElementId();
                        RebarCoverType rct   = doc.GetElement(rctId) as RebarCoverType;
                        double         cv    = f.feetToMillimeter(rct.get_Parameter(BuiltInParameter.COVER_TYPE_LENGTH).AsDouble());
                        coverValue.Add(cv);
                    }
                    catch (Exception ex)
                    {
                        message = ex.Message;
                    }
                }
                topExterior.Add(coverValue[0]);
                bottomInterior.Add(coverValue[1]);
                others.Add(coverValue[2]);
            }

            return(new Dictionary <string, object>
            {
                { "topExterior", topExterior },
                { "bottomInterior", bottomInterior },
                { "others", others },
                //{ "Message", message },
            });
        }
Exemple #4
0
        public static Dictionary <string, object> Database(String connectionString, string dbName)
        {
            DynaFunctions f             = new DynaFunctions();
            string        commandString = "USE [master]; DROP DATABASE " + dbName;
            string        result        = f.executeSqlCommand(commandString, connectionString);

            return(new Dictionary <string, object>
            {
                { "message", result },
                { "dbName", dbName },
            });
        }
Exemple #5
0
        public static Dictionary <string, object> Table(string connectionString, string tableName, string dbSchema = "dbo")
        {
            DynaFunctions f             = new DynaFunctions();
            string        commandString = "DROP TABLE [" + dbSchema + "]." + tableName;
            string        result        = f.executeSqlCommand(commandString, connectionString);

            return(new Dictionary <string, object>
            {
                { "message", result },
                { "tablename", tableName },
            });
        }
Exemple #6
0
        public static Dictionary <string, object> ColumnsFromTable(string connectionString, List <string> fieldNames, string tableName, string dbSchema = "dbo")
        {
            DynaFunctions f      = new DynaFunctions();
            string        result = "";

            foreach (string fn in fieldNames)
            {
                string commandString = "ALTER TABLE [" + dbSchema + "]." + tableName + " DROP COLUMN " + fn + ";";
                result = f.executeSqlCommand(commandString, connectionString);
            }
            return(new Dictionary <string, object>
            {
                { "message", result },
            });
        }
Exemple #7
0
        public static Dictionary <string, object> getRebarProperties(List <Revit.Elements.Element> rebars)
        {
            string        message = "";
            Document      doc     = DocumentManager.Instance.CurrentDBDocument;
            DynaFunctions f       = new DynaFunctions();
            //UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication;
            //Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            //UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;
            List <string> rStyle = new List <string>();
            List <Revit.Elements.Element> rType      = new List <Revit.Elements.Element>();
            List <Revit.Elements.Element> hStartType = new List <Revit.Elements.Element>();
            List <Revit.Elements.Element> hEndType   = new List <Revit.Elements.Element>();
            List <string> hStartOrient = new List <string>();
            List <string> hEndOrient   = new List <string>();

            foreach (Revit.Elements.Element r in rebars)
            {
                Autodesk.Revit.DB.Element el = doc.GetElement(r.UniqueId.ToString());
                rStyle.Add(el.get_Parameter(BuiltInParameter.REBAR_ELEM_HOOK_STYLE).AsValueString());
                ElementId eId = el.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM).AsElementId();
                rType.Add(doc.GetElement(eId).ToDSType(true));
                try
                {
                    eId = el.get_Parameter(BuiltInParameter.REBAR_ELEM_HOOK_START_TYPE).AsElementId();
                    hStartType.Add(doc.GetElement(eId).ToDSType(true));
                }
                catch { hStartType.Add(null); }
                try
                {
                    eId = el.get_Parameter(BuiltInParameter.REBAR_ELEM_HOOK_END_TYPE).AsElementId();
                    hEndType.Add(doc.GetElement(eId).ToDSType(true));
                }
                catch { hEndType.Add(null); }
                hEndOrient.Add(el.get_Parameter(BuiltInParameter.REBAR_ELEM_HOOK_END_ORIENT).AsValueString());
                hStartOrient.Add(el.get_Parameter(BuiltInParameter.REBAR_ELEM_HOOK_START_ORIENT).AsValueString());
            }

            return(new Dictionary <string, object>
            {
                { "rebarStyle", rStyle },
                { "rebarBarType", rType },
                { "hookStartType", hStartType },
                { "hookEndType", hEndType },
                { "hookStartOrientation", hStartOrient },
                { "hookEndOrientation", hEndOrient },
                //{ "Message", message },
            });
        }
Exemple #8
0
        public static Dictionary <string, object> DuctCollector(Boolean refresh = false)
        {
            List <Revit.Elements.Element> elList = new List <Revit.Elements.Element>();
            List <ElementId> elIdList            = new List <ElementId>();
            List <string>    elNameList          = new List <string>();
            List <double>    elLengthList        = new List <double>();
            List <double>    elOffsetList        = new List <double>();
            List <string>    elCalcSizeList      = new List <string>();
            List <string>    elLevelList         = new List <string>();
            List <double>    elArea = new List <double>();

            if (refresh)
            {
                Document doc = DocumentManager.Instance.CurrentDBDocument;
                //UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication;
                //Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
                //UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;

                FilteredElementCollector collector = new FilteredElementCollector(doc).WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_DuctCurves);

                foreach (Autodesk.Revit.DB.Element e in collector)
                {
                    DynaFunctions f = new DynaFunctions();

                    elIdList.Add(e.Id);
                    elNameList.Add(e.Name);
                    elLengthList.Add(f.feetToMillimeter(f.paramAsDouble(e, BuiltInParameter.CURVE_ELEM_LENGTH)));
                    elList.Add(doc.GetElement(e.Id).ToDSType(true));
                    elOffsetList.Add(f.feetToMillimeter(f.paramAsDouble(e, BuiltInParameter.RBS_OFFSET_PARAM)));
                    elCalcSizeList.Add(f.paramAsString(e, BuiltInParameter.RBS_CALCULATED_SIZE));
                    elLevelList.Add(f.paramAsValueString(e, BuiltInParameter.RBS_START_LEVEL_PARAM));
                    elArea.Add(f.sqfToSqm(f.paramAsDouble(e, BuiltInParameter.RBS_CURVE_SURFACE_AREA)));
                }
            }

            return(new Dictionary <string, object>
            {
                { "Elements", elList },
                { "Id", elIdList },
                { "Name", elNameList },
                { "Length", elLengthList },
                { "Area", elArea },
                { "Offset", elOffsetList },
                { "Size", elCalcSizeList },
                { "Level", elLevelList },
            });
        }
Exemple #9
0
        public static Dictionary <string, object> getRebarCenterLineCurve(
            List <Revit.Elements.Element> rebar,
            bool adjustForSelfIntersection = false,
            bool suppressHooks             = true,
            bool suppressBendRadius        = true,
            bool multiplanarOption         = true
            )
        {
            string        message = "";
            Document      doc     = DocumentManager.Instance.CurrentDBDocument;
            DynaFunctions f       = new DynaFunctions();
            //UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication;
            //Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            //UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;
            List <Autodesk.DesignScript.Geometry.PolyCurve> curves = new List <Autodesk.DesignScript.Geometry.PolyCurve>();
            MultiplanarOption mp = MultiplanarOption.IncludeOnlyPlanarCurves;

            foreach (Revit.Elements.Element r in rebar)
            {
                switch (multiplanarOption)
                {
                case true: mp = MultiplanarOption.IncludeOnlyPlanarCurves; break;

                case false: mp = MultiplanarOption.IncludeAllMultiplanarCurves; break;
                }
                Autodesk.Revit.DB.Element el = doc.GetElement(r.UniqueId.ToString());
                Rebar         reb            = el as Rebar;
                IList <Curve> sketch         = reb.GetCenterlineCurves(adjustForSelfIntersection, suppressHooks, suppressBendRadius, mp, 0);
                List <Autodesk.DesignScript.Geometry.Curve> crv = new List <Autodesk.DesignScript.Geometry.Curve>();
                foreach (Curve s in sketch)
                {
                    Autodesk.DesignScript.Geometry.Curve c = Revit.GeometryConversion.RevitToProtoCurve.ToProtoType(s, true);
                    crv.Add(c);
                }
                Autodesk.DesignScript.Geometry.PolyCurve pc = Autodesk.DesignScript.Geometry.PolyCurve.ByJoinedCurves(crv);
                curves.Add(pc);
            }

            return(new Dictionary <string, object>
            {
                { "polyCurves", curves },
                //{ "Message", message },
            });
        }
Exemple #10
0
        public static Dictionary <string, object> ColumnFromTableByName(string connectionString, string tableName, string fieldName, string dbSchema = "dbo")
        {
            DynaFunctions f             = new DynaFunctions();
            string        commandString = "SELECT * FROM [" + dbSchema + "]." + tableName;
            string        result        = "";
            List <string> output        = new List <string>();

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                try
                {
                    SqlCommand command = new SqlCommand(commandString, conn);
                    conn.Open();
                    command.ExecuteNonQuery();
                    result = "Executed";

                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            if (reader[fieldName.ToString()].ToString() != null)
                            {
                                output.Add(reader[fieldName.ToString()].ToString());
                            }
                            else
                            {
                                output.Add("null");
                            }
                        }
                    }
                    conn.Close();
                }
                catch (SqlException ex)
                {
                    result = ex.Message;
                }
            }

            return(new Dictionary <string, object>
            {
                { "message", result },
                { "output", output },
            });
        }
Exemple #11
0
        public static Dictionary <string, object> IntersectionByElementCategoryFromLink(Revit.Elements.Category category, Document document = null, bool refresh = false)
        {
            List <Revit.Elements.Element>         elList = new List <Revit.Elements.Element>();
            List <List <Revit.Elements.Element> > inList = new List <List <Revit.Elements.Element> >();
            string executed = "";

            if (refresh)
            {
                BuiltInCategory myCatEnum = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), category.Id.ToString(), true);
                Document        doc       = DocumentManager.Instance.CurrentDBDocument;
                //UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication;
                //Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
                //UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;

                ElementCategoryFilter    filter    = new ElementCategoryFilter(myCatEnum);
                FilteredElementCollector collector = new FilteredElementCollector(doc).WherePasses(filter).WhereElementIsNotElementType();

                foreach (Autodesk.Revit.DB.Element e in collector)
                {
                    List <Revit.Elements.Element> intersList = new List <Revit.Elements.Element>();
                    DynaFunctions f = new DynaFunctions();

                    ElementIntersectsElementFilter interFiler = new ElementIntersectsElementFilter(e);
                    FilteredElementCollector       interElem  = new FilteredElementCollector(document).WherePasses(interFiler).WhereElementIsNotElementType();
                    if (interElem.GetElementCount() > 0)
                    {
                        elList.Add(doc.GetElement(e.Id).ToDSType(true));
                        foreach (Autodesk.Revit.DB.Element el in interElem)
                        {
                            intersList.Add(document.GetElement(el.Id).ToDSType(true));
                        }
                        inList.Add(intersList);
                    }
                }
            }
            return(new Dictionary <string, object>
            {
                { "Elements", elList },
                { "Intersections", inList },
                { "Executed", executed }
            });
        }
Exemple #12
0
        public static Dictionary <string, object> setRebarDistributionType(List <Revit.Elements.Element> rebars, bool distributionType = false)
        {
            string        message = "";
            Document      doc     = DocumentManager.Instance.CurrentDBDocument;
            DynaFunctions f       = new DynaFunctions();
            //UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication;
            //Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            //UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;
            List <double> rDiameters = new List <double>();

            Transaction tx = new Transaction(doc, "rebars");

            DistributionType dt = DistributionType.Uniform;

            switch (distributionType)
            {
            case true: dt = DistributionType.VaryingLength; break;

            case false: dt = DistributionType.Uniform; break;
            }
            foreach (Revit.Elements.Element r in rebars)
            {
                Autodesk.Revit.DB.Element el = doc.GetElement(r.UniqueId.ToString());
                Rebar reb = el as Rebar;
                try
                {
                    tx.Start("rebars");
                    reb.DistributionType = dt;
                    tx.Commit();
                }
                catch (Exception ex)
                {
                    message = ex.Message;
                }
            }

            return(new Dictionary <string, object>
            {
                { "rebarDiameter", rDiameters },
                { "Message", message },
            });
        }
Exemple #13
0
        public static Dictionary <string, object> Table(List <String> fieldNames, List <string> fieldTypes, string connectionString, string tableName, string dbSchema = "dbo")
        {
            DynaFunctions f           = new DynaFunctions();
            int           k           = 0;
            string        tableFields = "(";

            foreach (string fn in fieldNames)
            {
                tableFields += fn + " " + fieldTypes[k] + ",";
            }
            tableFields += ");";

            string commandString = "CREATE TABLE [" + dbSchema + "]." + tableName + tableFields;
            string result        = f.executeSqlCommand(commandString, connectionString);

            return(new Dictionary <string, object>
            {
                { "message", result },
                { "tablename", tableName },
            });
        }
Exemple #14
0
        public static Dictionary <string, object> getRebarDiameter(List <Revit.Elements.Element> rebarBarType)
        {
            string        message = "";
            Document      doc     = DocumentManager.Instance.CurrentDBDocument;
            DynaFunctions f       = new DynaFunctions();
            //UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication;
            //Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            //UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;
            List <double> rDiameters = new List <double>();

            foreach (Revit.Elements.Element rt in rebarBarType)
            {
                Autodesk.Revit.DB.Element el = doc.GetElement(rt.UniqueId.ToString());
                rDiameters.Add(f.feetToMillimeter(el.get_Parameter(BuiltInParameter.REBAR_BAR_DIAMETER).AsDouble()));
            }

            return(new Dictionary <string, object>
            {
                { "rebarDiameter", rDiameters },
                //{ "Message", message },
            });
        }
Exemple #15
0
        public static Dictionary <string, object> ColumnsNamesFromTable(string connectionString, string tableName, string dbSchema = "dbo")
        {
            DynaFunctions f             = new DynaFunctions();
            string        commandString = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" + tableName + "' AND TABLE_SCHEMA = '" + dbSchema + "';";
            string        result        = "";
            List <string> output        = new List <string>();

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                try
                {
                    SqlCommand command = new SqlCommand(commandString, conn);
                    conn.Open();
                    command.ExecuteNonQuery();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            output.Add(reader[0].ToString());
                        }
                    }
                    conn.Close();
                    result = "Executed";
                }
                catch (SqlException ex)
                {
                    result = ex.Message;
                }
            }

            return(new Dictionary <string, object>
            {
                { "message", result },
                { "output", output },
            });
        }
Exemple #16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="category"></param>
        /// <param name="refresh"></param>
        /// <returns></returns>
        public static List <List <Autodesk.DesignScript.Geometry.Point> > IntersectionPointsByCategory(Revit.Elements.Category category, Document document = null, bool refresh = false)
        {
            List <Revit.Elements.Element>         elList = new List <Revit.Elements.Element>();
            List <List <Revit.Elements.Element> > inList = new List <List <Revit.Elements.Element> >();

            List <List <Autodesk.DesignScript.Geometry.Point> > cPoints = new List <List <Autodesk.DesignScript.Geometry.Point> >();

            if (refresh)
            {
                BuiltInCategory myCatEnum = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), category.Id.ToString(), true);
                Document        doc       = DocumentManager.Instance.CurrentDBDocument;

                //UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication;
                //Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
                //UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;

                ElementCategoryFilter    filter    = new ElementCategoryFilter(myCatEnum);
                ElementCategoryFilter    exclude   = new ElementCategoryFilter(BuiltInCategory.OST_GenericModel);
                FilteredElementCollector excluded  = new FilteredElementCollector(doc).WherePasses(exclude);
                FilteredElementCollector collector = new FilteredElementCollector(doc).WherePasses(filter).WhereElementIsNotElementType();
                collector.Excluding(excluded.ToElementIds());

                foreach (Autodesk.Revit.DB.Element e in collector)
                {
                    DynaFunctions f = new DynaFunctions();


                    ElementIntersectsElementFilter interFiler = new ElementIntersectsElementFilter(e);
                    FilteredElementCollector       interElem  = new FilteredElementCollector(document).WherePasses(interFiler).WhereElementIsNotElementType();
                    if (interElem.GetElementCount() > 0)
                    {
                        List <Autodesk.Revit.DB.Solid> elGeoms = new List <Autodesk.Revit.DB.Solid>();
                        GeometryElement geomEl = e.get_Geometry(new Options());
                        foreach (GeometryObject geomObj in geomEl)
                        {
                            elGeoms.Add(geomObj as Autodesk.Revit.DB.Solid);
                        }

                        elList.Add(doc.GetElement(e.Id).ToDSType(true));
                        List <Autodesk.Revit.DB.Solid> iS = new List <Autodesk.Revit.DB.Solid>();
                        List <Autodesk.DesignScript.Geometry.Point> cPoint = new List <Autodesk.DesignScript.Geometry.Point>();
                        List <Autodesk.DesignScript.Geometry.Solid> iSS    = new List <Autodesk.DesignScript.Geometry.Solid>();
                        foreach (Autodesk.Revit.DB.Element el in interElem)
                        {
                            GeometryElement intEl = el.get_Geometry(new Options());
                            foreach (GeometryObject intObj in intEl)
                            {
                                iS.Add(intObj as Autodesk.Revit.DB.Solid);
                            }
                        }
                        foreach (Autodesk.Revit.DB.Solid s0 in elGeoms)
                        {
                            foreach (Autodesk.Revit.DB.Solid s1 in iS)
                            {
                                Autodesk.Revit.DB.Solid i = BooleanOperationsUtils.ExecuteBooleanOperation(s0, s1, BooleanOperationsType.Intersect);
                                if (i != null)
                                {
                                    iSS.Add(Revit.GeometryConversion.RevitToProtoSolid.ToProtoType(i));
                                    DisplayUnitType dt = doc.GetUnits().GetFormatOptions(UnitType.UT_Length).DisplayUnits;

                                    XYZ coord = new XYZ(f.convertToUnit(i.ComputeCentroid().X, dt), f.convertToUnit(i.ComputeCentroid().Y, dt), f.convertToUnit(i.ComputeCentroid().Z, dt));
                                    //XYZ coord = new XYZ(i.ComputeCentroid().X, i.ComputeCentroid().Y, i.ComputeCentroid().Z);
                                    Autodesk.DesignScript.Geometry.Point p = Autodesk.DesignScript.Geometry.Point.ByCoordinates(coord.X, coord.Y, coord.Z);
                                    cPoint.Add(p);
                                }
                            }
                        }
                        cPoints.Add(cPoint);
                    }
                }
            }
            return(cPoints);
        }
Exemple #17
0
        public static Dictionary <string, object> ElementParametersByCategoryFromDocument(Autodesk.Revit.DB.Document doc, Revit.Elements.Category category, List <string> parameters = null, Boolean refresh = false)
        {
            string executed = "";
            List <Revit.Elements.Element> elList = new List <Revit.Elements.Element>();
            List <List <object> >         values = new List <List <object> >();

            if (refresh)
            {
                BuiltInCategory       myCatEnum = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), category.Id.ToString());
                ElementCategoryFilter filter    = new ElementCategoryFilter(myCatEnum);

                //Document doc = DocumentManager.Instance.CurrentDBDocument;
                //UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication;
                //Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
                //UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;

                FilteredElementCollector  collector = new FilteredElementCollector(doc).WherePasses(filter).WhereElementIsNotElementType();
                List <Definition>         param     = new List <Definition>();
                Autodesk.Revit.DB.Element e         = collector.FirstElement();
                ParameterSet paramSet = e.Parameters;

                foreach (string s in parameters)
                {
                    foreach (Autodesk.Revit.DB.Parameter p in paramSet)
                    {
                        if (p.Definition.Name == s)
                        {
                            param.Add(p.Definition);
                        }
                    }
                }

                if (param.Count != parameters.Count)
                {
                    executed = "Check parameters name";
                }
                else
                {
                    executed = "Executed";

                    foreach (Autodesk.Revit.DB.Element el in collector)
                    {
                        List <object> elParams = new List <object>();
                        DynaFunctions f        = new DynaFunctions();
                        elList.Add(doc.GetElement(el.Id).ToDSType(true));
                        foreach (Definition p in param)
                        {
                            switch (el.get_Parameter(p).StorageType)
                            {
                            case StorageType.Double: elParams.Add(el.get_Parameter(p).AsDouble()); break;

                            case StorageType.Integer: elParams.Add(el.get_Parameter(p).AsInteger()); break;

                            case StorageType.String: elParams.Add(el.get_Parameter(p).AsString()); break;

                            case StorageType.ElementId: elParams.Add(el.get_Parameter(p).AsValueString()); break;
                            }
                        }
                        values.Add(elParams);
                    }
                }
            }

            return(new Dictionary <string, object>
            {
                { "Elements", elList },
                { "Values", values },
                { "Result", executed }
            });
        }
Exemple #18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="category"></param>
        /// <param name="refresh"></param>
        /// <returns></returns>
        public static List <List <Autodesk.DesignScript.Geometry.Solid> > IntersectionSolidsByCategory(Revit.Elements.Category category, Document document = null, bool refresh = false)
        {
            List <Revit.Elements.Element>         elList = new List <Revit.Elements.Element>();
            List <List <Revit.Elements.Element> > inList = new List <List <Revit.Elements.Element> >();

            List <List <Autodesk.DesignScript.Geometry.Solid> > interGeoms = new List <List <Autodesk.DesignScript.Geometry.Solid> >();


            if (refresh)
            {
                BuiltInCategory myCatEnum = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), category.Id.ToString(), true);
                Document        doc       = DocumentManager.Instance.CurrentDBDocument;

                //UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication;
                //Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
                //UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;

                ElementCategoryFilter    filter    = new ElementCategoryFilter(myCatEnum);
                ElementCategoryFilter    exclude   = new ElementCategoryFilter(BuiltInCategory.OST_GenericModel);
                FilteredElementCollector excluded  = new FilteredElementCollector(doc).WherePasses(exclude);
                FilteredElementCollector collector = new FilteredElementCollector(doc).WherePasses(filter).WhereElementIsNotElementType();
                collector.Excluding(excluded.ToElementIds());


                foreach (Autodesk.Revit.DB.Element e in collector)
                {
                    DynaFunctions f = new DynaFunctions();

                    ElementIntersectsElementFilter interFiler = new ElementIntersectsElementFilter(e);
                    FilteredElementCollector       interElem  = new FilteredElementCollector(document).WherePasses(interFiler).WhereElementIsNotElementType();
                    if (interElem.GetElementCount() > 0)
                    {
                        List <Autodesk.Revit.DB.Solid> elGeoms = new List <Autodesk.Revit.DB.Solid>();
                        GeometryElement geomEl = e.get_Geometry(new Options());
                        foreach (GeometryObject geomObj in geomEl)
                        {
                            elGeoms.Add(geomObj as Autodesk.Revit.DB.Solid);
                        }
                        List <Autodesk.Revit.DB.Solid> iS = new List <Autodesk.Revit.DB.Solid>();
                        List <Autodesk.DesignScript.Geometry.Solid> iSS = new List <Autodesk.DesignScript.Geometry.Solid>();
                        foreach (Autodesk.Revit.DB.Element el in interElem)
                        {
                            GeometryElement intEl = el.get_Geometry(new Options());
                            foreach (GeometryObject intObj in intEl)
                            {
                                iS.Add(intObj as Autodesk.Revit.DB.Solid);
                            }
                        }
                        foreach (Autodesk.Revit.DB.Solid s0 in elGeoms)
                        {
                            foreach (Autodesk.Revit.DB.Solid s1 in iS)
                            {
                                Autodesk.Revit.DB.Solid i = BooleanOperationsUtils.ExecuteBooleanOperation(s0, s1, BooleanOperationsType.Intersect);
                                if (i != null)
                                {
                                    Autodesk.Revit.DB.Solid bbox = f.CreateSolidFromBoundingBox(i);
                                    iSS.Add(Revit.GeometryConversion.RevitToProtoSolid.ToProtoType(i));
                                }
                            }
                        }
                        interGeoms.Add(iSS);
                    }
                }
            }
            return(interGeoms);
        }