Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Remap Revit element levels so levels can be deleted without deleting geometry

Anonymous

Remap Revit element levels so levels can be deleted without deleting geometry

Anonymous
Not applicable

    public partial class ThisApplication
    {
        private void Module_Startup(object sender, EventArgs e)
        {

        }

        private void Module_Shutdown(object sender, EventArgs e)
        {

        }

        #region Revit Macros generated code
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(Module_Startup);
            this.Shutdown += new System.EventHandler(Module_Shutdown);
        }
        #endregion
        public void LevelRemap()
        {
            
            Document doc = this.ActiveUIDocument.Document;
            UIDocument uidoc = this.ActiveUIDocument;
            Level level = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element, "Select level")) as Level;
            
            Level levelBelow = new FilteredElementCollector(doc)
                .ofClass(typeof(Level))
                .Cast<Level>()
                .OrderBy(q => q.Elevation)
                .Where(q => q.Elevation <= level.Elevation)
                .FirstOrDefault();
            
            if (levelBelow == null)
            {
                TaskDialog.Show("Error""No level below " + level.Elevation);
                return;
            }
            
            List<string> paramsToAdjust = new List<string> { "Base offset""Sill Height""Top offset"};
            
            List<Element> elements = new FilteredElementCollector(doc).WherePasses(new ElementLevelFilter(level.Id)).ToList();
            using (Transaction t = new Transaction(doc, "Level Remap"))
            {
                t.Start();
                foreach (Element e in elements)
                {
                    foreach (Parameter p in e.Parameters)
                    {
                        if (p.StorageType != StorageType.ElementId  || p.IsReadOnly)
                            continue;
                        if (p.AsElementId() != level.Id)
                            continue;
                        
                        double elevationDiff = level.Elevation - levelBelow.Elevation;
                        
                        p.Set(levelBelow.Id);
                        
                        foreach (string paramName in paramsToAdjust)
                        {
                            Parameter pToAdjust = e.LookupParameter(paramName);
                            if (pToAdjust != null && !pToAdjust.IsReadOnly)
                            pToAdjust.Set(pToAdjust.AsDouble() + elevationDiff);
                        }
                    }
                }
                t.commit();
            }
    
        }

 

Error:'Autodesk.Revit.DB.FilteredElementCollector' does not contain a definition for 'ofClass' and no extension method 'ofClass' accepting a first argument of type 'Autodesk.Revit.DB.FilteredElementCollector' could be found (are you missing a using directive or an assembly reference?) (CS1061) - C:\ProgramData\Autodesk\Revit\Macros\2018\Revit\AppHookup\levelRemap\Source\levelRemap\ThisApplication.cs:47,6

 

Kindly give a solution to clear the error

 

0 Likes
Reply
808 Views
1 Reply
Reply (1)

BobbyC.Jones
Advocate
Advocate

OfClass()

--
Bobby C. Jones