public static global::Revit.Elements.Element SetParameterValueByNameCaSeiNSeNSiTiVe(global::Revit.Elements.Element element, string parameterName, object value) { //check Rhythm version //Rhythm.Utilities.VersionChecker(); Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument; //create a list to hold the element ids and add them to it global::Revit.Elements.Parameter[] elementParams = element.Parameters; string paramToSet = null; //score of each match list List <int> values = new List <int>(); //score the match in the parameter list foreach (var param in elementParams) { values.Add(StringComparisonUtilities.Compute(parameterName, param.Name)); } //get the closest matching parameter name int minIndex = values.IndexOf(values.Min()); paramToSet = elementParams[minIndex].Name; //Convert to a usable value var dynval = value as dynamic; TransactionManager.Instance.EnsureInTransaction(doc); //set that thing! var parameterValue = element.SetParameterByName(paramToSet, dynval); TransactionManager.Instance.TransactionTaskDone(); return(element); }
public static global::Revit.Elements.Element SetParameterByNameTypeOrInstance(global::Revit.Elements.Element element, string parameterName, object value) { //create a list to hold the element ids and add them to it Autodesk.Revit.DB.Element internalElement = element.InternalElement; Autodesk.Revit.DB.Document doc = internalElement.Document; //declare variable to assign object paramValue; //looks up the parameter to see if it exists var result = internalElement.LookupParameter(parameterName); //if parameter exists as instance obtain it, otherwise try for type if (result != null) { paramValue = element.SetParameterByName(parameterName, value); } else { paramValue = doc.GetElement(internalElement.GetTypeId()) .ToDSType(true) .SetParameterByName(parameterName, value); } return(element); }