/// <summary> /// Получает смещение от уровня через параметр семейства. /// /// </summary> /// <param name="fi"></param> /// <returns></returns> public static double GetOffsetFromLevel(FamilyInstance fi) { double elev = -999; Parameter offsetParam = fi.get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM); if (offsetParam != null) { elev = offsetParam.AsDouble(); if (elev != -999) { return(elev); } } offsetParam = fi.get_Parameter(BuiltInParameter.INSTANCE_ELEVATION_PARAM); if (offsetParam != null) { elev = offsetParam.AsDouble(); if (elev != -999) { return(elev); } } if (elev == 0) { offsetParam = fi.get_Parameter(BuiltInParameter.INSTANCE_SILL_HEIGHT_PARAM); elev = offsetParam.AsDouble(); } return(elev); }
public static string GetParameterValueString(Element e, BuiltInParameter bip) { Parameter p = e.get_Parameter(bip); string s = string.Empty; if (null != p) { switch (p.StorageType) { case StorageType.Integer: s = p.AsInteger().ToString(); break; case StorageType.ElementId: s = p.AsElementId().IntegerValue.ToString(); break; case StorageType.Double: s = p.AsDouble().ToString(); break; case StorageType.String: s = p.AsDouble().ToString(); break; default: s = ""; break; } } return(s); }
//Sets the value of the family parameter based on a parameter value private void SetDocumentParameter(FamilyParameter docParameter, Parameter famParameter) { switch (famParameter.StorageType) { case (StorageType.Double): var value = famParameter.AsDouble(); familyManager.Set(docParameter, famParameter.AsDouble()); break; case (StorageType.Integer): familyManager.Set(docParameter, famParameter.AsInteger()); break; case (StorageType.String): familyManager.Set(docParameter, famParameter.AsString()); break; case (StorageType.ElementId): familyManager.Set(docParameter, famParameter.AsElementId()); break; case (StorageType.None): break; } }
private static Value _getParam(Parameter p) { switch (p.StorageType) { case StorageType.ElementId: return(Value.NewContainer(p.AsElementId())); case StorageType.String: return(Value.NewString(p.AsString())); case StorageType.Integer: case StorageType.Double: switch (p.Definition.ParameterType) { case ParameterType.Length: return(Value.NewContainer(Units.Length.FromFeet(p.AsDouble(), dynSettings.Controller.UnitsManager))); case ParameterType.Area: return(Value.NewContainer(Units.Area.FromSquareFeet(p.AsDouble(), dynSettings.Controller.UnitsManager))); case ParameterType.Volume: return(Value.NewContainer(Units.Volume.FromCubicFeet(p.AsDouble(), dynSettings.Controller.UnitsManager))); default: return(Value.NewNumber(p.AsDouble())); } default: throw new Exception(string.Format("Parameter {0} has no storage type.", p)); } }
public CompareResult Compare2Params(string n, Parameter p1, Parameter p2, CompareResult rz) { if (p1.StorageType != p2.StorageType) { throw(new Exception("Different parameter storage types can't be compared")); } Double d = 0; string v = ""; switch (p1.StorageType) { case StorageType.Double: v = p1.AsDouble().ToString() + "-" + p2.AsDouble().ToString(); if (p1.AsDouble() == 0) { if (p2.AsDouble() < tolerance) { d = 1; } else { d = 0; } } else { d = Math.Abs((p2.AsDouble() - p1.AsDouble()) / p1.AsDouble()); if (d < tolerance) { d = 1; } else { d = 1 - d; } } break; default: v = p1.AsString() + "-" + p2.AsString(); if (p1.AsValueString() == p2.AsValueString()) { d = 1; } else { d = 0; } break; } rz.result += d; rz.total += 1; rz.AppendLine(n + ": " + v + " " + d.ToString() + "/1"); return(rz); }
/// <summary> /// SetLayer method /// </summary> /// <param name="layerNumber">The layerNumber for the number of the layers</param> public void SetLayer(int layerNumber) { // Get each layer. // An individual layer can be accessed by Layers property and its thickness and material can then be reported. m_slabLayer = m_slabLayerCollection[layerNumber]; // Get the Thickness property and change to the metric millimeter m_thickness = ((m_slabLayer.Width) * ToMetricThickness * ToMillimeter).ToString() + " mm"; // Get the Material name property if (ElementId.InvalidElementId != m_slabLayer.MaterialId) { Material material = m_document.GetElement(m_slabLayer.MaterialId) as Material; m_materialName = material.Name; } else { m_materialName = "Null"; } // The Young modulus can be found from the material by using the following generic parameters: // PHY_MATERIAL_PARAM_YOUNG_MOD1, PHY_MATERIAL_PARAM_YOUNG_MOD2, PHY_MATERIAL_PARAM_YOUNG_MOD3 if (ElementId.InvalidElementId != m_slabLayer.MaterialId) { Material material = m_document.GetElement(m_slabLayer.MaterialId) as Material; Parameter youngModuleAttribute = null; youngModuleAttribute = material.get_Parameter(BuiltInParameter.PHY_MATERIAL_PARAM_YOUNG_MOD1); if (null != youngModuleAttribute) { m_youngModulusX = (youngModuleAttribute.AsDouble() / ToMetricYoungmodulus).ToString("F2") + " MPa"; } youngModuleAttribute = material.get_Parameter(BuiltInParameter.PHY_MATERIAL_PARAM_YOUNG_MOD2); if (null != youngModuleAttribute) { m_youngModulusY = (youngModuleAttribute.AsDouble() / ToMetricYoungmodulus).ToString("F2") + " MPa"; } youngModuleAttribute = material.get_Parameter(BuiltInParameter.PHY_MATERIAL_PARAM_YOUNG_MOD3); if (null != youngModuleAttribute) { m_youngModulusZ = (youngModuleAttribute.AsDouble() / ToMetricYoungmodulus).ToString("F2") + " MPa"; } } else { m_youngModulusX = "Null"; m_youngModulusY = "Null"; m_youngModulusZ = "Null"; } }
public object GetParameterValue(Parameter parameter) { object returnValue = null; if (parameter == null || !parameter.HasValue) { return(returnValue); } switch (parameter.StorageType) { case StorageType.Double: returnValue = parameter.AsDouble(); break; case StorageType.Integer: returnValue = parameter.AsInteger(); break; case StorageType.String: returnValue = parameter.AsString(); break; case StorageType.ElementId: returnValue = parameter.AsElementId(); break; } return(returnValue); }
public string GetParameterValue(Parameter parameter) { string s; switch (parameter.StorageType) { case StorageType.Double: s = RealString(parameter.AsDouble()); break; case StorageType.Integer: s = parameter.AsInteger().ToString(); break; case StorageType.String: s = parameter.AsString(); break; case StorageType.ElementId: s = parameter.AsElementId().IntegerValue.ToString(); break; case StorageType.None: s = ""; break; default: s = "0.0"; break; } return(s); }
/// <summary> /// Calculates Roll value (Rotation angle) for a beam, column and member /// </summary> /// <param name="exporterIFC"> /// The ExporterIFC object. /// </param> /// <param name="extrusionCreationData"> /// The IFCExtrusionCreationData. /// </param> /// <param name="element"> /// The element to calculate the value. /// </param> /// <param name="elementType"> /// The element type. /// </param> /// <returns> /// True if the operation succeed, false otherwise. /// </returns> public override bool Calculate(ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType) { Parameter rollPar = element.get_Parameter(BuiltInParameter.STRUCTURAL_BEND_DIR_ANGLE); if (rollPar != null) { double?roll = rollPar.AsDouble(); if (roll != null && roll.HasValue) { m_Roll = UnitUtil.ScaleAngle(roll.Value); return(true); } } // For other elements with ExtrusionData. Parameter will take precedence (override) if (ParameterUtil.GetDoubleValueFromElementOrSymbol(element, "IfcRoll", out m_Roll) == null) { ParameterUtil.GetDoubleValueFromElementOrSymbol(element, "Roll", out m_Roll); } m_Roll = UnitUtil.ScaleAngle(m_Roll); if (m_Roll > MathUtil.Eps()) { return(true); } return(false); }
//Build solid public void incrementIntercetor(Document doc, XYZ startOfInterest, Parameter zOffsetVar, out ElementId columnId, out ElementId beamId) { columnId = null; beamId = null; double radius = 0; double limit = 0.75; double zOffset = zOffsetVar.AsDouble(); //lower arc center double centerZ = (startOfInterest.Z + zOffset) - 0.25; XYZ arcCenter = new XYZ(startOfInterest.X, startOfInterest.Y, centerZ); //Build a solid cylinder for (radius = .125; radius < limit; radius = radius + 0.1) { // Create a vertical half-circle loop in the frame location. List <CurveLoop> curveloops = new List <CurveLoop>(); CurveLoop circle = new CurveLoop(); circle.Append(Arc.Create(arcCenter, radius, 0, Math.PI, XYZ.BasisX, XYZ.BasisY)); circle.Append(Arc.Create(arcCenter, radius, Math.PI, 2 * Math.PI, XYZ.BasisX, XYZ.BasisY)); curveloops.Add(circle); Solid cylinder = GeometryCreationUtilities.CreateExtrusionGeometry(curveloops, XYZ.BasisZ, (0.25)); //PaintSolid(commandData, cylinder, 5); //Find column IEnumerable <Element> columns = new FilteredElementCollector(doc) .OfClass(typeof(FamilyInstance)) .OfCategory(BuiltInCategory.OST_StructuralColumns) .WherePasses(new ElementIntersectsSolidFilter(cylinder)); if (columns.Count() > 0) { foreach (Element e in columns) { FamilyInstance fi = e as FamilyInstance; FamilySymbol fs = fi.Symbol; columnId = e.Id; } break; } //Find beam IEnumerable <Element> beams = new FilteredElementCollector(doc) .OfClass(typeof(FamilyInstance)) .OfCategory(BuiltInCategory.OST_StructuralFraming) .WherePasses(new ElementIntersectsSolidFilter(cylinder)); if (beams.Count() > 0) { foreach (Element e in beams) { FamilyInstance fi = e as FamilyInstance; FamilySymbol fs = fi.Symbol; beamId = e.Id; } break; } } //End of loop }
public void GetParameters() { Document doc = Column.Document; FamilySymbol type = Column.Symbol; Width = type.LookupParameter("b").AsDouble(); Height = type.LookupParameter("h").AsDouble(); LocationPoint lp = Column.Location as LocationPoint; XYZ p = lp.Point; Parameter blP = Column.LookupParameter("Base Level"); Parameter boP = Column.LookupParameter("Base Offset"); Level bl = doc.GetElement(blP.AsElementId()) as Level; double bo = boP.AsDouble(); Parameter tlP = Column.LookupParameter("Top Level"); Parameter toP = Column.LookupParameter("Top Offset"); Level tl = doc.GetElement(tlP.AsElementId()) as Level; double to = toP.AsDouble(); DrivingCurve = Line.CreateBound(new XYZ(p.X, p.Y, bl.Elevation + bo), new XYZ(p.X, p.Y, tl.Elevation + to)); Length = DrivingCurve.Length; }
public static bool ResetValue(this Parameter parameter) { if (!parameter.HasValue) { return(true); } #if REVIT_2020 if (parameter.IsShared && (parameter.Definition as ExternalDefinition).HideWhenNoValue) { return(parameter.ClearValue()); } #endif switch (parameter.StorageType) { case StorageType.Integer: return(parameter.AsInteger() == 0 || parameter.Set(0)); case StorageType.Double: return(parameter.AsDouble() == 0.0 || parameter.Set(0.0)); case StorageType.String: return(parameter.AsString() == string.Empty || parameter.Set(string.Empty)); case StorageType.ElementId: return(parameter.AsElementId() == ElementId.InvalidElementId || parameter.Set(ElementId.InvalidElementId)); } return(false); }
public AnalyticElement(Element element) { Element = element; Parameter parInsTypeCheck = Element.get_Parameter(BuiltInParameter.RBS_REFERENCE_INSULATION_TYPE); if (parInsTypeCheck.HasValue) { Parameter parInsThickness = Element.get_Parameter(BuiltInParameter.RBS_REFERENCE_INSULATION_THICKNESS); InsulationThk = (int)parInsThickness.AsDouble().FtToMm().Round(); } switch (Element) { case Pipe pipe: //Outside diameter oDia = Element.get_Parameter(BuiltInParameter.RBS_PIPE_OUTER_DIAMETER).AsDouble().FtToMm(); //Wallthk DN = (int)pipe.Diameter.FtToMm().Round(); WallThk = MepUtils.pipeWallThkDict()[DN]; break; case FamilyInstance fi: //Outside diameter Cons cons = MepUtils.GetConnectors(fi); DN = (int)(cons.Primary.Radius * 2).FtToMm().Round(); oDia = MepUtils.outerDiaDict()[DN]; WallThk = MepUtils.pipeWallThkDict()[DN]; break; default: break; } }
public static double GetWidthStemOfDoubletee(this FamilyInstance familyInstance, Document doc) { FamilyInstance familyInstance1 = null; Element p = familyInstance.SuperComponent; if (p != null) { familyInstance1 = p as FamilyInstance; } else { familyInstance1 = familyInstance; } ElementId type = familyInstance1.GetTypeId(); Element ele = doc.GetElement(type); Parameter pa = ele.LookupParameter("DT_Stem_Spacing_Form"); if (pa != null) { return(pa.AsDouble()); } else { return(0); } }
private static void SetParameter(Parameter parameter, string value) { switch (parameter.StorageType) { case StorageType.Integer: if (int.TryParse(value, out int integerValue) && parameter.AsInteger() != integerValue) { parameter.Set(integerValue); } break; case StorageType.Double: if (double.TryParse(value, out double doubleValue) && parameter.AsDouble() != doubleValue) { parameter.Set(doubleValue); } break; case StorageType.String: if (parameter.AsString() != value) { parameter.Set(value); } break; case StorageType.ElementId: if (int.TryParse(value, out int elementIdIntegerValue) && parameter.AsElementId()?.IntegerValue != elementIdIntegerValue) { parameter.Set(new ElementId(elementIdIntegerValue)); } break; } }
public void GetParameters() { Document doc = Wall.Document; WallType type = Wall.WallType; Width = type.LookupParameter("Width").AsDouble(); LocationCurve lc = Wall.Location as LocationCurve; Curve c = lc.Curve; Parameter boP = Wall.LookupParameter("Base Offset"); c = GeomUtil.OffsetCurve(c, XYZ.BasisZ, boP.AsDouble()); List <XYZ> ps = new List <XYZ> { c.GetEndPoint(0), c.GetEndPoint(1) }; ps.Sort(new ZYXComparer()); DrivingCurve = Line.CreateBound(ps[0], ps[1]); Length = DrivingCurve.Length; Parameter uhP = Wall.LookupParameter("Unconnected Height"); Height = uhP.AsDouble(); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; // code Reference r = uidoc.Selection. PickObject(ObjectType.Element, "HAY CHON DOI TUONG"); Element e = doc.GetElement(r); Parameter parameter = e .get_Parameter(BuiltInParameter.INSTANCE_LENGTH_PARAM); MessageBox.Show(parameter.AsDouble().ToString()); return(Result.Succeeded); }
private static string GetParameterValue(Parameter param) { if (param == null) { return(string.Empty); } string str; switch (param.StorageType) { case StorageType.Integer: str = param.AsInteger().ToString(); break; case StorageType.Double: str = param.AsDouble().ToString(CultureInfo.InvariantCulture); break; case StorageType.String: str = param.AsString(); break; case StorageType.ElementId: str = param.AsElementId().ToString(); break; default: str = param.AsString(); break; } return(str ?? string.Empty); }
/// <summary> /// Get double value of parameter in meters unit. /// E.g. Length in meters, Area in square meters /// and Volume in Cubic_meters. /// Other units not supported yet. /// </summary> public static double AsMetersValue( this Parameter param) { if (param.StorageType != StorageType.Double) { throw new NotSupportedException( "Parameter does not have double value"); } double imperialValue = param.AsDouble(); UnitType ut = ConvertParameterTypeToUnitType( param.Definition.ParameterType); switch (ut) { case UnitType.UT_Length: return(imperialValue * METERS_IN_FEET); case UnitType.UT_Area: return(imperialValue * Math.Pow( METERS_IN_FEET, 2)); case UnitType.UT_Volume: return(imperialValue * Math.Pow( METERS_IN_FEET, 3)); } throw new NotSupportedException(); }
public static string GetAsString(Parameter param) { switch (param.StorageType) { case StorageType.None: return(""); case StorageType.Integer: return(param.AsInteger().ToString()); case StorageType.Double: double doubleval = param.AsDouble(); if (param.Definition.UnitType == UnitType.UT_Length) { doubleval *= 304.8; } return(doubleval.ToString("F1")); case StorageType.String: return(param.AsString()); case StorageType.ElementId: int intval = param.AsElementId().IntegerValue; return(intval.ToString()); default: return(""); } }
/// <summary> /// Gets double value from parameter of an element. /// </summary> /// <param name="element">The element.</param> /// <param name="group">Optional property group to limit search to.</param> /// <param name="propertyName">The property name.</param> /// <param name="propertyValue">The output property value.</param> /// <exception cref="System.ArgumentNullException">Thrown when element is null.</exception> /// <exception cref="System.ArgumentException">Thrown when propertyName is null or empty.</exception> /// <returns>The parameter, or null if not found.</returns> public static Parameter GetDoubleValueFromElement(Element element, BuiltInParameterGroup?group, string propertyName, out double propertyValue) { if (element == null) { throw new ArgumentNullException("element"); } if (String.IsNullOrEmpty(propertyName)) { throw new ArgumentException("It is null or empty.", "propertyName"); } propertyValue = 0.0; Parameter parameter = GetParameterFromName(element.Id, group, propertyName); if (parameter != null && parameter.HasValue) { switch (parameter.StorageType) { case StorageType.Double: propertyValue = parameter.AsDouble(); return(parameter); case StorageType.Integer: propertyValue = parameter.AsInteger(); return(parameter); case StorageType.String: return(Double.TryParse(parameter.AsString(), out propertyValue) ? parameter : null); } } return(null); }
private void checkBox_Unchecked(object sender, EventArgs e) { CheckBox cb = sender as CheckBox; TreeViewItem tvi = cb.Parent as TreeViewItem; if (tvi.HasItems) { foreach (TreeViewItem tvitest in tvi.Items) { (tvitest.Header as CheckBox).IsChecked = false; } } else { Parameter p = cb.Tag as Parameter; foreach (ElementId ei in elementsId) { Parameter par = doc.GetElement(ei).get_Parameter(p.Definition); if (Math.Round(par.AsDouble()) == Math.Round(p.AsDouble()) && par.AsElementId() == p.AsElementId() && par.AsInteger() == p.AsInteger() && par.AsString() == p.AsString() && par.AsValueString() == p.AsValueString()) { filteredElementId.Remove(ei); } } filteredElementId = filteredElementId .Distinct() .ToList(); label1.Content = "Выбрано элементов: " + filteredElementId.Count; } }
public double GetCapLength(Element i) { FamilyInstance fi = i as FamilyInstance; if ((fi.MEPModel as MechanicalFitting).PartType == PartType.Cap) { string[] parameters = { "Length", "Длина воздуховода", "L" }; foreach (string p in parameters) { Parameter parLength = i.LookupParameter(p); if (parLength != null) { length = parLength.AsDouble(); } else { length = 0.0; } } } else { length = 0.0; } return(length); }
void CopyParameter(Parameter cpFrom, Parameter cpTo) { switch (cpFrom.StorageType) { case StorageType.String: cpTo.Set(cpFrom.AsString()); break; case StorageType.Integer: cpTo.Set(cpFrom.AsInteger()); break; case StorageType.Double: cpTo.Set(cpFrom.AsDouble()); break; case StorageType.ElementId: cpTo.Set(cpFrom.AsInteger()); break; case StorageType.None: throw new Exception(); default: throw new Exception(); } }
/// <summary> /// Return parameter value formatted as string /// </summary> static string ParameterToString(Parameter p) { string s = "null"; if (p != null) { switch (p.StorageType) { case StorageType.Double: s = p.AsDouble().ToString("0.##"); break; case StorageType.Integer: s = p.AsInteger().ToString(); break; case StorageType.String: s = p.AsString(); break; case StorageType.ElementId: s = p.AsElementId().IntegerValue.ToString(); break; case StorageType.None: s = "none"; break; } } return(s); }
/// <summary> /// Check whether the floor is planar. /// </summary> /// <param name="bbXYZ">The floor's bounding box.</param> /// <param name="floor">The floor object.</param> /// <returns>A bool value suggests the floor is planar or not.</returns> private static bool IsPlanarFloor(BoundingBoxXYZ bbXYZ, Floor floor) { // Get floor thickness. double floorThickness = 0.0; ElementType floorType = m_revit.ActiveUIDocument.Document.GetElement(floor.GetTypeId()) as ElementType; Parameter attribute = floorType.get_Parameter(BuiltInParameter.FLOOR_ATTR_DEFAULT_THICKNESS_PARAM); if (null != attribute) { floorThickness = attribute.AsDouble(); } // Get bounding box thickness. double boundThickness = Math.Abs(bbXYZ.Max.Z - bbXYZ.Min.Z); // Planar or not. if (Math.Abs(boundThickness - floorThickness) < PlanarPrecision) { return(true); } else { return(false); } }
public static string GetParameterValueString(this Parameter param) { string empty = string.Empty; string str; switch ((int)param.StorageType) { case 0: str = param.AsValueString().ToString(); break; case 1: str = param.AsInteger().ToString(); break; case 2: str = param.AsDouble().ToString(CultureInfo.InvariantCulture); break; case 3: str = param.AsString(); break; case 4: str = param.AsElementId().ToString(); break; default: str = param.AsValueString(); break; } return(str ?? string.Empty); }
object GetParameterValue(Parameter par) { object parValue = null; if (!par.HasValue) { return(parValue); } switch (par.StorageType) { case StorageType.Double: parValue = par.AsDouble(); break; case StorageType.Integer: parValue = par.AsInteger(); break; case StorageType.String: parValue = par.AsString(); break; case StorageType.ElementId: parValue = par.AsElementId(); break; default: break; } return(parValue); }
/// <summary> /// /// </summary> /// <param name="p"></param> /// <returns></returns> public static object GetParameterValue(Parameter p) { switch (p.StorageType) { case StorageType.None: throw new System.ArgumentOutOfRangeException(); case StorageType.Integer: // (Konrad) It appears that by default yes/no parameters // have a greyed out box checked to 1 even though stored // integer value would return 0 return(p.HasValue ? p.AsInteger() : 1); case StorageType.Double: return(p.AsDouble()); case StorageType.String: return(p.AsString()); case StorageType.ElementId: return(p.AsElementId().IntegerValue); default: throw new System.ArgumentOutOfRangeException(); } }
/// <summary> /// get the room property and Department property according the property name /// </summary> /// <param name="room">a instance of room class</param> /// <param name="propertyName">the property name</param> /// <param name="proValue">the value of property</param> public String GetProperty(Room room, BuiltInParameter paramEnum) { String propertyValue = null; //the value of parameter //get the parameter via the parameterId Parameter param = room.get_Parameter(paramEnum); //get the parameter's storage type StorageType storageType = param.StorageType; switch (storageType) { case StorageType.Integer: int iVal = param.AsInteger(); propertyValue = iVal.ToString(); break; case StorageType.String: String stringVal = param.AsString(); propertyValue = stringVal; break; case StorageType.Double: Double dVal = param.AsDouble(); dVal = Math.Round(dVal, 2); propertyValue = dVal.ToString(); break; default: break; } return(propertyValue); }
/// <summary> /// Helper to return parameter value as string. /// One can also use param.AsValueString() to /// get the user interface representation. /// </summary> public static string GetParameterValue( Parameter param ) { string s; switch( param.StorageType ) { case StorageType.Double: // // the internal database unit for all lengths is feet. // for instance, if a given room perimeter is returned as // 102.36 as a double and the display unit is millimeters, // then the length will be displayed as // peri = 102.36220472440 // peri * 12 * 25.4 // 31200 mm // //s = param.AsValueString(); // value seen by user, in display units //s = param.AsDouble().ToString(); // if not using not using LabUtils.RealString() s = RealString( param.AsDouble() ); // raw database value in internal units, e.g. feet break; case StorageType.Integer: s = param.AsInteger().ToString(); break; case StorageType.String: s = param.AsString(); break; case StorageType.ElementId: s = param.AsElementId().IntegerValue.ToString(); break; case StorageType.None: s = "?NONE?"; break; default: s = "?ELSE?"; break; } return s; }
private static Expression _getParam(FamilyInstance fi, Parameter p) { if (p.StorageType == StorageType.Double) { return Expression.NewNumber(p.AsDouble()); } else if (p.StorageType == StorageType.Integer) { return Expression.NewNumber(p.AsInteger()); } else if (p.StorageType == StorageType.String) { return Expression.NewString(p.AsString()); } else { return Expression.NewContainer(p.AsElementId()); } }
private void Stream(ArrayList data, Parameter param) { data.Add(new Snoop.Data.ClassSeparator(typeof(Parameter))); data.Add(new Snoop.Data.Object("Definition", param.Definition)); try { // this only works for certain types of Parameters data.Add(new Snoop.Data.String("Display unit type", param.DisplayUnitType.ToString())); } catch (System.Exception) { data.Add(new Snoop.Data.String("Display unit type", "N/A")); } try { // this only works for certain types of Parameters data.Add(new Snoop.Data.Object("Element", param.Element)); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("Element", ex)); } try { // this only works for certain types of Parameters data.Add(new Snoop.Data.String("GUID", param.GUID.ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("GUID", ex)); } try { // this only works for certain types of Parameters data.Add(new Snoop.Data.Bool("HasValue", param.HasValue)); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("HasValue", ex)); } try { // this only works for certain types of Parameters data.Add(new Snoop.Data.ElementId("ID", param.Id,m_activeDoc)); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("ID", ex)); } try { // this only works for certain types of Parameters data.Add(new Snoop.Data.Bool("IsShared", param.IsShared)); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("IsShared", ex)); } data.Add(new Snoop.Data.String("Storage type", param.StorageType.ToString())); if (param.StorageType == StorageType.Double) data.Add(new Snoop.Data.Double("Value", param.AsDouble())); else if (param.StorageType == StorageType.ElementId) data.Add(new Snoop.Data.ElementId("Value", param.AsElementId(), m_app.ActiveUIDocument.Document)); else if (param.StorageType == StorageType.Integer) data.Add(new Snoop.Data.Int("Value", param.AsInteger())); else if (param.StorageType == StorageType.String) data.Add(new Snoop.Data.String("Value", param.AsString())); data.Add(new Snoop.Data.String("As value string", param.AsValueString())); }
private static FScheme.Value _getParam(FamilySymbol fi, Parameter p) { if (p.StorageType == StorageType.Double) { return FScheme.Value.NewNumber(p.AsDouble()); } else if (p.StorageType == StorageType.Integer) { return FScheme.Value.NewNumber(p.AsInteger()); } else if (p.StorageType == StorageType.String) { return FScheme.Value.NewString(p.AsString()); } else { return FScheme.Value.NewContainer(p.AsElementId()); } }
private static Value _getParam(Parameter p) { switch (p.StorageType) { case StorageType.ElementId: return Value.NewContainer(p.AsElementId()); case StorageType.String: return Value.NewString(p.AsString()); case StorageType.Integer: case StorageType.Double: switch (p.Definition.ParameterType) { case ParameterType.Length: return Value.NewContainer(Units.Length.FromFeet(p.AsDouble(), dynSettings.Controller.UnitsManager)); case ParameterType.Area: return Value.NewContainer(Units.Area.FromSquareFeet(p.AsDouble(), dynSettings.Controller.UnitsManager)); case ParameterType.Volume: return Value.NewContainer(Units.Volume.FromCubicFeet(p.AsDouble(), dynSettings.Controller.UnitsManager)); default: return Value.NewNumber(p.AsDouble()); } default: throw new Exception(string.Format("Parameter {0} has no storage type.", p)); } }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { #region TEST_1 #if TEST_1 // // you cannot create your own parameter, because the // constuctor is for internal use only. This is due // to the fact that a parameter cannot live on its own, // it is linked to a definition and needs to be hooked // up properly in the Revit database system to work // ... case 1245614 [Formatting units strings]: // bool iReallyWantToCrash = false; if( iReallyWantToCrash ) { Parameter p = new Parameter(); p.Set( 1.0 ); string s = p.AsDouble().ToString(); string t = p.AsValueString(); Debug.WriteLine( "Value " + s ); Debug.WriteLine( "Value string " + t ); } #endif // TEST #endregion // TEST_1 UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; // Loop through all pre-selected elements: foreach( ElementId id in uidoc.Selection.GetElementIds() ) { Element e = doc.GetElement( id ); string s = string.Empty; // set this variable to false to analyse the element's own parameters, // i.e. instance parameters for a family instance, and set it to true // to analyse a family instance's type parameters: bool analyseTypeParameters = false; if( analyseTypeParameters ) { if( e is FamilyInstance ) { FamilyInstance inst = e as FamilyInstance; if( null != inst.Symbol ) { e = inst.Symbol; s = " type"; } } else if( e is Wall ) { Wall wall = e as Wall; if( null != wall.WallType ) { e = wall.WallType; s = " type"; } } // ... add support for other types if desired ... } // Loop through and list all UI-visible element parameters List<string> a = new List<string>(); #region 4.1.a Iterate over element parameters and retrieve their name, type and value: foreach( Parameter p in e.Parameters ) { string name = p.Definition.Name; string type = p.StorageType.ToString(); string value = LabUtils.GetParameterValue2( p, uidoc.Document ); //bool read_only = p.Definition.IsReadOnly; // 2013 bool read_only = p.IsReadOnly; // 2014 a.Add( string.Format( "Name={0}; Type={1}; Value={2}; ValueString={3}; read-{4}", name, type, value, p.AsValueString(), ( read_only ? "only" : "write" ) ) ); } #endregion // 4.1.a string what = e.Category.Name + " (" + e.Id.IntegerValue.ToString() + ")"; LabUtils.InfoMsg( what + " has {0} parameter{1}{2}", a ); // If we know which param we are looking for, then: // A) If a standard parameter, we can get it via BuiltInParam // signature of Parameter method: try { #region 4.1.b Retrieve a specific built-in parameter: Parameter p = e.get_Parameter( BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM ); #endregion // 4.1.b if( null == p ) { LabUtils.InfoMsg( "FAMILY_BASE_LEVEL_OFFSET_PARAM is NOT available for this element." ); } else { string name = p.Definition.Name; string type = p.StorageType.ToString(); string value = LabUtils.GetParameterValue2( p, doc ); LabUtils.InfoMsg( "FAMILY_BASE_LEVEL_OFFSET_PARAM: Name=" + name + "; Type=" + type + "; Value=" + value ); } } catch( Exception ) { LabUtils.InfoMsg( "FAMILY_BASE_LEVEL_OFFSET_PARAM is NOT available for this element." ); } // B) For a shared parameter, we can get it via "GUID" signature // of Parameter method ... this will be shown later in Labs 4 ... // C) or we can get the parameter by name: // alternatively, loop through all parameters and // search for the name (this works for either // standard or shared). Note that the same name // may occur multiple times: const string paramName = "Base Offset"; //Parameter parByName = e.get_Parameter( paramName ); // 2014 IList<Parameter> paramsByName = e.GetParameters( paramName ); // 2015 if( 0 == paramsByName.Count ) { LabUtils.InfoMsg( paramName + " is NOT available for this element." ); } else foreach( Parameter p in paramsByName ) { string parByNameName = p.Definition.Name; string parByNameType = p.StorageType.ToString(); string parByNameValue = LabUtils.GetParameterValue2( p, doc ); LabUtils.InfoMsg( paramName + ": Name=" + parByNameName + "; Type=" + parByNameType + "; Value=" + parByNameValue ); } #region TEST_2 #if TEST_2 List<string> a = GetParameters( doc, e ); foreach( string s2 in a ) { Debug.WriteLine( s2 ); } #endif // TEST_2 #endregion // TEST_2 } return Result.Failed; }
/// <summary> /// Helper function: return a string form of a given parameter. /// </summary> public static string ParameterToString(Parameter param) { string val = "none"; if (param == null) { return val; } // To get to the parameter value, we need to pause it depending on its storage type switch (param.StorageType) { case StorageType.Double: double dVal = param.AsDouble(); val = dVal.ToString(); break; case StorageType.Integer: int iVal = param.AsInteger(); val = iVal.ToString(); break; case StorageType.String: string sVal = param.AsString(); val = sVal; break; case StorageType.ElementId: ElementId idVal = param.AsElementId(); val = idVal.IntegerValue.ToString(); break; case StorageType.None: break; } return val; }
private void writeValueByStorageType(Parameter p, TextWriter writer, Document doc) { if (null != p) { switch (p.StorageType) { case StorageType.Double: { writer.Write(p.AsDouble()); break; } case StorageType.Integer: { writer.Write(p.AsInteger()); break; } case StorageType.String: { writer.Write(p.AsString()); break; } case StorageType.ElementId: { Element elem = doc.get_Element(p.AsElementId()); if (null == elem) writer.Write("NULL ELEMENT FOUND"); else writer.Write(elem.Name); break; } default: writer.Write("N/A"); break; } } }
private static Value _getParam(FamilyInstance fi, Parameter p) { if (p.StorageType == StorageType.Double) { switch (p.Definition.ParameterType) { case ParameterType.Length: return Value.NewContainer(Units.Length.FromFeet(p.AsDouble())); break; case ParameterType.Area: return Value.NewContainer(Units.Area.FromSquareFeet(p.AsDouble())); break; case ParameterType.Volume: return Value.NewContainer(Units.Volume.FromCubicFeet(p.AsDouble())); break; default: return Value.NewNumber(p.AsDouble()); break; } } else if (p.StorageType == StorageType.Integer) { return Value.NewNumber(p.AsInteger()); } else if (p.StorageType == StorageType.String) { return Value.NewString(p.AsString()); } else { return Value.NewContainer(p.AsElementId()); } }