Announcements

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

Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

1 REPLY 1
Reply
Message 1 of 2
Anonymous
805 Views, 1 Reply

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

    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

 

1 REPLY 1
Message 2 of 2
BobbyC.Jones
in reply to: Anonymous

OfClass()

--
Bobby C. Jones

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report