private static void _transferParameters(RevitElem SourceElement, RevitElem DestinationElement) { RevitDB.ParameterSet sourceParameters = SourceElement.Parameters; foreach (RevitDB.Parameter sourceParam in sourceParameters) { if (sourceParam.IsReadOnly == false) { RevitDB.Definition def = sourceParam.Definition; RevitDB.Parameter destinationParam = DestinationElement.get_Parameter(def); RevitDB.StorageType st = sourceParam.StorageType; switch (st) { case RevitDB.StorageType.Double: destinationParam.Set(sourceParam.AsDouble()); break; case RevitDB.StorageType.ElementId: destinationParam.Set(sourceParam.AsElementId()); break; case RevitDB.StorageType.Integer: destinationParam.Set(sourceParam.AsInteger()); break; case RevitDB.StorageType.String: destinationParam.Set(sourceParam.AsString()); break; } } } }
public static string get_ParameterByString(Element e, string lookup) { string aString = ""; bool found = false; ParameterSetIterator i = e.Parameters.ForwardIterator(); i.Reset(); bool iMoreAttribute = i.MoveNext(); while (iMoreAttribute) { object o = i.Current; Parameter familyAttribute = o as Parameter; //find the parameter whose name is same to the given parameter name Autodesk.Revit.DB.StorageType st = familyAttribute.StorageType; switch (st) { //get the storage type case StorageType.String: if (familyAttribute.Definition.Name == lookup) { //make conversion between degrees and radians aString = familyAttribute.AsString(); found = true; } break; } if (found) { break; } else { iMoreAttribute = i.MoveNext(); } } return(aString); }
public Autodesk.Revit.UI.Result Execute( ExternalCommandData revit, ref string message, ElementSet elements) { try { // Get the active document and view UIDocument revitDoc = revit.Application.ActiveUIDocument; Autodesk.Revit.DB.View view = revitDoc.Document.ActiveView; foreach (Autodesk.Revit.DB.Element elem in revitDoc.Selection.Elements) { //if( elem.GetType() == typeof( Autodesk.Revit.DB.Structure.Rebar ) ) if (elem is Rebar) { string str = ""; Autodesk.Revit.DB.Structure.Rebar rebar = (Autodesk.Revit.DB.Structure.Rebar)elem; ParameterSet pars = rebar.Parameters; foreach (Parameter param in pars) { string val = ""; string name = param.Definition.Name; Autodesk.Revit.DB.StorageType type = param.StorageType; switch (type) { case Autodesk.Revit.DB.StorageType.Double: val = param.AsDouble().ToString(); break; case Autodesk.Revit.DB.StorageType.ElementId: Autodesk.Revit.DB.ElementId id = param.AsElementId(); Autodesk.Revit.DB.Element paraElem = revitDoc.Document.get_Element(id); if (paraElem != null) { val = paraElem.Name; } break; case Autodesk.Revit.DB.StorageType.Integer: val = param.AsInteger().ToString(); break; case Autodesk.Revit.DB.StorageType.String: val = param.AsString(); break; default: break; } str = str + name + ": " + val + "\r\n"; } MessageBox.Show(str, "Rebar parameters"); return(Autodesk.Revit.UI.Result.Succeeded); } } message = "No rebar selected!"; return(Autodesk.Revit.UI.Result.Failed); } catch (Exception e) { message = e.Message; return(Autodesk.Revit.UI.Result.Failed); } }
/// <summary> /// get the parameter value according given parameter name /// </summary> public string FindParameter(string parameterName, FamilyInstance familyInstanceName) { ParameterSetIterator i = familyInstanceName.Parameters.ForwardIterator(); i.Reset(); string valueOfParameter = null; bool iMoreAttribute = i.MoveNext(); while (iMoreAttribute) { bool isFound = false; object o = i.Current; Parameter familyAttribute = o as Parameter; if (familyAttribute.Definition.Name == parameterName) { //find the parameter whose name is same to the given parameter name Autodesk.Revit.DB.StorageType st = familyAttribute.StorageType; switch (st) { //get the storage type case StorageType.Double: if (parameterName.Equals(AngleDefinitionName)) { //make conversion between degrees and radians Double temp = familyAttribute.AsDouble(); valueOfParameter = Math.Round(temp * 180 / (Math.PI), 3).ToString(); } else { valueOfParameter = familyAttribute.AsDouble().ToString(); } break; case StorageType.ElementId: //get Autodesk.Revit.DB.ElementId as string valueOfParameter = familyAttribute.AsElementId().ToString(); break; case StorageType.Integer: //get Integer as string valueOfParameter = familyAttribute.AsInteger().ToString(); break; case StorageType.String: //get string valueOfParameter = familyAttribute.AsString(); break; case StorageType.None: valueOfParameter = familyAttribute.AsValueString(); break; default: break; } isFound = true; } if (isFound) { break; } iMoreAttribute = i.MoveNext(); } //return the value. return(valueOfParameter); }
public void createCountSchedule(String name, ElementId elementId) { ViewSchedule schedule = new FilteredElementCollector(CachedDoc).OfClass(typeof(ViewSchedule)).Where(x => x.Name == name + " Schedule").FirstOrDefault() as ViewSchedule; if (schedule == null) { Transaction tSchedule = new Transaction(CachedDoc, "Create Schedule"); tSchedule.Start(); //Create an empty view schedule for doors. //schedule = ViewSchedule.CreateSchedule(CachedDoc, new ElementId(BuiltInCategory.INVALID), ElementId.InvalidElementId); schedule = ViewSchedule.CreateSchedule(CachedDoc, elementId, ElementId.InvalidElementId); schedule.Name = name + " Schedule"; ElementId keynoteId = new ElementId(BuiltInParameter.KEYNOTE_PARAM); //Iterate all the schedulable fields gotten from the doors view schedule. foreach (SchedulableField schedulableField in schedule.Definition.GetSchedulableFields()) { //See if the FieldType is ScheduleFieldType.Instance. if (schedulableField.FieldType == ScheduleFieldType.Count || schedulableField.ParameterId == keynoteId) { //Get ParameterId of SchedulableField. ElementId parameterId = schedulableField.ParameterId; //Add a new schedule field to the view schedule by using the SchedulableField as argument of AddField method of Autodesk.Revit.DB.ScheduleDefinition class. ScheduleField field = schedule.Definition.AddField(schedulableField); //See if the parameterId is a BuiltInParameter. if (Enum.IsDefined(typeof(BuiltInParameter), parameterId.IntegerValue)) { BuiltInParameter bip = (BuiltInParameter)parameterId.IntegerValue; //Get the StorageType of BuiltInParameter. Autodesk.Revit.DB.StorageType st = CachedDoc.get_TypeOfStorage(bip); //if StorageType is String or ElementId, set GridColumnWidth of schedule field to three times of current GridColumnWidth. //And set HorizontalAlignment property to left. if (st == Autodesk.Revit.DB.StorageType.String || st == Autodesk.Revit.DB.StorageType.ElementId) { field.GridColumnWidth = 3 * field.GridColumnWidth; field.HorizontalAlignment = ScheduleHorizontalAlignment.Left; } //For other StorageTypes, set HorizontalAlignment property to center. else { field.HorizontalAlignment = ScheduleHorizontalAlignment.Center; } } if (field.ParameterId == keynoteId) { ScheduleSortGroupField sortGroupField = new ScheduleSortGroupField(field.FieldId); schedule.Definition.AddSortGroupField(sortGroupField); schedule.Definition.IsItemized = false; } if (schedulableField.FieldType == ScheduleFieldType.Count) { } } } tSchedule.Commit(); tSchedule.Dispose(); } else { schedule.RefreshData(); } ViewScheduleExportOptions opt = new ViewScheduleExportOptions(); opt.FieldDelimiter = ","; opt.Title = false; string path = _export_folder_name; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string file = System.IO.Path.GetFileNameWithoutExtension(name) + ".csv"; schedule.Export(path, file, opt); }
public void createMaterialTakeOffSchedule(String name, ElementId elementId) { //Get UIDocument UIDocument uidoc = _cachedCmdData.Application.ActiveUIDocument; //Get Document Document doc = uidoc.Document; ViewSchedule schedule = new FilteredElementCollector(CachedDoc).OfClass(typeof(ViewSchedule)).Where(x => x.Name == name + " Schedule").FirstOrDefault() as ViewSchedule; if (schedule == null) { Transaction tSchedule = new Transaction(CachedDoc, "Create Schedule"); tSchedule.Start(); //Create an empty view schedule for doors. schedule = ViewSchedule.CreateMaterialTakeoff(CachedDoc, elementId); schedule.Name = name + " Schedule"; ElementId volumeId = new ElementId(BuiltInParameter.MATERIAL_VOLUME); ElementId areaId = new ElementId(BuiltInParameter.MATERIAL_AREA); //Iterate all the schedulable fields gotten from the doors view schedule. foreach (SchedulableField schedulableField in schedule.Definition.GetSchedulableFields()) { //See if the FieldType is ScheduleFieldType.Instance. if (schedulableField.ParameterId == volumeId || schedulableField.ParameterId == areaId || schedulableField.GetName(doc).Equals("Material: Keynote")) { //Get ParameterId of SchedulableField. ElementId parameterId = schedulableField.ParameterId; //Add a new schedule field to the view schedule by using the SchedulableField as argument of AddField method of Autodesk.Revit.DB.ScheduleDefinition class. ScheduleField field = schedule.Definition.AddField(schedulableField); //See if the parameterId is a BuiltInParameter. if (Enum.IsDefined(typeof(BuiltInParameter), parameterId.IntegerValue)) { BuiltInParameter bip = (BuiltInParameter)parameterId.IntegerValue; //Get the StorageType of BuiltInParameter. Autodesk.Revit.DB.StorageType st = CachedDoc.get_TypeOfStorage(bip); //if StorageType is String or ElementId, set GridColumnWidth of schedule field to three times of current GridColumnWidth. //And set HorizontalAlignment property to left. if (st == Autodesk.Revit.DB.StorageType.String || st == Autodesk.Revit.DB.StorageType.ElementId) { field.GridColumnWidth = 3 * field.GridColumnWidth; field.HorizontalAlignment = ScheduleHorizontalAlignment.Left; } //For other StorageTypes, set HorizontalAlignment property to center. else { field.HorizontalAlignment = ScheduleHorizontalAlignment.Center; } } if (schedulableField.GetName(doc).Equals("Material: Keynote")) { ScheduleSortGroupField sortGroupField = new ScheduleSortGroupField(field.FieldId); schedule.Definition.AddSortGroupField(sortGroupField); schedule.Definition.IsItemized = false; } if (field.ParameterId == volumeId) { FormatOptions formatOpt = new FormatOptions(DisplayUnitType.DUT_CUBIC_FEET, UnitSymbolType.UST_CF, 0.01); formatOpt.UseDefault = false; field.SetFormatOptions(formatOpt); field.DisplayType = ScheduleFieldDisplayType.Totals; } if (field.ParameterId == areaId) { FormatOptions formatOpt = new FormatOptions(DisplayUnitType.DUT_SQUARE_FEET, UnitSymbolType.UST_SF, 0.01); formatOpt.UseDefault = false; field.SetFormatOptions(formatOpt); field.DisplayType = ScheduleFieldDisplayType.Totals; } } } tSchedule.Commit(); tSchedule.Dispose(); } else { schedule.RefreshData(); } ViewScheduleExportOptions opt = new ViewScheduleExportOptions(); opt.FieldDelimiter = ","; opt.Title = false; string path = _export_folder_name; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string file = System.IO.Path.GetFileNameWithoutExtension(name) + ".csv"; schedule.Export(path, file, opt); }
static bool TryGetParameterDefinition(DB.Document doc, DB.ElementId id, out DB.StorageType storageType, out DB.ParameterType parameterType) { if (id.TryGetBuiltInParameter(out var builtInParameter)) { storageType = doc.get_TypeOfStorage(builtInParameter); if (storageType == DB.StorageType.ElementId) { if (builtInParameter == DB.BuiltInParameter.ELEM_TYPE_PARAM) { parameterType = DB.ParameterType.FamilyType; return(true); } if (builtInParameter == DB.BuiltInParameter.ELEM_CATEGORY_PARAM || builtInParameter == DB.BuiltInParameter.ELEM_CATEGORY_PARAM_MT) { parameterType = (DB.ParameterType) int.MaxValue; return(true); } } if (storageType == DB.StorageType.Double) { if (BuiltInParametersTypes.TryGetValue(builtInParameter, out parameterType)) { return(true); } var categoriesWhereDefined = doc.GetBuiltInCategoriesWithParameters(). Select(bic => new DB.ElementId(bic)). Where(cid => DB.TableView.GetAvailableParameters(doc, cid).Contains(id)). ToArray(); using (var collector = new DB.FilteredElementCollector(doc)) { using ( var filteredCollector = categoriesWhereDefined.Length == 0 ? collector.WherePasses(new DB.ElementClassFilter(typeof(DB.ParameterElement), false)) : categoriesWhereDefined.Length > 1 ? collector.WherePasses(new DB.ElementMulticategoryFilter(categoriesWhereDefined)) : collector.WherePasses(new DB.ElementCategoryFilter(categoriesWhereDefined[0])) ) { foreach (var element in filteredCollector) { var parameter = element.get_Parameter(builtInParameter); if (parameter is null) { continue; } parameterType = parameter.Definition.ParameterType; BuiltInParametersTypes.Add(builtInParameter, parameterType); return(true); } } } parameterType = DB.ParameterType.Invalid; return(false); } parameterType = DB.ParameterType.Invalid; return(true); } else { try { if (doc.GetElement(id) is DB.ParameterElement parameter) { storageType = parameter.GetDefinition().ParameterType.ToStorageType(); parameterType = parameter.GetDefinition().ParameterType; return(true); } } catch (Autodesk.Revit.Exceptions.InvalidOperationException) { } } storageType = DB.StorageType.None; parameterType = DB.ParameterType.Invalid; return(false); }