I am trying to create a new instance of a Generic Wall Type so that I can keep all parameter settings of the original generic wall, but change the width. My problem is the width for a wallType has no { Set; } (is read-only). If someone can explain to me how to effectively create a custom Wall type with a specified width, it would be greatly appreciated.
using System; using System.Collections.Generic; using Autodesk.Revit.DB; using Autodesk.Revit.UI; using Autodesk.Revit.Attributes; // Replace a selected wall with a wall of different width. (create new type) namespace RevitPlugin0816 { [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class WallTypePrint : IExternalCommand { public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiApp = commandData.Application; UIDocument uidoc = uiApp.ActiveUIDocument; Autodesk.Revit.ApplicationServices.Application app = uiApp.Application; Autodesk.Revit.DB.Document doc = uiApp.ActiveUIDocument.Document; Transaction trans = new Transaction(doc); trans.Start(); List<WallType> oWallTypes = new List<WallType>(); List<WallType> GenericWallTypes = new List<WallType>(); oWallTypes = GetWallTypes(doc); //Get a list of all Generic Wall Types in the document foreach (WallType wt in oWallTypes) if (wt.Name.Contains("Generic")) GenericWallTypes.Add(wt); //Duplicate Generic Wall Type: Generic - 8" WallType newWallType = GenericWallTypes[0].Duplicate("Custom WallType") as WallType; //locate parameter for wall width Parameter p = newWallType.get_Parameter(BuiltInParameter.WALL_ATTR_WIDTH_PARAM); //set the new width of the wall to 6.00 p.Set(6.00); //ERROR: wall width is read-only trans.Commit(); return Result.Succeeded; }//public Result Execute public static List<WallType> GetWallTypes(Autodesk.Revit.DB.Document doc) { List<WallType> oWallTypes = new List<WallType>(); try { FilteredElementCollector collector = new FilteredElementCollector(doc); FilteredElementIterator itor = collector .OfClass(typeof(HostObjAttributes)) .GetElementIterator(); // Reset the iterator itor.Reset(); // Iterate through each family while (itor.MoveNext()) { Autodesk.Revit.DB.HostObjAttributes oSystemFamilies = itor.Current as Autodesk.Revit.DB.HostObjAttributes; if (oSystemFamilies == null) continue; // Get the family's category Category oCategory = oSystemFamilies.Category; // Process if the category is found if (oCategory != null) { if (oCategory.Name == "Walls") { WallType oWallType = oSystemFamilies as WallType; if (oWallType != null) oWallTypes.Add(oWallType); } } } //while itor.NextMove() return oWallTypes; } catch (Exception) { //MessageBox.Show( ex.Message ); return oWallTypes = new List<WallType>(); } } //GetWallTypes } }