public override bool Equals(object obj) { ParameterData otherParameter = obj as ParameterData; if (otherParameter == null) { return(false); } return(_parameter.Id.Equals(otherParameter._parameter.Id)); }
private void GroupingParameters(int groupingType) { lvParameters.Groups.Clear(); foreach (ListViewItem item in lvParameters.Items) { ParameterData parameterData = item.Tag as ParameterData; if (parameterData == null) { continue; } switch (groupingType) { case 1: if ("Y" == parameterData.ContainedInCollection) { item.Group = GetListViewGroupForParameter(item.ListView, "Parameter in Element.Parameters collection"); } else { item.Group = GetListViewGroupForParameter(item.ListView, "Parameter retrieving via Element.get_Parameter(BuiltInParameter)"); } break; case 2: item.Group = GetListViewGroupForParameter(item.ListView, parameterData.Type); break; case 3: item.Group = GetListViewGroupForParameter(item.ListView, parameterData.ReadWrite); break; case 4: item.Group = GetListViewGroupForParameter(item.ListView, parameterData.GroupName); break; } } }
/// <summary> /// Revit external command to list all valid /// built-in parameters for a given selected /// element. /// </summary> public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; // Select element var element = Util.GetSingleSelectedElementOrPrompt(uidoc); if (element == null) { return(Result.Cancelled); } bool isSymbol = false; // For a family instance, ask user whether to // display instance or type parameters; in a // similar manner, we could add dedicated // switches for Wall --> WallType, // Floor --> FloorType etc. ... if (element is FamilyInstance) { var inst = element as FamilyInstance; if (inst.Symbol != null) { var msg = string.Format(_type_prompt, "is a family instance"); if (!Util.QuestionMsg(msg)) { element = inst.Symbol; isSymbol = true; } } } else if (element.CanHaveTypeAssigned()) { ElementId typeId = element.GetTypeId(); if (typeId == null) { Util.InfoMsg("Element can have a type, but the current type is null."); } else if (typeId == ElementId.InvalidElementId) { Util.InfoMsg("Element can have a type, but the current type id is the invalid element id."); } else { Element type = doc.GetElement(typeId); if (type == null) { Util.InfoMsg("Element has a type, but it cannot be accessed."); } else { string msg = string.Format(_type_prompt, "has an element type"); if (!Util.QuestionMsg(msg)) { element = type; isSymbol = true; } } } } // Retrieve parameter data var unique = new HashSet <string>(); var data = new List <ParameterData>(); var set = element.Parameters; var bipNames = Enum.GetNames(typeof(BuiltInParameter)); foreach (var bipName in bipNames) { if (!Enum.TryParse(bipName, out BuiltInParameter bip)) { continue; } var parameter = element.get_Parameter(bip); if (parameter != null) { var valueString = (parameter.StorageType == StorageType.ElementId) ? Util.GetParameterValue2(parameter, doc) : parameter.AsValueString(); var containedInCollection = ContainedInCollection(parameter, set); var parameterData = new ParameterData(bip, parameter, valueString, containedInCollection, bipName); var identifyer = $"{parameterData.Enum}{parameterData.Name}"; if (!unique.Contains(identifyer)) { data.Add(parameterData); unique.Add(identifyer); } } } // Retrieve parameters from Element.Parameters collection foreach (Parameter parameter in element.Parameters) { var valueString = (parameter.StorageType == StorageType.ElementId) ? Util.GetParameterValue2(parameter, doc) : parameter.AsValueString(); var bip = (parameter.Definition as InternalDefinition).BuiltInParameter; var parameterData = new ParameterData(bip, parameter, valueString, true, null); var identifyer = $"{parameterData.Enum}{parameterData.Name}"; if (!unique.Contains(identifyer)) { data.Add(parameterData); unique.Add(identifyer); } } // Display form var description = Util.ElementDescription(element, true) + (isSymbol ? " Type" : " Instance"); var formViewModel = new BipCheckerListViewModel(element, description, data); var form = new BipCheckerListView { DataContext = formViewModel }; form.ShowDialog(); return(Result.Succeeded); }
/// <summary> /// Revit external command to list all valid /// built-in parameters for a given selected /// element. /// </summary> public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements ) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; // Select element Element e = Util.GetSingleSelectedElementOrPrompt( uidoc ); if( null == e ) { return Result.Cancelled; } bool isSymbol = false; // For a family instance, ask user whether to // display instance or type parameters; in a // similar manner, we could add dedicated // switches for Wall --> WallType, // Floor --> FloorType etc. ... if( e is FamilyInstance ) { FamilyInstance inst = e as FamilyInstance; if( null != inst.Symbol ) { string symbol_name = Util.ElementDescription( inst.Symbol, true ); string family_name = Util.ElementDescription( inst.Symbol.Family, true ); string msg = string.Format( _type_prompt, "is a family instance" ); if( !Util.QuestionMsg( msg ) ) { e = inst.Symbol; isSymbol = true; } } } else if( e.CanHaveTypeAssigned() ) { ElementId typeId = e.GetTypeId(); if( null == typeId ) { Util.InfoMsg( "Element can have a type," + " but the current type is null." ); } else if( ElementId.InvalidElementId == typeId ) { Util.InfoMsg( "Element can have a type," + " but the current type id is the" + " invalid element id." ); } else { Element type = doc.GetElement( typeId ); if( null == type ) { Util.InfoMsg( "Element has a type," + " but it cannot be accessed." ); } else { string msg = string.Format( _type_prompt, "has an element type" ); if( !Util.QuestionMsg( msg ) ) { e = type; isSymbol = true; } } } } // Retrieve parameter data SortableBindingList<ParameterData> data = new SortableBindingList<ParameterData>(); { WaitCursor waitCursor = new WaitCursor(); ParameterSet set = e.Parameters; bool containedInCollection; /* * Edited by Chekalin Victor 13.12.2012 * !!! This implemention does not work properly * if enum has the same integer value * For example, BuiltInParameter.All_MODEL_COST and * BuiltInParameter.DOOR_COST have -1001205 integer value * Array bips = Enum.GetValues( typeof( BuiltInParameter ) ); int n = bips.Length; * */ /* * Edited by Chekalin Victor 13.12.2012 */ var bipNames = Enum.GetNames( typeof( BuiltInParameter ) ); Parameter p; /* * Edited by Chekalin Victor 13.12.2012 */ //foreach( BuiltInParameter a in bips ) foreach( var bipName in bipNames ) { BuiltInParameter a; if( !Enum.TryParse( bipName, out a ) ) continue; try { p = e.get_Parameter( a ); #region Check for external definition #if CHECK_FOR_EXTERNAL_DEFINITION Definition d = p.Definition; ExternalDefinition e = d as ExternalDefinition; // this is never possible string guid = ( null == e ) ? null : e.GUID.ToString(); #endif // CHECK_FOR_EXTERNAL_DEFINITION #endregion // Check for external definition if( null != p ) { string valueString = ( StorageType.ElementId == p.StorageType ) ? Util.GetParameterValue2( p, doc ) : p.AsValueString(); //containedInCollection = set.Contains( p ); // this does not work containedInCollection = ContainedInCollection( p, set ); data.Add( new ParameterData( a, p, valueString, containedInCollection, bipName ) ); } } catch( Exception ex ) { Debug.Print( "Exception retrieving built-in parameter {0}: {1}", a, ex ); } } } // Retrieve parameters from Element.Parameters collection foreach( Parameter p in e.Parameters ) { string valueString = ( StorageType.ElementId == p.StorageType ) ? Util.GetParameterValue2( p, doc ) : p.AsValueString(); ParameterData parameterData = new ParameterData( ( p.Definition as InternalDefinition ).BuiltInParameter, p, valueString, true, null ); if( !data.Contains( parameterData ) ) data.Add( parameterData ); } // Display form string description = Util.ElementDescription( e, true ) + ( isSymbol ? " Type" : " Instance" ); #if USE_LIST_VIEW using( BuiltInParamsCheckerFormListView form = new BuiltInParamsCheckerFormListView( e, description, data ) ) #else using (BuiltInParamsCheckerForm form = new BuiltInParamsCheckerForm( description, data)) #endif // USE_LIST_VIEW { form.ShowDialog(); } return Result.Succeeded; }
/// <summary> /// Revit external command to list all valid /// built-in parameters for a given selected /// element. /// </summary> public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; // Select element Element e = Util.GetSingleSelectedElementOrPrompt( uidoc); if (null == e) { return(Result.Cancelled); } bool isSymbol = false; // For a family instance, ask user whether to // display instance or type parameters; in a // similar manner, we could add dedicated // switches for Wall --> WallType, // Floor --> FloorType etc. ... if (e is FamilyInstance) { FamilyInstance inst = e as FamilyInstance; if (null != inst.Symbol) { string symbol_name = Util.ElementDescription( inst.Symbol, true); string family_name = Util.ElementDescription( inst.Symbol.Family, true); string msg = string.Format(_type_prompt, "is a family instance"); if (!Util.QuestionMsg(msg)) { e = inst.Symbol; isSymbol = true; } } } else if (e.CanHaveTypeAssigned()) { ElementId typeId = e.GetTypeId(); if (null == typeId) { Util.InfoMsg("Element can have a type," + " but the current type is null."); } else if (ElementId.InvalidElementId == typeId) { Util.InfoMsg("Element can have a type," + " but the current type id is the" + " invalid element id."); } else { Element type = doc.GetElement(typeId); if (null == type) { Util.InfoMsg("Element has a type," + " but it cannot be accessed."); } else { string msg = string.Format(_type_prompt, "has an element type"); if (!Util.QuestionMsg(msg)) { e = type; isSymbol = true; } } } } // Retrieve parameter data SortableBindingList <ParameterData> data = new SortableBindingList <ParameterData>(); { WaitCursor waitCursor = new WaitCursor(); ParameterSet set = e.Parameters; bool containedInCollection; /* * Edited by Chekalin Victor 13.12.2012 * !!! This implemention does not work properly * if enum has the same integer value * For example, BuiltInParameter.All_MODEL_COST and * BuiltInParameter.DOOR_COST have -1001205 integer value * * Array bips = Enum.GetValues( * typeof( BuiltInParameter ) ); * * int n = bips.Length; * */ /* * Edited by Chekalin Victor 13.12.2012 */ var bipNames = Enum.GetNames(typeof(BuiltInParameter)); Parameter p; /* * Edited by Chekalin Victor 13.12.2012 */ //foreach( BuiltInParameter a in bips ) foreach (var bipName in bipNames) { BuiltInParameter a; if (!Enum.TryParse(bipName, out a)) { continue; } try { p = e.get_Parameter(a); #region Check for external definition #if CHECK_FOR_EXTERNAL_DEFINITION Definition d = p.Definition; ExternalDefinition e = d as ExternalDefinition; // this is never possible string guid = (null == e) ? null : e.GUID.ToString(); #endif // CHECK_FOR_EXTERNAL_DEFINITION #endregion // Check for external definition if (null != p) { string valueString = (StorageType.ElementId == p.StorageType) ? Util.GetParameterValue2(p, doc) : p.AsValueString(); //containedInCollection = set.Contains( p ); // this does not work containedInCollection = ContainedInCollection(p, set); data.Add(new ParameterData(a, p, valueString, containedInCollection, bipName)); } } catch (Exception ex) { Debug.Print( "Exception retrieving built-in parameter {0}: {1}", a, ex); } } } // Retrieve parameters from Element.Parameters collection foreach (Parameter p in e.Parameters) { string valueString = (StorageType.ElementId == p.StorageType) ? Util.GetParameterValue2(p, doc) : p.AsValueString(); ParameterData parameterData = new ParameterData( (p.Definition as InternalDefinition).BuiltInParameter, p, valueString, true, null); if (!data.Contains(parameterData)) { data.Add(parameterData); } } // Display form string description = Util.ElementDescription(e, true) + (isSymbol ? " Type" : " Instance"); #if USE_LIST_VIEW using (BuiltInParamsCheckerFormListView form = new BuiltInParamsCheckerFormListView(e, description, data)) #else using (BuiltInParamsCheckerForm form = new BuiltInParamsCheckerForm( description, data)) #endif // USE_LIST_VIEW { form.ShowDialog(); } return(Result.Succeeded); }