[Transaction(TransactionMode.Manual)][Regeneration(RegenerationOption.Manual)] public class SetParam : IExternalCommand{ public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uiDoc = commandData.Application.ActiveUIDocument; Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application; // 门 string family = " 单开门 " ; string type = " M0721 " ; FamilySymbol fs = FindElementType(uiDoc.Document, typeof (FamilySymbol), family, type, BuiltInCategory.OST_Doors) as FamilySymbol; Transaction tr = new Transaction(uiDoc.Document, " test " ); tr.Start(); foreach (Parameter para in fs.Parameters) if (para.Definition.Name == " Height " ) para.Set(mmToFeet( 200 )); tr.Commit(); return Result.Succeeded; } // 毫米到英寸,单位换算 public double mmToFeet( double val) { return val / 304.8 ; } // 通过族名称,族类型,从过滤器中找到指定的类型。 public Element FindElementType(Document doc, Type targetType, string familyName, string typeName, BuiltInCategory catagory) { IList < Element > elements = FindSpecialElements(doc, targetType, catagory); Element elem = null ; foreach (Element e in elements) { if (e.Name.Equals(typeName) && e.get_Parameter(BuiltInParameter.SYMBOL_FAMILY_NAME_PARAM).AsString().Equals(familyName)) { elem = e; break ; } } return elem; } // 过滤 // FindSpecialElements(doc, typeof(FamilySymbol), BuiltInCategory.OST_Doors); public IList < Element > FindSpecialElements(Document doc, Type targetType, BuiltInCategory catagory) { FilteredElementCollector collector = new FilteredElementCollector(doc); collector.OfClass(targetType); if (collector != null ) collector.OfCategory(catagory); IList < Element > elements = collector.ToElements(); return elements; }}