/// <summary> /// Method to retrieve parameters from element according to storage type /// </summary> /// <param name="doc"></param> /// <param name="category"></param> /// <returns></returns> public static Parameter[] GetParametersOfCategoryByStorageType(Document doc, BuiltInCategory category) { List <Parameter> parameters = new List <Parameter>(); Element element = new FilteredElementCollector(doc).OfCategory(category).WhereElementIsNotElementType().FirstElement(); if (element != null) { ParameterSet parameterSet = element.Parameters; ParameterSetIterator paramIt = parameterSet.ForwardIterator(); paramIt.Reset(); while (paramIt.MoveNext()) { Parameter param = paramIt.Current as Parameter; if (param.StorageType == StorageType.String && param.IsReadOnly == false) { parameters.Add(param); } } return(parameters.ToArray()); } else { return(null); } }
/// <summary> /// Gets the parameter by name from an element. /// </summary> /// <param name="element"> /// The element. /// </param> /// <param name="propertyName"> /// The property name. /// </param> /// <returns> /// The Parameter. /// </returns> static Parameter getParameterFromName(Element element, string propertyName) { ParameterSet parameterIds = element.Parameters; if (parameterIds.Size == 0) { return(null); } IList <Parameter> parameters = new List <Parameter>(); IList <Definition> paramDefinitions = new List <Definition>(); // We will do two passes. In the first pass, we will look at parameters in the IFC group. // In the second pass, we will look at all other groups. ParameterSetIterator parameterIt = parameterIds.ForwardIterator(); while (parameterIt.MoveNext()) { Parameter parameter = parameterIt.Current as Parameter; Definition paramDefinition = parameter.Definition; if (paramDefinition == null) { continue; } if (paramDefinition.ParameterGroup != BuiltInParameterGroup.PG_IFC) { parameters.Add(parameter); paramDefinitions.Add(paramDefinition); continue; } if (NamingUtil.IsEqualIgnoringCaseAndSpaces(paramDefinition.Name, propertyName)) { return(parameter); } } int size = paramDefinitions.Count; for (int ii = 0; ii < size; ii++) { if (NamingUtil.IsEqualIgnoringCaseAndSpaces(paramDefinitions[ii].Name, propertyName)) { return(parameters[ii]); } } return(null); }
/// <summary> /// Method to retrieve instance parameters of an instance /// </summary> /// <param name="element"></param> /// <returns></returns> public static Parameter[] GetParametersOfInstance(Element element) { List <Parameter> parameters = new List <Parameter>(); ParameterSet parameterSet = element.Parameters; ParameterSetIterator paramIt = parameterSet.ForwardIterator(); paramIt.Reset(); while (paramIt.MoveNext()) { Parameter param = paramIt.Current as Parameter; if (param.StorageType == StorageType.String && param.IsReadOnly == false) { parameters.Add(param); } } return(parameters.ToArray()); }
/// <summary> /// Cache the parameters for an element, allowing quick access later. /// </summary> /// <param name="id">The element id.</param> static private void CacheParametersForElement(ElementId id) { if (id == ElementId.InvalidElementId) { return; } if (m_NonIFCParameters.ContainsKey(id)) { return; } IDictionary <BuiltInParameterGroup, ParameterElementCache> nonIFCParameters = new SortedDictionary <BuiltInParameterGroup, ParameterElementCache>(); ParameterElementCache ifcParameters = new ParameterElementCache(); m_NonIFCParameters[id] = nonIFCParameters; m_IFCParameters[id] = ifcParameters; Element element = ExporterCacheManager.Document.GetElement(id); if (element == null) { return; } ParameterSet parameterIds = element.Parameters; if (parameterIds.Size == 0) { return; } // We will do two passes. In the first pass, we will look at parameters in the IFC group. // In the second pass, we will look at all other groups. ParameterSetIterator parameterIt = parameterIds.ForwardIterator(); while (parameterIt.MoveNext()) { Parameter parameter = parameterIt.Current as Parameter; if (parameter == null) { continue; } if (IsDuplicateParameter(parameter)) { continue; } Definition paramDefinition = parameter.Definition; if (paramDefinition == null) { continue; } // Don't cache parameters that aren't visible to the user. InternalDefinition internalDefinition = paramDefinition as InternalDefinition; if (internalDefinition != null && internalDefinition.Visible == false) { continue; } if (string.IsNullOrWhiteSpace(paramDefinition.Name)) { continue; } string cleanPropertyName = NamingUtil.RemoveSpaces(paramDefinition.Name); BuiltInParameterGroup groupId = paramDefinition.ParameterGroup; if (groupId != BuiltInParameterGroup.PG_IFC) { ParameterElementCache cacheForGroup = null; if (!nonIFCParameters.TryGetValue(groupId, out cacheForGroup)) { cacheForGroup = new ParameterElementCache(); nonIFCParameters[groupId] = cacheForGroup; } cacheForGroup.ParameterCache[cleanPropertyName] = parameter; } else { ifcParameters.ParameterCache[cleanPropertyName] = parameter; } } }
/// <summary> /// Cache the parameters for an element, allowing quick access later. /// </summary> /// <param name="id">The element id.</param> static private void CacheParametersForElement(ElementId id) { if (id == ElementId.InvalidElementId) { return; } if (m_NonIFCParameters.ContainsKey(id)) { return; } IDictionary <BuiltInParameterGroup, ParameterElementCache> nonIFCParameters = new SortedDictionary <BuiltInParameterGroup, ParameterElementCache>(); ParameterElementCache ifcParameters = new ParameterElementCache(); m_NonIFCParameters[id] = nonIFCParameters; m_IFCParameters[id] = ifcParameters; Element element = ExporterCacheManager.Document.GetElement(id); if (element == null) { return; } ParameterSet parameterIds = element.Parameters; if (parameterIds.Size == 0) { return; } // We will do two passes. In the first pass, we will look at parameters in the IFC group. // In the second pass, we will look at all other groups. ParameterSetIterator parameterIt = parameterIds.ForwardIterator(); while (parameterIt.MoveNext()) { Parameter parameter = parameterIt.Current as Parameter; if (parameter == null) { continue; } if (IsDuplicateParameter(parameter)) { continue; } Definition paramDefinition = parameter.Definition; if (paramDefinition == null) { continue; } // Don't cache parameters that aren't visible to the user. InternalDefinition internalDefinition = paramDefinition as InternalDefinition; if (internalDefinition != null && internalDefinition.Visible == false) { continue; } if (string.IsNullOrWhiteSpace(paramDefinition.Name)) { continue; } string cleanPropertyName = NamingUtil.RemoveSpaces(paramDefinition.Name); BuiltInParameterGroup groupId = paramDefinition.ParameterGroup; ParameterElementCache cacheForGroup = null; if (groupId != BuiltInParameterGroup.PG_IFC) { if (!nonIFCParameters.TryGetValue(groupId, out cacheForGroup)) { cacheForGroup = new ParameterElementCache(); nonIFCParameters[groupId] = cacheForGroup; } } else { cacheForGroup = ifcParameters; } if (cacheForGroup != null) { // We may have situations (due to bugs) where a parameter with the same name appears multiple times. // In this case, we will preserve the first parameter with a value. // Note that this can still cause inconsistent behavior in the case where multiple parameters with the same // name have values, and we should warn about that when we start logging. if (!cacheForGroup.ParameterCache.ContainsKey(cleanPropertyName) || !cacheForGroup.ParameterCache[cleanPropertyName].HasValue) { cacheForGroup.ParameterCache[cleanPropertyName] = parameter; } } } }