Renombrar Patrones de Línea
Revit API Macro
Descripción
El siguiente código busca todos los patrones de línea con un prefijo en el nombre y lo modifica. Este script es una evolución del ejemplo de Matthew Nelson. Gracias Matt! Si lo usas es bajo tu responsabiliad. Y si lo modificas o mejoras compártelo!
public void renameLinePatterns()
{
//Get the current document
UIDocument uidoc = this.ActiveUIDocument;
Document doc = uidoc.Document;
//Get all line patters starting with PREFIX
var collector = new FilteredElementCollector(doc)
.OfClass(typeof(LinePatternElement))
.Where(i => i.Name.StartsWith("PREFIX")).ToList();
//Add them to a list of ids - this is redundant but makes this code reusable for other purposes
List<ElementId> ids = new List<ElementId>();
for (int i = 0; i < collector.Count(); i++)
{
ids.Add(collector[i].Id);
}
//Start the transaction that will modify your document
using(Transaction t = new Transaction(doc,"Rename LinePatterns"))
{
t.Start();
try
{
foreach (ElementId id in ids)
{
//Get the line pattern element
LinePatternElement lpe = doc.GetElement(id) as LinePatternElement;
if (lpe != null)
{
//Get the line pattern name
string lpeName = lpe.Name;
//Modify the name of the line pattern
lpe.Name = lpeName + "-FOO";
}
}
}
catch (Exception)
{
t.RollBack();
TaskDialog.Show("Rename LinePatterns","Renaming failed");
return;
}
t.Commit();
TaskDialog.Show("Rename LinePatterns","Renaming complete");
}
}
Plataforma
Revit.
Tipo
Revit API Macro.