public DB.Parameter GetParameter(DB.Element element) { if (ParameterSharedGUID.HasValue) { return(element.get_Parameter(ParameterSharedGUID.Value)); } if (ParameterBuiltInId != DB.BuiltInParameter.INVALID) { return(element.get_Parameter(ParameterBuiltInId)); } return(element.GetParameter(ParameterName, ParameterType, ParameterBinding, ParameterClass)); }
internal static DB.Parameter GetParameter(IGH_ActiveObject obj, DB.Element element, IGH_Goo key) { DB.Parameter parameter = null; switch (key as Types.ParameterKey ?? key.ScriptVariable()) { case Types.ParameterKey parameterKey: if (parameterKey.Document.Equals(element.Document)) { if (Enum.IsDefined(typeof(DB.BuiltInParameter), parameterKey.Id.IntegerValue)) { parameter = element.get_Parameter((DB.BuiltInParameter)parameterKey.Id.IntegerValue); if (parameter is null) { obj.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"Parameter '{DB.LabelUtils.GetLabelFor((DB.BuiltInParameter) parameterKey.Id.IntegerValue)}' not defined in 'Element'"); } } else if (element.Document.GetElement(parameterKey.Id) is DB.ParameterElement parameterElement) { parameter = element.get_Parameter(parameterElement.GetDefinition()); if (parameter is null) { obj.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"Parameter '{parameterElement.Name}' not defined in 'Element'"); } } else { obj.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"Data conversion failed from {key.TypeName} to Revit Parameter element"); } } else { obj.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"'ParameterKey' doesn't belong same document as 'Element'"); } break; case DB.Parameter param: if (param.Element.Document.Equals(element.Document) && param.Element.Id == element.Id) { parameter = param; } else { obj.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"Parameter '{param.Definition.Name}' doesn't belong to 'Element'"); } break; case string parameterName: parameter = element.GetParameter(parameterName, DBX.ParameterClass.Any); if (parameter is null) { obj.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"Parameter '{parameterName}' not defined in 'Element'"); } break; case int parameterId: if (Enum.IsDefined(typeof(DB.BuiltInParameter), parameterId)) { parameter = element.get_Parameter((DB.BuiltInParameter)parameterId); if (parameter is null) { obj.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"Parameter '{DB.LabelUtils.GetLabelFor((DB.BuiltInParameter) parameterId)}' not defined in 'Element'"); } } else if (element.Document.GetElement(new DB.ElementId(parameterId)) is DB.ParameterElement parameterElement) { parameter = element.get_Parameter(parameterElement.GetDefinition()); if (parameter is null) { obj.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"Parameter '{parameterElement.Name}' not defined in 'Element'"); } } else { obj.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"Data conversion failed from {key.TypeName} to Revit Parameter element"); } break; case DB.ElementId parameterElementId: if (Enum.IsDefined(typeof(DB.BuiltInParameter), parameterElementId.IntegerValue)) { parameter = element.get_Parameter((DB.BuiltInParameter)parameterElementId.IntegerValue); if (parameter is null) { obj.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"Parameter '{DB.LabelUtils.GetLabelFor((DB.BuiltInParameter) parameterElementId.IntegerValue)}' not defined in 'Element'"); } } else if (element.Document.GetElement(parameterElementId) is DB.ParameterElement parameterElement) { parameter = element.get_Parameter(parameterElement.GetDefinition()); if (parameter is null) { obj.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"Parameter '{parameterElement.Name}' not defined in 'Element'"); } } else { obj.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"Data conversion failed from {key.TypeName} to Revit Parameter element"); } break; case Guid guid: parameter = element.get_Parameter(guid); if (parameter is null) { obj.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"Parameter '{guid}' not defined in 'Element'"); } break; default: obj.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"Data conversion failed from {key.TypeName} to Revit Parameter element"); break; } return(parameter); }