Is it possible to change the walltype name through API?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to change the WallType for all walls in the selection.
I am trying to implement it in the following way:
Selection selection = uidoc.Selection;
ElementSet collection = selection.Elements;
List<WallType> type=new List<Walltype>();
int index =0;
Transaction trans = new Transaction(doc);
trans.Start("Wall Type");
foreach (Element collectedElem in collection)
{
if (collectedElem.GetType().Name == "Wall")
{
Wall wall = null;
wall = (Wall)collectedElem;
string wallValue = collectedElem.Name.ToUpper() + ":" + collectedElem.Level.Name;
//excelWallInfo is a string list loaded from external excel file. Each entry is in the format WalltypeName+":"+Level+":"+NewName
foreach (string entry in excelWallInfo)
{
if (entry.Contains(wallValue) == true)
{
string[] entryElements = entry.Split(':');
string newWallTypeName = entryElements[2];
if (newWallTypeName == "None" || newWallTypeName == null)
{
newWallTypeName = "EmptyName";
}
type.Add((WallType)wall.WallType.Duplicate(newWallTypeName)); //This line has problem in the second iteration.
TaskDialog.Show("Duplicated Element Type", type[index].Name);
wall.WallType = type[index];
index ++;
}
}
}
trans.Commit();
}
The above code stopped in the second iteration. The first change is successful. However, in the second iteration. The revit software throughs it into the exception.
Any help is appreciated! Thanks very much!