/// <summary> /// Creats document section with table and graph /// </summary> /// <param name="sectionTitle">Title of the section</param> /// <param name="resultsInPoints"> Result in point collection</param> /// <param name="resultTypes">The type of results that will be displayed in the diagram and in the table.</param> /// <param name="document">Active Revit document</param> /// <param name="elementType">Structural element type</param> /// <param name="addTable">Enabling/disabling inserting a table</param> /// <param name="addDiagram">Enabling/disabling inserting a graph</param> /// <param name="tableTitle"> Title of the table</param> /// <param name="diagramTitle"> Title of the graph</param> /// <param name="reversedAxis">Sets the direction of the Y axis on the graph</param> /// <returns>Returns section of document with diagram and table</returns> private DocumentSection CreateSectionTableAndDiagramForLinearElements(ICollection <ResultInPointLinear> resultsInPoints, List <ResultTypeLinear> resultTypes, Autodesk.Revit.DB.Document document, ElementType elementType, bool addTable = true, bool addDiagram = true, bool reversedAxis = false, String sectionTitle = "", String tableTitle = "", String diagramTitle = "") { DocumentSection newDocumentSection = null; if (addTable || addDiagram) { newDocumentSection = new DocumentSection(sectionTitle, 5); newDocumentSection.Level = DetailLevel.Medium; if (addTable) { DocumentSection tableSection = new DocumentSection(tableTitle, 6); DocumentTable resultTable = CreateResultTableForLinearElements(resultsInPoints, resultTypes, document); resultTable.Level = DetailLevel.Medium; newDocumentSection.Body.Elements.Add(resultTable); } if (addDiagram) { DocumentSection diagramSection = new DocumentSection(); DocumentDiagram resultDiagram = CreateResultDiagramForLinearElements(diagramTitle, resultsInPoints, resultTypes, document, elementType, reversedAxis); resultDiagram.Level = DetailLevel.Detail; newDocumentSection.Body.Elements.Add(new DocumentLineBreak(2)); newDocumentSection.Body.Elements.Add(resultDiagram); } } return(newDocumentSection); }
/// <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); }