protected override void TrySolveInstance(IGH_DataAccess DA) { DB.Element element = null; if (!DA.GetData("Element", ref element)) { return; } string parameterName = null; bool noFilterName = (!DA.GetData("Name", ref parameterName) && Params.Input[1].Sources.Count == 0); var builtInParameterGroup = DB.BuiltInParameterGroup.INVALID; bool noFilterGroup = (!DA.GetData("Group", ref builtInParameterGroup) && Params.Input[2].Sources.Count == 0); bool readOnly = false; bool noFilterReadOnly = (!DA.GetData("ReadOnly", ref readOnly) && Params.Input[3].Sources.Count == 0); List <DB.Parameter> parameters = null; if (element is object) { parameters = new List <DB.Parameter>(element.Parameters.Size); foreach (var group in element.GetParameters(DBX.ParameterClass.Any).GroupBy((x) => x.Definition?.ParameterGroup ?? DB.BuiltInParameterGroup.INVALID).OrderBy((x) => x.Key)) { foreach (var param in group.OrderBy(x => x.Id.IntegerValue)) { if (!noFilterName && parameterName != param.Definition?.Name) { continue; } if (!noFilterGroup && builtInParameterGroup != (param.Definition?.ParameterGroup ?? DB.BuiltInParameterGroup.INVALID)) { continue; } if (!noFilterReadOnly && readOnly != param.IsReadOnly) { continue; } parameters.Add(param); } } } DA.SetDataList("Parameters", parameters); }
//set specified parameter as double for the given element public static bool setParameterValueAsDouble(Autodesk.Revit.DB.Element curElem, string paramName, double newValue) { //bool functionReturnValue = false; Autodesk.Revit.DB.Parameter curParam = curElem.GetParameters(paramName).First(); try { curParam.Set(newValue); return(true); //return functionReturnValue; } catch (Exception ex) { //error TaskDialog.Show("Error", "Could not change parameter value"); } return(false); //return functionReturnValue; }
public static void CopyParametersFrom(this Autodesk.Revit.DB.Element to, Autodesk.Revit.DB.Element from, ICollection <BuiltInParameter> parametersMask = null) { if (from != null && to != null) { foreach (var previousParameter in from.GetParameters(ParameterSource.Any)) { using (previousParameter) using (var param = to.get_Parameter(previousParameter.Definition)) { if (param == null || param.IsReadOnly) { continue; } if (parametersMask != null) { if (param.Definition is InternalDefinition internalDefinition) { if (parametersMask.Contains(internalDefinition.BuiltInParameter)) { continue; } } } switch (previousParameter.StorageType) { case StorageType.Integer: param.Set(previousParameter.AsInteger()); break; case StorageType.Double: param.Set(previousParameter.AsDouble()); break; case StorageType.String: param.Set(previousParameter.AsString()); break; case StorageType.ElementId: param.Set(previousParameter.AsElementId()); break; } } } } }