using System; using System.IO; using System.Windows.Forms; using System.Collections; using System.Collections.Generic; using Autodesk.Revit; using Autodesk.Revit.DB; using ELEMENTSET = Autodesk.Revit.DB.ElementSet; using PARAMETER = Autodesk.Revit.DB.Parameter; using Autodesk.Revit.Structural.Enums; using DocCSharp.csproj; namespace Revit.SDK.Samples.RenumbItems.CS { /// /// Renumber items /// Use Filter to pick -only- equip /// June 2009 /// public class RenumbItems { ThisDocument m_doc; //ThisDocument data for VSTA /// /// Ctro without parameter is not allowed /// private RenumbItems() { } /// /// Ctor with ThisDocument as /// /// ThisDocument handler public RenumbItems(ThisDocument hostDoc) { m_doc = hostDoc; } /// /// Run this sample /// public void Run() { ELEMENTSET collection = m_doc.Selection.Elements; // check user selection if (collection.Size < 1) { //MessageBox.Show("Please select an object to Renumber", "Renumber Doors"); return; } bool error = true; try { error = true; int num = 1; //NUMBER START // IEnumerator e = collection.GetEnumerator(); bool MoreValue = e.MoveNext(); while (MoreValue) { Element comp = e.Current as Element; PARAMETER p = comp.get_Parameter(Autodesk.Revit.Parameters.BuiltInParameter.DOOR_NUMBER); string drno = p.AsString(); p.Set(drno); drno++; MoreValue = e.MoveNext(); } error = false; } catch { // if revit threw an exception, try to catch it foreach (Element c in collection) { m_doc.Selection.Elements.Insert(c); } //MessageBox.Show("Element(s) can't be renumbered.", "Renumber Doors"); return; } finally { // if revit threw an exception, display error and return failed if (error) { //MessageBox.Show("Renumber failed."); } } return; } } }