public static Dictionary <string, object> ProjectPosition(dynamic Document_RevitLinkInstance) { var doc = DocumentManager.Instance.CurrentDBDocument; Dictionary <string, object> appversion = ApplicationVersion(); int version = 0; ProjectPosition pData; SiteLocation lData; string dispsym; if (appversion.TryGetValue("Version Number", out object value)) { version = Convert.ToInt32(value); } if (Document_RevitLinkInstance != null && Document_RevitLinkInstance.GetType().FullName.ToString() != "Revit.Application.Document") { doc = Document_RevitLinkInstance.InternalElement.Document; } ProjectLocation pLoc = doc.ActiveProjectLocation; if (version > 2017) { pData = pLoc.GetProjectPosition(XYZ.Zero); lData = pLoc.GetSiteLocation(); } else { pData = pLoc.GetProjectPosition(XYZ.Zero); lData = pLoc.SiteLocation; } double angle = pData.Angle * (180 / Math.PI); double elevation = Math.Round(pData.Elevation, 8); double ew = Math.Round(pData.EastWest, 8); double ns = Math.Round(pData.NorthSouth, 8); UnitType unittype = UnitType.UT_Length; FormatOptions formatoptions = doc.GetUnits().GetFormatOptions(unittype); DisplayUnitType dispunits = formatoptions.DisplayUnits; UnitSymbolType symtype = formatoptions.UnitSymbol; if (symtype == UnitSymbolType.UST_NONE) { dispsym = "none"; } else { dispsym = LabelUtils.GetLabelFor(symtype); } elevation = UnitUtils.ConvertFromInternalUnits(elevation, dispunits); ew = UnitUtils.ConvertFromInternalUnits(ew, dispunits); ns = UnitUtils.ConvertFromInternalUnits(ns, dispunits); return(new Dictionary <string, object> { { "Angle", angle }, { "NorthSouth", ns }, { "EastWest", ew }, { "Elevation", elevation } }); }
public static string Get(UnitSymbolType unitSymbolType, UnitSymbolType onError = UnitSymbolType.UST_NONE) { try { return(LabelUtils.GetLabelFor(unitSymbolType)); } catch (Exception) { try { return(LabelUtils.GetLabelFor(onError)); } catch (Exception) { return(onError.ToString()); } } }
/// <summary> /// Convert a UnitSymbolType enumeration value /// to a brief human readable abbreviation string. /// </summary> public static string UnitSymbolTypeString(UnitSymbolType u) { string s = u.ToString(); Debug.Assert(s.StartsWith("UST_"), "expected UnitSymbolType enumeration value to begin with 'UST_'"); s = s.Substring(4).Replace("_SUP_", "^").ToLower(); return(s); }
/// <summary> /// Tries to get from symbol. /// </summary> /// <param name="unitSymbolString">The unit symbol string.</param> /// <param name="unitSymbol">The unit symbol.</param> /// <returns></returns> public static bool TryGetFromSymbol(this string unitSymbolString, out UnitSymbolType unitSymbol) { var valueExists = unitSymbolTypes.ContainsValue(unitSymbolString); unitSymbol = (!valueExists) ? UnitSymbolType.UST_NONE : unitSymbolTypes .FirstOrDefault(x => x.Value.Equals(unitSymbolString, StringComparison.OrdinalIgnoreCase)) .Key; return(valueExists); }
/// <summary> /// DerivedUnitExpectedTypes constructor. /// </summary> public DerivedUnitExpectedTypes(UnitName unitName, UnitSymbolType unitSymbol) { UnitName = unitName; UnitSymbol = unitSymbol; }
public UnitsTypeAssignment(UnitSymbolType symbolType, DisplayUnitType displayType) { SymbolType = symbolType; DisplayType = displayType; }
/// <summary> /// Tries to get the symbol for the given <see cref="UnitSymbolType"/> value. /// </summary> /// <param name="unitSymbol">The unit symbol.</param> /// <param name="unitSymbolString">The unit symbol string representation.</param> /// <returns></returns> public static bool TryGetSymbol(this UnitSymbolType unitSymbol, out string unitSymbolString) { return(unitSymbolTypes.TryGetValue(unitSymbol, out unitSymbolString)); }
/// <summary> /// Creats the section of document with diagram /// </summary> /// <param name="title">Title of the diagram</param> /// <param name="resultsInPoints"> Result in point collection</param> /// <param name="resultTypes">The type of results that will be displayed in the diagram.</param> /// <param name="document">Active Revit document</param> /// <param name="elementType">Structural element type</param> /// <param name="reversedAxis">Sets the direction of the Y axis on the graph</param> /// <returns>Returns section of document with diagram</returns> private DocumentDiagram CreateResultDiagramForLinearElements(String title, IEnumerable <ResultInPointLinear> resultsInPoints, List <ResultTypeLinear> resultTypes, Autodesk.Revit.DB.Document document, ElementType elementType, bool reversedAxis) { Units units = document.GetUnits(); DocumentDiagram chart = new DocumentDiagram(); if (resultTypes != null) { if (resultTypes.Count() > 0) { if (title.Length != 0) { chart.Title = title; } chart.Height = 200; chart.Width = 4 * chart.Height; UnitType unitTypeX = ResultTypeLinear.X.GetUnitType(); FormatOptions formatOptions = units.GetFormatOptions(unitTypeX); DisplayUnitType displayUnitTypeX = formatOptions.DisplayUnits; DisplayUnitType internalDisplayUnitTypeX = UnitsConverter.GetInternalUnit(unitTypeX); UnitSymbolType unitSymbolTypeX = formatOptions.UnitSymbol; String axisTitle = ""; if (ElementType.Column == elementType) { axisTitle = Resources.ResourceManager.GetString("AxisHeight"); } else { axisTitle = Resources.ResourceManager.GetString("AxisLength"); } if (UnitSymbolType.UST_NONE != unitSymbolTypeX) { axisTitle += " " + LabelUtils.GetLabelFor(unitSymbolTypeX); } chart.AxisX.Title = axisTitle; chart.AxisY.Reversed = reversedAxis; UnitType unitTypeY = resultTypes.First().GetUnitType(); formatOptions = units.GetFormatOptions(unitTypeY); DisplayUnitType displayUnitTypeY = formatOptions.DisplayUnits; DisplayUnitType internalDisplayUnitTypeY = UnitsConverter.GetInternalUnit(unitTypeY); UnitSymbolType unitSymbolTypeY = formatOptions.UnitSymbol; switch (unitTypeY) { case UnitType.UT_Reinforcement_Area: axisTitle = Resources.ResourceManager.GetString("AxisArea"); break; case UnitType.UT_Force: axisTitle = Resources.ResourceManager.GetString("AxisForce"); break; case UnitType.UT_Moment: axisTitle = Resources.ResourceManager.GetString("AxisMoment"); break; case UnitType.UT_Displacement_Deflection: axisTitle = Resources.ResourceManager.GetString("AxisDisplacmentDeflection"); break; case UnitType.UT_Section_Dimension: axisTitle = Resources.ResourceManager.GetString("AxisSpacing"); break; case UnitType.UT_Reinforcement_Area_per_Unit_Length: axisTitle = Resources.ResourceManager.GetString("AxisDencity"); break; default: break; } axisTitle += " "; if (UnitSymbolType.UST_NONE == unitSymbolTypeY) { if (DisplayUnitType.DUT_FEET_FRACTIONAL_INCHES == displayUnitTypeY) { axisTitle += LabelUtils.GetLabelFor(UnitSymbolType.UST_FT); } else if (DisplayUnitType.DUT_FRACTIONAL_INCHES == displayUnitTypeY) { axisTitle += LabelUtils.GetLabelFor(UnitSymbolType.UST_IN); } } else { axisTitle += LabelUtils.GetLabelFor(unitSymbolTypeY); } chart.AxisY.Title = axisTitle; double valX = 0; double valY = 0; foreach (ResultTypeLinear resultType in resultTypes) { DocumentDiagramSeries series = new DocumentDiagramSeries(resultType.ToString()); chart.Legend = true; chart.Series.Add(series); series.Color = ResultTypeLinearToColorDictionary[resultType]; series.Name = Resources.ResourceManager.GetString(resultType.ToString()); int lblNbr = 5; int lblN = 0; int lblStep = resultsInPoints.Count <ResultInPointLinear>() / lblNbr; // Labels on the X axis will be formatted according to Revit preferences //formatOptions = units.GetFormatOptions(unitTypeX); //string accuracy = formatOptions.Accuracy.ToString(); //accuracy = accuracy.Replace("1", "0"); string valXAsString = ""; foreach (ResultInPointLinear resultInPoint in resultsInPoints) { valX = Autodesk.Revit.DB.UnitUtils.Convert(resultInPoint[ResultTypeLinear.X], internalDisplayUnitTypeX, displayUnitTypeX); valY = Autodesk.Revit.DB.UnitUtils.Convert(resultInPoint[resultType], internalDisplayUnitTypeY, displayUnitTypeY); series.AddXY(valX, valY); if (lblStep == 0 || lblN % lblStep == 0) { //DocumentValue docVal = new DocumentValue(resultInPoint[ResultTypeLinear.X], displayUnitTypeX, unitTypeX, units); DocumentValue docVal = new DocumentValue(valX, displayUnitTypeX, unitTypeX, units); valXAsString = (string)docVal.Value; chart.AxisX.Labels.Add(new DocumentDiagramAxisLabel(valX, valXAsString)); } lblN++; } } } } return(chart); }