//Get the parameter value as Double private static double GetParameterValue(FamilyType ft, FamilyParameter fp) { double value = 0.0; switch (fp.StorageType) { case (StorageType.Double): value = Convert.ToDouble(ft.AsDouble(fp)); break; case (StorageType.Integer): value = Convert.ToDouble(ft.AsInteger(fp)); break; case (StorageType.String): value = 0.0; break; case (StorageType.ElementId): value = 0.0; break; default: break; } return(value); }
static string FamilyParamValueString( FamilyType t, FamilyParameter fp, Document doc) { string value = t.AsValueString(fp); switch (fp.StorageType) { case StorageType.Double: value = Util.RealString( (double)t.AsDouble(fp)) + " (double)"; break; case StorageType.ElementId: ElementId id = t.AsElementId(fp); Element e = doc.GetElement(id); value = id.IntegerValue.ToString() + " (" + Util.ElementDescription(e) + ")"; break; case StorageType.Integer: value = t.AsInteger(fp).ToString() + " (int)"; break; case StorageType.String: value = "'" + t.AsString(fp) + "' (string)"; break; } return(value); }
public static string ParameterToString(Document doc, FamilyParameter param, FamilyType type) { if (!type.HasValue(param)) { return("无"); } if (param.Definition.ParameterType == ParameterType.Invalid) { return("不可用"); } switch (param.StorageType) { case StorageType.Double: #if R2014 var uStr = FormatUtils.Format(doc, param.Definition.UnitType, type.AsDouble(param).Value); #else var uStr = UnitFormatUtils.Format(doc.GetUnits(), param.Definition.UnitType, type.AsDouble(param).Value, false, false); #endif return(uStr); //var uStr = string.Empty; //if (param.Definition.ParameterType == ParameterType.Length) //{ // uStr = GetParamaterUnit(param.DisplayUnitType); //} //var dStr = param.AsValueString(); //if (!String.IsNullOrEmpty(uStr) && !dStr.EndsWith(uStr)) dStr += uStr; //return dStr; case StorageType.Integer: var v = type.AsInteger(param).Value; if (param.Definition.ParameterType == ParameterType.YesNo) { if (v == 0) { return("否"); } return("是"); } #if R2014 return(FormatUtils.Format(doc, param.Definition.UnitType, v)); #else return(UnitFormatUtils.Format(doc.GetUnits(), param.Definition.UnitType, v, false, false)); #endif case StorageType.String: return(type.AsString(param)); case StorageType.ElementId: ElementId idVal = type.AsElementId(param); return(AsElementName(doc, idVal)); case StorageType.None: default: return("无"); } }
public FamilyParameterValueWrapper(FamilyParameter parameter, FamilyType familyType, Document doc) { _parameter = parameter; _familyType = familyType; _doc = doc; // Значение параметра \"{parameter.Definition.Name}\" Title = string.Format(Language.GetItem(ModPlusConnector.Instance.Name, "p4"), parameter.Definition.Name); ParameterName = parameter.Definition.Name; FamilyTypeName = familyType.Name; switch (parameter.StorageType) { case StorageType.String: Source = familyType.AsString(parameter); break; case StorageType.Integer: Source = familyType.AsInteger(parameter).ToString(); break; case StorageType.Double: var d = familyType.AsDouble(parameter); if (d.HasValue) { Source = UnitUtils.ConvertFromInternalUnits( d.Value, #if R2017 || R2018 || R2019 || R2020 parameter.DisplayUnitType) #else parameter.GetUnitTypeId()) #endif .ToString(CultureInfo.InvariantCulture); } break; } Destination = string.Empty; }
static string FamilyParamValueString( FamilyType t, FamilyParameter fp, Document doc) { string value = t.AsValueString( fp ); switch( fp.StorageType ) { case StorageType.Double: value = Util.RealString( ( double ) t.AsDouble( fp ) ) + " (double)"; break; case StorageType.ElementId: ElementId id = t.AsElementId( fp ); Element e = doc.GetElement( id ); value = id.IntegerValue.ToString() + " (" + Util.ElementDescription( e ) + ")"; break; case StorageType.Integer: value = t.AsInteger( fp ).ToString() + " (int)"; break; case StorageType.String: value = "'" + t.AsString( fp ) + "' (string)"; break; } return value; }
/// <summary> /// The method is used to collect template information, specifying the New Window Parameters /// </summary> private void CollectTemplateInfo() { List <Wall> walls = Utility.GetElements <Wall>(m_application, m_document); m_wallThickness = walls[0].Width; ParameterMap paraMap = walls[0].ParametersMap; Parameter wallheightPara = walls[0].get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM);//paraMap.get_Item("Unconnected Height"); if (wallheightPara != null) { m_wallHeight = wallheightPara.AsDouble(); } LocationCurve location = walls[0].Location as LocationCurve; m_wallWidth = location.Curve.Length; m_windowInset = m_wallThickness / 10; FamilyType type = m_familyManager.CurrentType; FamilyParameter heightPara = m_familyManager.get_Parameter(BuiltInParameter.WINDOW_HEIGHT); FamilyParameter widthPara = m_familyManager.get_Parameter(BuiltInParameter.WINDOW_WIDTH); FamilyParameter sillHeightPara = m_familyManager.get_Parameter("Default Sill Height"); if (type.HasValue(heightPara)) { switch (heightPara.StorageType) { case StorageType.Double: m_height = type.AsDouble(heightPara).Value; break; case StorageType.Integer: m_height = type.AsInteger(heightPara).Value; break; } } if (type.HasValue(widthPara)) { switch (widthPara.StorageType) { case StorageType.Double: m_width = type.AsDouble(widthPara).Value; break; case StorageType.Integer: m_width = type.AsDouble(widthPara).Value; break; } } if (type.HasValue(sillHeightPara)) { switch (sillHeightPara.StorageType) { case StorageType.Double: m_sillHeight = type.AsDouble(sillHeightPara).Value; break; case StorageType.Integer: m_sillHeight = type.AsDouble(sillHeightPara).Value; break; } } //set the height,width and sillheight parameter of the opening m_familyManager.Set(m_familyManager.get_Parameter(BuiltInParameter.WINDOW_HEIGHT), m_height); m_familyManager.Set(m_familyManager.get_Parameter(BuiltInParameter.WINDOW_WIDTH), m_width); m_familyManager.Set(m_familyManager.get_Parameter("Default Sill Height"), m_sillHeight); //get materials FilteredElementCollector elementCollector = new FilteredElementCollector(m_document); elementCollector.WherePasses(new ElementClassFilter(typeof(Material))); IList <Element> materials = elementCollector.ToElements(); foreach (Element materialElement in materials) { Material material = materialElement as Material; m_para.GlassMaterials.Add(material.Name); m_para.FrameMaterials.Add(material.Name); } //get categories Categories categories = m_document.Settings.Categories; Category category = categories.get_Item(BuiltInCategory.OST_Windows); CategoryNameMap cnm = category.SubCategories; m_frameCat = categories.get_Item(BuiltInCategory.OST_WindowsFrameMullionProjection); m_glassCat = categories.get_Item(BuiltInCategory.OST_WindowsGlassProjection); //get referenceplanes List <ReferencePlane> planes = Utility.GetElements <ReferencePlane>(m_application, m_document); foreach (ReferencePlane p in planes) { if (p.Name.Equals("Sash")) { m_sashPlane = p; } if (p.Name.Equals("Exterior")) { m_exteriorPlane = p; } if (p.Name.Equals("Center (Front/Back)")) { m_centerPlane = p; } if (p.Name.Equals("Top") || p.Name.Equals("Head")) { m_topPlane = p; } if (p.Name.Equals("Sill") || p.Name.Equals("Bottom")) { m_sillPlane = p; } } }
private void PopulateModel() { ValueParameters = new ObservableCollection <FamilyParameterModel>(); ValueParameters.CollectionChanged += ValueParameters_CollectionChanged; BuiltInParameters = new ObservableCollection <FamilyParameterModel>(); CheckParameters = new ObservableCollection <FamilyParameterModel>(); famParam = new SortedList <string, FamilyParameter>(); FamilyManager familyManager = doc.FamilyManager; FamilyType familyType = familyManager.CurrentType; if (familyType == null) { familyType = CreateDefaultFamilyType(familyManager); } Utils.Init(this.doc); double value = 0.0; foreach (FamilyParameter fp in familyManager.Parameters) { if (!famEdit(fp, familyType)) { continue; } else { if (!famParam.ContainsKey(fp.Definition.Name)) { famParam.Add(fp.Definition.Name, fp); } } } List <ElementId> eId = new List <ElementId>(); FilteredElementCollector collector = new FilteredElementCollector(doc); List <Dimension> dimList = collector .OfCategory(BuiltInCategory.OST_Dimensions) .WhereElementIsNotElementType() .Cast <Dimension>() .ToList(); List <FamilyParameter> paramUsed = new List <FamilyParameter>(); foreach (Dimension dim in dimList) { try { if (dim.FamilyLabel != null) { paramUsed.Add(dim.FamilyLabel); } } catch (Exception) { } } foreach (FamilyParameter fp in famParam.Values) { bool associated = !fp.AssociatedParameters.IsEmpty || paramUsed.Any(x => x.Definition.Name.Equals(fp.Definition.Name)); bool builtIn = fp.Id.IntegerValue < 0; ///yes-no parameters if (fp.Definition.ParameterType.Equals(ParameterType.YesNo)) { if (fp.StorageType == StorageType.Integer) { value = Convert.ToDouble(familyType.AsInteger(fp)); } //eId.Add(fp.Id); FamilyParameterModel newItem = new FamilyParameterModel(); // collect data yes-no newItem.Precision = Properties.Settings.Default.Precision; newItem.Name = fp.Definition.Name; newItem.Value = value; newItem.Type = fp.Definition.ParameterType.ToString(); newItem.Associated = associated; newItem.BuiltIn = fp.Id.IntegerValue < 0; newItem.Shared = fp.IsShared; newItem.Visible = associated ? true : Properties.Settings.Default.AssociatedVisibility; newItem.TypeOrInstance = fp.IsInstance ? "Instance" : "Type"; CheckParameters.Add(newItem); continue; } ///slider parameters if (fp.StorageType == StorageType.Double) { value = Convert.ToDouble(familyType.AsDouble(fp)); } else if (fp.StorageType == StorageType.Integer) { value = Convert.ToDouble(familyType.AsInteger(fp)); } eId.Add(fp.Id); if (!builtIn) { FamilyParameterModel newItem = new FamilyParameterModel(); // collect data slider, value != 0 newItem.Precision = Properties.Settings.Default.Precision; newItem.Name = fp.Definition.Name; newItem.Value = value; newItem.Type = fp.Definition.ParameterType.ToString(); newItem.Associated = associated; newItem.BuiltIn = fp.Id.IntegerValue < 0; newItem.Shared = fp.IsShared; newItem.Visible = associated ? true : Properties.Settings.Default.AssociatedVisibility; newItem.TypeOrInstance = fp.IsInstance ? "Instance" : "Type"; ValueParameters.Add(newItem); } else { FamilyParameterModel newItem = new FamilyParameterModel(); // collect data slider, value == 0 newItem.Precision = Properties.Settings.Default.Precision; newItem.Name = fp.Definition.Name; newItem.Value = value; newItem.Type = fp.Definition.ParameterType.ToString(); newItem.Associated = associated; newItem.BuiltIn = fp.Id.IntegerValue < 0; newItem.Shared = fp.IsShared; newItem.Visible = associated ? true : Properties.Settings.Default.AssociatedVisibility; newItem.TypeOrInstance = fp.IsInstance ? "Instance" : "Type"; BuiltInParameters.Add(newItem); } } }
/// <summary> /// Check parameter conditions /// </summary> /// <param name="fp"></param> /// <param name="ft"></param> /// <returns></returns> private Boolean famEdit(FamilyParameter fp, FamilyType ft) { //double valueDouble; //int valueInt; if (!fp.StorageType.ToString().Equals("Double") && !fp.StorageType.ToString().Equals("Integer")) { return false; } else if (fp.UserModifiable) { return false; } else if (fp.IsDeterminedByFormula || fp.Formula != null) { return false; } else if (!ft.HasValue(fp)) { return false; } else if (ft.AsDouble(fp) == null && ft.AsInteger(fp) == null) { return false; } //else if (!double.TryParse(ft.AsDouble(fp).ToString(), out valueDouble) && !int.TryParse(ft.AsInteger(fp).ToString(), out valueInt)) //{ // return false; //} else if (fp.IsReporting) { return false; } else if (fp.IsDeterminedByFormula) { return false; } return true; }
public CFamilyParameter(FamilyParameter oParam, FamilyType oFamType) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Invalid comparison between Unknown and I4 //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Invalid comparison between Unknown and I4 //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Invalid comparison between Unknown and I4 //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Invalid comparison between Unknown and I4 //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Invalid comparison between Unknown and I4 //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) this.Name = oParam.get_Definition().get_Name(); this.ParamStorageType = oParam.get_StorageType(); this.TypeName = oFamType.get_Name(); this.ID = oParam.get_Id().get_IntegerValue(); if (oFamType.HasValue(oParam)) { if ((int)this.ParamStorageType == 1 && (int)oParam.get_Definition().get_ParameterType() == 10) { if (oFamType.AsInteger(oParam) == 1) { this.Value = "Yes"; } else { this.Value = "No"; } } else if ((int)this.ParamStorageType == 1) { this.Value = oFamType.AsInteger(oParam).ToString(); } else if ((int)this.ParamStorageType == 2) { this.Value = Math.Round(oFamType.AsDouble(oParam).Value, 2).ToString(); } else if ((int)this.ParamStorageType == 3) { this.Value = oFamType.AsString(oParam); } } }
private List <FamilyTypeData> GetTypes(Family family, Document doc, string path) { Document familyDoc = doc.EditFamily(family); FamilyManager familyManager = familyDoc.FamilyManager; FamilyTypeSet familyTypes = familyManager.Types; FamilyTypeSetIterator iterator = familyTypes.ForwardIterator(); iterator.Reset(); List <FamilyTypeData> types = new List <FamilyTypeData>(); while (iterator.MoveNext()) { using (Transaction trans = new Transaction(familyDoc, "Getting Parameter")) { trans.Start(); familyManager.CurrentType = iterator.Current as FamilyType; FamilyType type = familyManager.CurrentType; string paramDescription = string.Empty; //FamilyParameter paramDescription; try { paramDescription = type.AsString(familyManager.get_Parameter(BuiltInParameter.ALL_MODEL_DESCRIPTION)); } catch (Exception e) { Console.WriteLine(e); } string paramMountType = string.Empty; try { paramMountType = type.AsString(familyManager.get_Parameter("Installationsart")); } catch (Exception e) { Console.WriteLine(e); } string paramPlacement = string.Empty; try { paramPlacement = type.AsString(familyManager.get_Parameter("Installationsort")); } catch (Exception e) { Console.WriteLine(e); } string paramInstallationMedium = string.Empty; try { paramInstallationMedium = type.AsString(familyManager.get_Parameter("Installations Medium")); } catch (Exception e) { Console.WriteLine(e); } string paramDiameter = string.Empty; try { paramDiameter = ConvertSize((double)type.AsDouble(familyManager.get_Parameter("E_Durchmesser"))); } catch (Exception e) { Console.WriteLine(e); } string paramWidth = string.Empty; try { paramWidth = ConvertSize((double)type.AsDouble(familyManager.get_Parameter("E_Breite"))); } catch (Exception e) { Console.WriteLine(e); } string paramHeight = string.Empty; try { paramHeight = ConvertSize((double)type.AsDouble(familyManager.get_Parameter("E_Hohe"))); } catch (Exception e) { Console.WriteLine(e); } string paramDepth = string.Empty; try { paramDepth = ConvertSize((double)type.AsDouble(familyManager.get_Parameter("E_Tiefe"))); } catch (Exception e) { Console.WriteLine(e); } string param_eBKP_H = string.Empty; try { param_eBKP_H = type.AsString(familyManager.get_Parameter("eBKP-H")); } catch (Exception e) { Console.WriteLine(e); } string paramBKP = string.Empty; try { paramBKP = type.AsString(familyManager.get_Parameter("BKP")); } catch (Exception e) { Console.WriteLine(e); } string paramManufacturer = string.Empty; try { paramManufacturer = type.AsString(familyManager.get_Parameter("Fabrikat")); } catch (Exception e) { Console.WriteLine(e); } string paramProduct = string.Empty; try { paramProduct = type.AsString(familyManager.get_Parameter("Produkt")); } catch (Exception e) { Console.WriteLine(e); } string paramProductNumber = string.Empty; try { paramProductNumber = type.AsString(familyManager.get_Parameter("Produkte-Nr.")); } catch (Exception e) { Console.WriteLine(e); } string paramE_Number = string.Empty; try { paramE_Number = type.AsString(familyManager.get_Parameter("E-Nummer")); } catch (Exception e) { Console.WriteLine(e); } string paramRevitCategory = String.Empty; try { //paramRevitCategory = type.AsString(familyManager.get_Parameter("Revit Kategorie")); paramRevitCategory = family.FamilyCategory.Name; } catch (Exception e) { Console.WriteLine("Revit Category" + e); } string paramOmniClass = string.Empty; try { paramOmniClass = family.get_Parameter(BuiltInParameter.OMNICLASS_CODE).AsString(); } catch (Exception e) { Console.WriteLine("OmniClass" + e); } if (true /*type != null && paramMountType!= null && paramPlacement!= null && paramInstallationMedium!=null*/) { FamilyTypeData typeData = new FamilyTypeData { Name = type.Name, Description = string.IsNullOrEmpty(paramDescription) ? emptyParameter : paramDescription, MountType = string.IsNullOrEmpty(paramMountType) ? emptyParameter : paramMountType, Placement = string.IsNullOrEmpty(paramPlacement) ? emptyParameter : paramPlacement, InstallationMedium = string.IsNullOrEmpty(paramInstallationMedium) ? emptyParameter : paramInstallationMedium, Path = path, CombinedTypeData = paramDescription + "\n" + type.Name, Diameter = string.IsNullOrEmpty(paramDiameter) ? emptyParameter : paramDiameter, Width = string.IsNullOrEmpty(paramWidth) ? emptyParameter : paramWidth, Hight = string.IsNullOrEmpty(paramHeight) ? emptyParameter : paramHeight, Depth = string.IsNullOrEmpty(paramDepth) ? emptyParameter : paramDepth, eBKP_H = string.IsNullOrEmpty(param_eBKP_H) ? emptyParameter : param_eBKP_H, BKP = string.IsNullOrEmpty(paramBKP) ? emptyParameter : paramBKP, Manufacturer = string.IsNullOrEmpty(paramManufacturer) ? emptyParameter : paramManufacturer, Product = string.IsNullOrEmpty(paramProduct) ? emptyParameter : paramProduct, ProductNumber = string.IsNullOrEmpty(paramProductNumber) ? emptyParameter : paramProductNumber, E_Number = string.IsNullOrEmpty(paramE_Number) ? emptyParameter : paramE_Number, RevitCategory = string.IsNullOrEmpty(paramRevitCategory) ? emptyParameter : paramRevitCategory, OmniClass = string.IsNullOrEmpty(paramOmniClass) ? emptyParameter : paramOmniClass }; types.Add(typeData); } trans.Commit(); } } return(types); }