private void SetRevitValue() { //What could go wrong? //1. The Value is already set and we go into circular reference - that should be resolved in the Revit value (skip if we are == value) //2. The UIValue is already set and we go into circular reference ... Value = Utils.GetDutValueTo(StorageType, DisplayUnitType, RevitValue); UIValue = ValueConvertUtils.StringFromDoubleConvert(DisplayUnitType, Precision, Value); if (!_suppres) { RequestHandling.MakeRequest(RequestId.ChangeParam, new Tuple <string, double>(Name, RevitValue)); // Suppres request in case of Shuffle, or mass request (can only make 1 single bulk request at a time) } else { _suppres = false; } }
//Create a checkbox FamilyParameterModel item internal static FamilyParameterModel FamilyParameterItem(FamilyType ft, FamilyParameter fp, List <FamilyParameter> paramLabel, List <FamilyParameter> paramFormula) { //Collect data depending on the type of paramter FamilyParameterModel newItem = new FamilyParameterModel(); //Create new FamilyParamterModel newItem.SuppressUpdate(); //When setting the first time, suppress the back-update coming from the UI because of difference in precision newItem.Name = fp.Definition.Name; //The name of the Parameter newItem.StorageType = fp.StorageType; newItem.ParamType = GetParameterType(fp); newItem.DisplayUnitType = GetDisplayUnitType(fp); //Set the DisplayUnitType for this parameter newItem.Precision = Utils.GetPrecision(newItem.DisplayUnitType); //Properties.Settings.Default.Precision; //The precision set by the User in the Settings newItem.Type = fp.Definition.ParameterType.ToString(); //The parameter type newItem.Associated = !fp.AssociatedParameters.IsEmpty; //If the parameter is being associated newItem.BuiltIn = fp.Id.IntegerValue < 0; newItem.Modifiable = fp.UserModifiable; newItem.Formula = fp.IsDeterminedByFormula; newItem.Label = paramLabel.Any(f => f.Id == fp.Id); newItem.Reporting = fp.IsReporting; newItem.UsedInFormula = paramFormula.Any(f => f.Id == fp.Id); newItem.ReadOnly = fp.IsReadOnly; newItem.Shared = fp.IsShared; newItem.TypeOrInstance = fp.IsInstance ? "Instance" : "Type"; newItem.IsUsed = (newItem.Associated || newItem.Label || newItem.UsedInFormula); //Used if any of the three is true newItem.Editable = newItem.IsUsed && !newItem.Formula && !newItem.Reporting; //If the Parameter is used or if the parameter is not defined by Formula, allow the user to edit newItem.Visible = Properties.Settings.Default.ToggleVisibility; //Set the visibility in the UI (user defined Tag property for ALL Tags, regardless of their specific conditions) newItem.TagVisible = Properties.Settings.Default.ToggleTagsVisibility; //Set the Tags visibility newItem.RevitValue = GetParameterValue(ft, fp); //Set the Revit internal value for the Parameter if (newItem.RevitValue == 0.0) { newItem.Value = Utils.GetDutValueTo(newItem.StorageType, newItem.DisplayUnitType, newItem.RevitValue); //The unit specific value in double newItem.UIValue = ValueConvertUtils.StringFromDoubleConvert(newItem.DisplayUnitType, newItem.Precision, newItem.Value); //The string representation of the value } return(newItem); }
//Executes after RaisePropertyChange of UIValue private void SetUIValue() { double newValue = ValueConvertUtils.DoubleFromStringConvert(StorageType, DisplayUnitType, UIValue); //Get the double representation of the value based on the display unit type //What could go wrong? //1. The conversion precision f***s it up, leading to circular reference //2. The string input from the UI was bad, and returned 0.0 if (newValue == 0.0 || Math.Abs(Value - newValue) < error) //There was an error, set back the old value { UIValue = ValueConvertUtils.StringFromDoubleConvert(DisplayUnitType, Precision, Value); } else { Value = (double)newValue; if (StorageType == StorageType.Integer) { RevitValue = Value; } else { RevitValue = Utils.GetDutValueFrom(DisplayUnitType, Value); //Make the change in the Value. This should propagate a series of changes as well } } }