private static ParameterMapProperties GetParameterMapProperties(Document doc, Entity entity) { ParameterMapProperties pmp = null; try { string spatialCategoryName = entity.Get <string>(m_schema.GetField(s_SpatialCategory)); string spatialParameterName = entity.Get <string>(m_schema.GetField(s_SpatialParameter)); string revitCategoryName = entity.Get <string>(m_schema.GetField(s_RevitCategory)); string revitParameterName = entity.Get <string>(m_schema.GetField(s_RevitParameter)); Category spatialCategory = doc.Settings.Categories.get_Item(spatialCategoryName); Category revitCategory = doc.Settings.Categories.get_Item(revitCategoryName); if (null != spatialCategory && null != revitCategory) { CategoryProperties scp = new CategoryProperties(spatialCategory); CategoryProperties rcp = new CategoryProperties(revitCategory); ParameterProperties spp = new ParameterProperties(spatialParameterName); ParameterProperties rpp = new ParameterProperties(revitParameterName); pmp = new ParameterMapProperties(spp, rpp, scp, rcp); } } catch (Exception ex) { MessageBox.Show("Failed to get parameter map properties.\n" + ex.Message, "Get Parameter Map Properties", MessageBoxButton.OK, MessageBoxImage.Warning); } return(pmp); }
public ParameterProperties(ParameterProperties pp) { this.ParameterObj = pp.ParameterObj; this.ParameterName = pp.ParameterName; this.ParamType = pp.ParamType; this.ParamId = pp.ParamId; this.BltParameter = pp.BltParameter; this.IsInstance = pp.IsInstance; this.IsReadOnly = pp.IsReadOnly; this.IsSelectable = pp.IsSelectable; this.TextColor = pp.TextColor; }
private Dictionary <string, Dictionary <string, ParameterProperties> > GetProjectParameters() { Dictionary <string, Dictionary <string, ParameterProperties> > paramDictionary = new Dictionary <string, Dictionary <string, ParameterProperties> >(); try { BindingMap bindingMap = m_doc.ParameterBindings; DefinitionBindingMapIterator iterator = bindingMap.ForwardIterator(); while (iterator.MoveNext()) { Definition definition = iterator.Key as Definition; string paramName = definition.Name; ElementBinding binding = iterator.Current as ElementBinding; ParameterProperties pp = new ParameterProperties(); pp.ParameterName = paramName; if (binding is InstanceBinding) { pp.IsInstance = true; } else if (binding is TypeBinding) { pp.IsInstance = false; } foreach (Category category in binding.Categories) { if (!string.IsNullOrEmpty(category.Name)) { if (!paramDictionary.ContainsKey(category.Name)) { Dictionary <string, ParameterProperties> dictionary = new Dictionary <string, ParameterProperties>(); dictionary.Add(pp.ParameterName, pp); paramDictionary.Add(category.Name, dictionary); } else { if (!paramDictionary[category.Name].ContainsKey(pp.ParameterName)) { paramDictionary[category.Name].Add(pp.ParameterName, pp); } } } } } } catch (Exception ex) { MessageBox.Show("Failed to get project parameters\n" + ex.Message, "Get Project Parameters", MessageBoxButton.OK, MessageBoxImage.Warning); } return(paramDictionary); }
public ParameterMapProperties(ParameterProperties spp, ParameterProperties rpp, CategoryProperties scp, CategoryProperties rcp) { spatialParameter = spp; spatialParamName = spp.ParameterName; revitParameter = rpp; revitParamName = rpp.ParameterName; spatialCategory = scp; spatialCatName = scp.CategoryName; revitCategory = rcp; revitCatName = rcp.CategoryName; }
private void buttonAdd_Click(object sender, RoutedEventArgs e) { try { if (null != dataGridSpatial.SelectedItem && null != dataGridRevit.SelectedItem) { ParameterProperties spp = (ParameterProperties)dataGridSpatial.SelectedItem; ParameterProperties rpp = (ParameterProperties)dataGridRevit.SelectedItem; if (rpp.IsSelectable) { CategoryProperties scp = (CategoryProperties)comboBoxSpace.SelectedItem; CategoryProperties rcp = (CategoryProperties)comboBoxRevit.SelectedItem; ParameterMapProperties pmp = new ParameterMapProperties(spp, rpp, scp, rcp); var properties = from property in parameterMapList where property.SpatialCatName == scp.CategoryName && property.RevitCatName == rcp.CategoryName && property.SpatialParamName == spp.ParameterName && property.RevitParamName == rpp.ParameterName select property; if (properties.Count() == 0) { parameterMapList.Add(pmp); dataGridParamMap.ItemsSource = null; dataGridParamMap.ItemsSource = parameterMapList; } else { MessageBox.Show("The selected parameter map already exist in the selsction.\nPlease select different categories and paraemters.", "Existing Maps", MessageBoxButton.OK, MessageBoxImage.Warning); } } else { MessageBox.Show("The storage types do not match between spatial and Revit parameters.\nPlease select a valid parameter.", "Storage Type Mismatched", MessageBoxButton.OK, MessageBoxImage.Information); } } else { MessageBox.Show("Please select a pair of parameter from a spatial category and a Revit category.", "Parameter Not Selected", MessageBoxButton.OK, MessageBoxImage.Information); } } catch (Exception ex) { MessageBox.Show("Failed to add links.\n" + ex.Message, "Add Parameter Maps", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void dataGridSpatial_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { if (null != dataGridSpatial.SelectedItem) { ParameterProperties selectedItem = (ParameterProperties)dataGridSpatial.SelectedItem; StorageType storageType = selectedItem.ParamType; List <ParameterProperties> paramList = dataGridRevit.ItemsSource as List <ParameterProperties>; List <ParameterProperties> parameterList = new List <ParameterProperties>(); if (null != paramList) { foreach (ParameterProperties pp in paramList) { ParameterProperties property = new ParameterProperties(pp); if (property.ParamType == storageType) { property.SetTextColor(true); } else { property.SetTextColor(false); } parameterList.Add(property); } } dataGridRevit.ItemsSource = null; dataGridRevit.ItemsSource = parameterList; } } catch (Exception ex) { MessageBox.Show("Failed to select a parameter in spatial elements.\n" + ex.Message, "Spatial Parameters Selection", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private Dictionary <string, ParameterProperties> GetParameterProperties(Category category) { Dictionary <string, ParameterProperties> paramDictionary = new Dictionary <string, ParameterProperties>(); try { Element firstElement = null; ElementType firstTypeElement = null; FilteredElementCollector collector = new FilteredElementCollector(m_doc); List <Element> elements = collector.OfCategoryId(category.Id).WhereElementIsNotElementType().ToElements().ToList(); if (elements.Count > 0) { firstElement = elements.First(); firstTypeElement = m_doc.GetElement(firstElement.GetTypeId()) as ElementType; } else { return(paramDictionary); } List <ElementId> categoryIds = new List <ElementId>(); categoryIds.Add(category.Id); //add builtIn Parameter ICollection <ElementId> supportedParams = ParameterFilterUtilities.GetFilterableParametersInCommon(m_doc, categoryIds); foreach (ElementId eId in supportedParams) { if (eId.IntegerValue < 0) { BuiltInParameter bltParam = (BuiltInParameter)eId.IntegerValue; string paramName = LabelUtils.GetLabelFor(bltParam); if (paramName.Contains("Extensions.")) { continue; } ParameterProperties pp = null; Parameter param = firstElement.LookupParameter(paramName); if (null != param) { pp = new ParameterProperties(param); pp.IsInstance = true; pp.BltParameter = bltParam; if (!paramDictionary.ContainsKey(pp.ParameterName)) { paramDictionary.Add(pp.ParameterName, pp); } } else if (null != firstTypeElement) { param = firstTypeElement.LookupParameter(paramName); if (null != param) { pp = new ParameterProperties(param); pp.IsInstance = false; pp.BltParameter = bltParam; if (!paramDictionary.ContainsKey(pp.ParameterName)) { paramDictionary.Add(pp.ParameterName, pp); } } } } } //add project parameter if (projectParameters.ContainsKey(category.Name)) { Dictionary <string, ParameterProperties> dictionary = projectParameters[category.Name]; foreach (string paramName in dictionary.Keys) { if (paramName.Contains("Extensions.")) { continue; } ParameterProperties property = dictionary[paramName]; if (property.IsInstance && null != firstTypeElement) { Parameter param = firstElement.LookupParameter(property.ParameterName); if (null != param) { ParameterProperties pp = new ParameterProperties(param); pp.IsInstance = true; if (!paramDictionary.ContainsKey(pp.ParameterName)) { paramDictionary.Add(pp.ParameterName, pp); } } } else if (null != firstTypeElement) { Parameter param = firstTypeElement.LookupParameter(property.ParameterName); if (null != param) { ParameterProperties pp = new ParameterProperties(param); pp.IsInstance = false; if (!paramDictionary.ContainsKey(pp.ParameterName)) { paramDictionary.Add(pp.ParameterName, pp); } } } } } //add family parameter //sorting collector = new FilteredElementCollector(m_doc); ICollection <ElementId> familyInstanceIds = collector.OfCategoryId(category.Id).OfClass(typeof(FamilyInstance)).ToElementIds(); collector = new FilteredElementCollector(m_doc); List <FamilySymbol> familySymbols = collector.OfCategoryId(category.Id).OfClass(typeof(FamilySymbol)).ToElements().Cast <FamilySymbol>().ToList(); List <string> familyNames = new List <string>(); if (familyInstanceIds.Count > 0) { foreach (FamilySymbol symbol in familySymbols) { string familyName = symbol.Family.Name; if (!string.IsNullOrEmpty(familyName)) { if (!familyNames.Contains(familyName)) { FamilyInstanceFilter instanceFilter = new FamilyInstanceFilter(m_doc, symbol.Id); collector = new FilteredElementCollector(m_doc, familyInstanceIds); List <Element> familyInstances = collector.WherePasses(instanceFilter).ToElements().ToList(); if (familyInstances.Count > 0) { FamilyInstance firstFamilyInstance = familyInstances.First() as FamilyInstance; foreach (Parameter param in firstFamilyInstance.Parameters) { if (param.Id.IntegerValue > 0) { ParameterProperties pp = new ParameterProperties(param); pp.IsInstance = true; if (!paramDictionary.ContainsKey(pp.ParameterName) && !pp.ParameterName.Contains("Extensions.")) { paramDictionary.Add(pp.ParameterName, pp); } } } FamilySymbol firstFamilySymbol = firstFamilyInstance.Symbol; foreach (Parameter param in firstFamilySymbol.Parameters) { if (param.Id.IntegerValue > 0) { ParameterProperties pp = new ParameterProperties(param); pp.IsInstance = false; if (!paramDictionary.ContainsKey(pp.ParameterName) && !pp.ParameterName.Contains("Extensions.")) { paramDictionary.Add(pp.ParameterName, pp); } } } } familyNames.Add(familyName); } } } } } catch (Exception ex) { MessageBox.Show("Failed to get parameter properties.\n" + ex.Message, "Get Parameter Properties", MessageBoxButton.OK, MessageBoxImage.Warning); } return(paramDictionary); }