示例#1
0
        public static global::Revit.Elements.Element SetParameterByNameTypeOrInstance(global::Revit.Elements.Element element,
                                                                                      string parameterName, object value)
        {
            //create a list to hold the element ids and add them to it
            Autodesk.Revit.DB.Element  internalElement = element.InternalElement;
            Autodesk.Revit.DB.Document doc             = internalElement.Document;
            //declare variable to assign
            object paramValue;
            //looks up the parameter to see if it exists
            var result = internalElement.LookupParameter(parameterName);

            //if parameter exists as instance obtain it, otherwise try for type
            if (result != null)
            {
                paramValue = element.SetParameterByName(parameterName, value);
            }
            else
            {
                paramValue = doc.GetElement(internalElement.GetTypeId())
                             .ToDSType(true)
                             .SetParameterByName(parameterName, value);
            }

            return(element);
        }
示例#2
0
        private List <Parameter> GetTypeParams(DB.Element element)
        {
            var elementType = Doc.GetElement(element.GetTypeId());

            if (elementType == null || elementType.Parameters == null)
            {
                return(new List <Parameter>());
            }
            return(GetElementParams(elementType, true));
        }
        private Dictionary <string, Parameter> GetTypeParams(DB.Element element)
        {
            var elementType = Doc.GetElement(element.GetTypeId());

            if (elementType == null || elementType.Parameters == null)
            {
                return(new Dictionary <string, Parameter>());
            }
            return(GetElementParams(elementType, true));
        }
示例#4
0
        private void backgroundWorker3_DoWork(object sender, DoWorkEventArgs e)
        {
            double i   = 0;
            double max = doorCollector.Count();


            foreach (Element Ele in doorCollector)
            {
                i += 100 / max;

                if (i <= 100)
                {
                    backgroundWorker3.ReportProgress((int)i);
                }
                else
                {
                    i = 100;
                    backgroundWorker3.ReportProgress((int)i);
                }

                if (backgroundWorker3.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }


                //

                Autodesk.Revit.DB.Element door = Ele as Autodesk.Revit.DB.Element;
                ElementId typeId = door.GetTypeId();
                Autodesk.Revit.DB.Element doorType = localDoc.Document.GetElement(typeId);  //Gets All the Doors

                FamilyInstance            famIns   = door as FamilyInstance;                //Covnvert to family instance to get the host of the door
                Element                   eleHost  = famIns.Host;                           //doors Host
                Autodesk.Revit.DB.Element wallHost = eleHost as Element;                    //convert host back to an element
                ElementId                 typeIdW  = wallHost.GetTypeId();                  //get the type Id of the host as an element
                Autodesk.Revit.DB.Element wallType = localDoc.Document.GetElement(typeIdW); //Use the type ID to find that specific element

                ParameterSet parameters = doorType.Parameters;                              //Finds All walls which needs to be changed

                ElementId typeID = famIns.GetTypeId();                                      //get type id of the family instance

                FamilySymbol fam = localDoc.Document.GetElement(typeID) as FamilySymbol;    // get the instance as a Family Symbol


                deleteParametersDoors.Add(fam.Family);
                //wallToDoors.Add(fam);
            }
        }
示例#5
0
        private void backgroundWorker4_DoWork(object sender, DoWorkEventArgs e)
        {
            double i   = 0;
            double max = windowCollector.Count();


            foreach (Element Ele in windowCollector)
            {
                i += 100 / max;

                if (i <= 100)
                {
                    backgroundWorker4.ReportProgress((int)i);
                }
                else
                {
                    i = 100;
                    backgroundWorker4.ReportProgress((int)i);
                }

                if (backgroundWorker4.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }


                Autodesk.Revit.DB.Element window = Ele as Autodesk.Revit.DB.Element;
                ElementId windowID = window.GetTypeId();
                Autodesk.Revit.DB.Element windowType = localDoc.Document.GetElement(windowID);

                FamilyInstance            famInsWin       = window as FamilyInstance;
                Element                   eleHostWin      = famInsWin.Host;
                Autodesk.Revit.DB.Element wallHostWin     = eleHostWin as Element;
                ElementId                 typeIdForWindow = wallHostWin.GetTypeId();
                Autodesk.Revit.DB.Element wallTypeWindow  = localDoc.Document.GetElement(typeIdForWindow);

                ParameterSet parametersWindow = windowType.Parameters;

                ElementId typeIDW = famInsWin.GetTypeId();

                FamilySymbol famW = localDoc.Document.GetElement(typeIDW) as FamilySymbol; // get the instance as a Family Symbol


                deleteParametersWindows.Add(famW.Family);
            }
        }
示例#6
0
 private void AddElementParams(Element e)
 {
     foreach (Parameter p in e.Parameters)
     {
         if (!(p.StorageType == StorageType.None))
         {
             AddDropDownItem(p);
         }
     }
     // if element can have type assigned it's safe to assume that it's an instance
     // and add type parameters to the list
     if (e.CanHaveTypeAssigned())
     {
         Autodesk.Revit.DB.ElementType et = DocumentManager.Instance.CurrentDBDocument.GetElement(e.GetTypeId()) as Autodesk.Revit.DB.ElementType;
         if (et != null)
         {
             AddTypeParams(et);
         }
     }
 }
示例#7
0
        public static Dictionary <string, object> getAllElementsParameters(List <Revit.Elements.Element> elements)
        {
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
            List <object> listType         = new List <object>();
            List <object> listInstance     = new List <object>();

            Autodesk.Revit.DB.Element el     = doc.GetElement(elements[0].UniqueId.ToString());
            Autodesk.Revit.DB.Element elType = doc.GetElement(el.GetTypeId());
            ParameterSet  paramSet           = el.Parameters;
            ParameterSet  paramSetType       = elType.Parameters;
            List <string> paramInstanceNames = new List <string>();
            List <string> paramTypeNames     = new List <string>();

            foreach (Autodesk.Revit.DB.Parameter p in paramSet)
            {
                paramInstanceNames.Add(p.Definition.Name);
            }

            foreach (Autodesk.Revit.DB.Parameter p in paramSet)
            {
                paramTypeNames.Add(p.Definition.Name);
            }

            foreach (Revit.Elements.Element e in elements)
            {
                List <object> itemInstanceParams = new List <object>();
                el = doc.GetElement(e.UniqueId.ToString());
                foreach (Autodesk.Revit.DB.Parameter p in paramSet)
                {
                    if (el.get_Parameter(p.Definition) != null)
                    {
                        switch (el.get_Parameter(p.Definition).StorageType)
                        {
                        case StorageType.Double: itemInstanceParams.Add(el.get_Parameter(p.Definition).AsValueString()); break;

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

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

                        case StorageType.ElementId: itemInstanceParams.Add(el.get_Parameter(p.Definition).AsValueString()); break;
                        }
                    }
                    else
                    {
                        itemInstanceParams.Add("");
                    }
                }

                listInstance.Add(itemInstanceParams);
            }

            foreach (Revit.Elements.Element e in elements)
            {
                List <object> itemTypeParams = new List <object>();
                el = doc.GetElement(e.UniqueId.ToString());
                Autodesk.Revit.DB.Element eType = doc.GetElement(el.GetTypeId());
                foreach (Autodesk.Revit.DB.Parameter p in paramSetType)
                {
                    if (eType.get_Parameter(p.Definition) != null)
                    {
                        switch (eType.get_Parameter(p.Definition).StorageType)
                        {
                        case StorageType.Double: itemTypeParams.Add(eType.get_Parameter(p.Definition).AsValueString()); break;

                        case StorageType.Integer: itemTypeParams.Add(eType.get_Parameter(p.Definition).AsInteger()); break;

                        case StorageType.String: itemTypeParams.Add(eType.get_Parameter(p.Definition).AsString()); break;

                        case StorageType.ElementId: itemTypeParams.Add(eType.get_Parameter(p.Definition).AsValueString()); break;
                        }
                    }
                    else
                    {
                        itemTypeParams.Add("");
                    }
                }

                listType.Add(itemTypeParams);
            }

            return(new Dictionary <string, object>
            {
                { "parameterInstanceNames", paramInstanceNames },
                { "parameterTypeNames", paramTypeNames },
                { "parameterInstanceList", listInstance },
                { "parameterTypeList", listType },
            });
        }
示例#8
0
        private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
        {
            double i   = 0;
            double max = doorCollector.Count();

            string stringParamWindow = "empty";

            foreach (Element Ele in windowCollector)
            {
                i += 100 / max;

                if (i <= 100)
                {
                    backgroundWorker2.ReportProgress((int)i);
                }
                else
                {
                    i = 100;
                    backgroundWorker2.ReportProgress((int)i);
                }

                if (backgroundWorker2.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }


                Autodesk.Revit.DB.Element window = Ele as Autodesk.Revit.DB.Element;
                ElementId typeId = window.GetTypeId();
                Autodesk.Revit.DB.Element windowType = localDoc.Document.GetElement(typeId); //Gets All the Doors

                FamilyInstance            famIns   = window as FamilyInstance;               //Covnvert to family instance to get the host of the door
                Element                   eleHost  = famIns.Host;                            //doors Host
                Autodesk.Revit.DB.Element wallHost = eleHost as Element;                     //convert host back to an element
                ElementId                 typeIdW  = wallHost.GetTypeId();                   //get the type Id of the host as an element
                Autodesk.Revit.DB.Element wallType = localDoc.Document.GetElement(typeIdW);  //Use the type ID to find that specific element


                stringParamWindow = wallType.get_Parameter(BuiltInParameter.FIRE_RATING).AsString(); //getting wall rating


                if (stringParamWindow == null)
                {
                    stringParamWindow = "No Value";
                }


                ParameterSet parameters = window.Parameters;                             //Finds All walls which needs to be changed

                ElementId typeID = famIns.GetTypeId();                                   //get type id of the family instance

                FamilySymbol fam = localDoc.Document.GetElement(typeID) as FamilySymbol; // get the instance as a Family Symbol



                //  wallToWindows.Add(fam);

                windowFamilies.Add(fam.Family);
                windowElementsDictionary.Add(Ele, stringParamWindow);
            }
        }
示例#9
0
        private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
        {
            double i   = 0;
            double max = doorPoints.Count;

            foreach (Element E in collDoors)
            {
                LocationPoint getDoorPoint = E.Location as LocationPoint;

                if (getDoorPoint == null)
                {
                    if (checkBoxCurtainWalls.Checked == true) //Add curtain walls to the list
                    {
                        Autodesk.Revit.DB.Element door = E as Autodesk.Revit.DB.Element;
                        ElementId typeId = door.GetTypeId();
                        Autodesk.Revit.DB.Element doorType = localDoc.Document.GetElement(typeId); //Gets All the Doors

                        FamilyInstance famIns  = door as FamilyInstance;                           //Covnvert to family instance to get the host of the door
                        Wall           eleHost = famIns.Host as Wall;                              //doors Host

                        LocationCurve LC = eleHost.Location as LocationCurve;
                        Curve         C  = LC.Curve;

                        Line L = C as Line;

                        doorPoints.Add(E, L.Origin as Autodesk.Revit.DB.XYZ);
                    }
                    else
                    {
                        //Dont add any doors with null points (The doors on curtain walls)
                    }
                }
                else
                {
                    doorPoints.Add(E, getDoorPoint.Point as Autodesk.Revit.DB.XYZ);
                }
            }

            Curve curve = (localSpline as CurveElement).GeometryCurve;

            tessellation = curve.Tessellate();

            splinePoints = new Dictionary <int, XYZ>(1);

            double stepsize = 5.0;
            double dist     = 0.0;

            XYZ p     = curve.GetEndPoint(0);
            int count = 0;

            foreach (XYZ q in tessellation)
            {
                if (0 == splinePoints.Count)
                {
                    splinePoints.Add(count, p);
                    dist = 0.0;
                    count++;
                }
                else
                {
                    dist += p.DistanceTo(q);

                    if (dist >= stepsize)
                    {
                        splinePoints.Add(count++, q);
                        dist = 0;
                    }
                    p = q;
                }
            }

            foreach (KeyValuePair <Element, XYZ> door in doorPoints)
            {
                i += 100 / max;

                if (i <= 100)
                {
                    backgroundWorker2.ReportProgress((int)i);
                }
                else
                {
                    i = 100;
                    backgroundWorker2.ReportProgress((int)i);
                }

                if (backgroundWorker2.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }



                double shortestLength = 0;
                XYZ    closestPoint   = new XYZ(0, 0, 0);



                for (int x = 0; x < splinePoints.Count; x++) //finds the shortest lenght door to point
                {
                    if (x == 0)                              // apply to first door in loop
                    {
                        shortestLength = door.Value.DistanceTo(splinePoints[0]);
                        closestPoint   = splinePoints[0];
                    }
                    else
                    {
                        // error
                        if (door.Value.DistanceTo(splinePoints[x]) < shortestLength)// if there is a shorter door
                        {
                            closestPoint   = splinePoints[x];
                            shortestLength = door.Value.DistanceTo(splinePoints[x]);// add the door
                        }
                    }
                }


                foreach (var item in splinePoints)
                {
                    if (closestPoint == item.Value)
                    {
                        //Spline point num/Door Element/Door Point/Closest point on spline
                        orderedPoints.Add(new Tuple <double, Element, XYZ, XYZ>(item.Key, door.Key, door.Value, closestPoint));
                    }
                }
            }
        }