private void radioMetric_Checked(object sender, RoutedEventArgs e) { revitElementAnalyser = null; revitUnitsUI = false; unitSystem = Autodesk.Revit.DB.DisplayUnit.METRIC; if (revitElements != null && revitElements.Count > 0) { DataBinding(revitElements[elements.Items.CurrentPosition]); } }
/// <summary> /// Creates maps based on surface results. The maps can be displayed in the documentation. /// </summary> /// <param name="element">Revit element for which result document is built</param> /// <param name="resultsInPoints">Result in point collection</param> /// <param name="resultTypes">The type of results, values and description that can be displayed on the maps.</param> /// <returns>Returns list of documets maps based on results that can be displayed in the documentation</returns> private List <DocumentMap> CreateResultMapSeriesForSurfaceElements(Element element, ICollection <ResultInPointSurface> resultsInPoints, IEnumerable <Tuple <ResultTypeSurface, string> > resultTypes) { List <DocumentMap> vDocMap = new List <DocumentMap>(); MapDataGenerator mapPoints = new MapDataGenerator(); foreach (Tuple <ResultTypeSurface, string> forceDesc in resultTypes) { List <double> resData = resultsInPoints.Select(s => s[forceDesc.Item1]).ToList(); if (resData.Max(s => (Math.Abs(s))) < 1.0e-8) { continue; } AnalyticalModel slab = element as AnalyticalModel; DisplayUnit displayUnit = DisplayUnit.IMPERIAL; if (Server.UnitSystem == Autodesk.Revit.DB.ResultsBuilder.UnitsSystem.Metric) { displayUnit = DisplayUnit.METRIC; } ElementAnalyser elementAnalyser = new ElementAnalyser(displayUnit); ElementInfo info = elementAnalyser.Analyse(element); XYZ xyz = new XYZ(); if (info != null) { foreach (ResultInPointSurface resInPt in resultsInPoints) { mapPoints.AddPoint(new XYZ(resInPt[ResultTypeSurface.X], resInPt[ResultTypeSurface.Y], resInPt[ResultTypeSurface.Z]), resInPt[forceDesc.Item1]); } var contourAndHoles = getContourAndHolePoints(info); contourAndHoles.Item1.ForEach(s => mapPoints.AddPointToContour(s)); contourAndHoles.Item2.ForEach(s => mapPoints.AddHole(s)); UnitType ut = forceDesc.Item1.GetUnitType(); DocumentMap docMap = new DocumentMap(ut, UnitsConverter.GetInternalUnit(ut)); docMap.Title = forceDesc.Item2; int nofPoints = mapPoints.Count; for (int ptId = 0; ptId < nofPoints; ptId++) { UV pt = mapPoints.GetPoint(ptId); docMap.AddPoint(pt.U, pt.V, mapPoints.GetValue(ptId)); } List <List <int> > holes = mapPoints.Holes; foreach (List <int> hole in holes) { docMap.AddHole(hole); } docMap.DefineContour(mapPoints.Contour); vDocMap.Add(docMap); } mapPoints.Clear(); } return(vDocMap); }
/// <summary> /// Gives possibility to read data from Revit data base and puts them into user element's objects and into user section's objects and into user common parameters. /// </summary> /// <param name="listElementData">List of user element objects.</param> /// <param name="parameters">User common parameters.</param> /// <param name="data">Acces to cref="ServiceData".</param> public void ReadFromRevitDB(List <ObjectDataBase> listElementData, CommonParametersBase parameters, Autodesk.Revit.DB.CodeChecking.ServiceData data) { // read additional information from Revit data and store them in user objects derived from ElementDataBase and listed in listElementData Autodesk.Revit.DB.CodeChecking.NotificationService.ProgressStart(Resources.ResourceManager.GetString("ReadingGeometry"), listElementData.Count); ElementAnalyser elementAnalyser = new ElementAnalyser(GetInputDataUnitSystem()); int step = 0; foreach (ObjectDataBase elemData in listElementData) { Element element = data.Document.GetElement(elemData.ElementId); if (element != null) { switch (elemData.Category) { default: break; case Autodesk.Revit.DB.BuiltInCategory.OST_ColumnAnalytical: { ColumnElement elem = elemData as ColumnElement; if (elem != null && !elem.Status.IsError()) { elem.Info = elementAnalyser.Analyse(element); if (elem.Info.Material.Characteristics.YoungModulus.X < Double.Epsilon) { elem.Status.AddError(Resources.ResourceManager.GetString("ErrYoungModulus")); } MaterialConcreteCharacteristics concrete = (MaterialConcreteCharacteristics)elem.Info.Material.Characteristics.Specific; if (concrete == null || concrete.Compression < Double.Epsilon) { elem.Status.AddError(Resources.ResourceManager.GetString("ErrConcreteCompression")); } foreach (SectionDataBase sectionDataBase in elem.ListSectionData) { ColumnSection sec = sectionDataBase as ColumnSection; if (sec != null) { sec.Info = elem.Info; } } } break; } case Autodesk.Revit.DB.BuiltInCategory.OST_BeamAnalytical: { BeamElement elem = elemData as BeamElement; if (elem != null && !elem.Status.IsError()) { elementAnalyser.TSectionAnalysis = false; LabelBeam labelBeam = elem.Label as LabelBeam; if (labelBeam != null) { elementAnalyser.TSectionAnalysis = labelBeam.SlabBeamInteraction == BeamSectionType.WithSlabBeamInteraction; } elem.Info = elementAnalyser.Analyse(element); if (elem.Info.Material.Characteristics.YoungModulus.X < Double.Epsilon) { elem.Status.AddError(Resources.ResourceManager.GetString("ErrYoungModulus")); } MaterialConcreteCharacteristics concrete = (MaterialConcreteCharacteristics)elem.Info.Material.Characteristics.Specific; if (concrete == null || concrete.Compression < Double.Epsilon) { elem.Status.AddError(Resources.ResourceManager.GetString("ErrConcreteCompression")); } foreach (SectionDataBase sectionDataBase in elem.ListSectionData) { BeamSection sec = sectionDataBase as BeamSection; if (sec != null) { sec.Info = elem.Info; } } } break; } } } Autodesk.Revit.DB.CodeChecking.NotificationService.ProgressStep(string.Format("{0:d}%", ++step * 100 / listElementData.Count)); if (NotificationService.ProgressBreakInvoked()) { break; } } }
//-------------------------------------------------------------- #endregion #region public methods //-------------------------------------------------------------- public void DataBinding(Autodesk.Revit.DB.Element revitElement) { UnitsAssignment.RevitUnits = revitElement.Document.GetUnits(); if (null == revitElementAnalyser) { revitElementAnalyser = revitUnitsUI ? new ElementAnalyser() : new ElementAnalyser(unitSystem); revitElementAnalyser.TSectionAnalysis = true; } ElementInfo elementInfo = revitElementAnalyser.Analyse(revitElement); switch (elementInfo.Type) { case ElementType.Beam: case ElementType.Column: elementSizeLabel.Content = "Length:"; if (revitUnitsUI) { elementSizeValue.Content = UnitsAssignment.FormatToRevitUI("GeomLength", elementInfo.GeomLength(), ElementInfoUnits.Assignments, true); } else { elementSizeValue.Content = elementInfo.GeomLength().ToString(); elementSizeValue.Content += " " + UnitsAssignment.GetUnitSymbol("GeomLength", ElementInfoUnits.Assignments, unitSystem); } SectionShapeType shapeType = SectionShapeType.Unusual; if (elementInfo.SectionsParams != null) { shapeType = elementInfo.SectionsParams.ShapeType; } bool tSectionCollapsedWhenSelected = false; tabSlab.Visibility = System.Windows.Visibility.Collapsed; tabWall.Visibility = System.Windows.Visibility.Collapsed; if (elementInfo.Slabs != null && elementInfo.Slabs.TSection != null) { tabTSection.Visibility = System.Windows.Visibility.Visible; tSectionDescription.DoBinding(elementInfo.Slabs, revitUnitsUI ? null : (Autodesk.Revit.DB.DisplayUnit?)unitSystem, elementInfo.GeomLength()); } else { if (tabTSection.IsSelected) { tSectionCollapsedWhenSelected = true; } tabTSection.Visibility = System.Windows.Visibility.Collapsed; } tabProfile.Visibility = System.Windows.Visibility.Visible; if (tabSlab.IsSelected || true == tSectionCollapsedWhenSelected || tabWall.IsSelected) { IInputElement previousFocusedElement = FocusManager.GetFocusedElement(this); tabProfile.Focus(); if (previousFocusedElement != null) { previousFocusedElement.Focus(); } } sectionDescription.DoBinding(shapeType, elementInfo.Sections, elementInfo.Material != null ? elementInfo.Material.Category == MaterialCategory.Metal : false); sectionParameters.DoBinding(revitElement.Name, elementInfo.SectionsParams, revitUnitsUI ? null : (Autodesk.Revit.DB.DisplayUnit?)unitSystem); break; case ElementType.Slab: elementSizeLabel.Content = "Thickness:"; if (revitUnitsUI) { if (elementInfo.Slabs.AsElement != null) { elementSizeValue.Content = UnitsAssignment.FormatToRevitUI("SlabThickness", elementInfo.Slabs.AsElement.Thickness(), ElementInfoUnits.Assignments, true); } } else { if (elementInfo.Slabs.AsElement != null) { elementSizeValue.Content = elementInfo.Slabs.AsElement.Thickness().ToString(); elementSizeValue.Content += " " + UnitsAssignment.GetUnitSymbol("SlabThickness", ElementInfoUnits.Assignments, unitSystem); } } tabProfile.Visibility = System.Windows.Visibility.Collapsed; tabTSection.Visibility = System.Windows.Visibility.Collapsed; tabWall.Visibility = System.Windows.Visibility.Collapsed; tabSlab.Visibility = System.Windows.Visibility.Visible; if (tabProfile.IsSelected || tabTSection.IsSelected || tabWall.IsSelected) { IInputElement previousFocusedElement = FocusManager.GetFocusedElement(this); tabSlab.Focus(); if (previousFocusedElement != null) { previousFocusedElement.Focus(); } } slabDescription.DoBinding(elementInfo.Slabs, revitUnitsUI ? null : (Autodesk.Revit.DB.DisplayUnit?)unitSystem); break; case ElementType.Wall: elementSizeLabel.Content = "Thickness:"; if (revitUnitsUI) { elementSizeValue.Content = UnitsAssignment.FormatToRevitUI("WallThickness", elementInfo.Walls.AsElement.Thickness(), ElementInfoUnits.Assignments, true); } else { elementSizeValue.Content = elementInfo.Walls.AsElement.Thickness().ToString(); elementSizeValue.Content += " " + UnitsAssignment.GetUnitSymbol("SlabThickness", ElementInfoUnits.Assignments, unitSystem); } tabProfile.Visibility = System.Windows.Visibility.Collapsed; tabTSection.Visibility = System.Windows.Visibility.Collapsed; tabSlab.Visibility = System.Windows.Visibility.Collapsed; tabWall.Visibility = System.Windows.Visibility.Visible; if (tabProfile.IsSelected || tabSlab.IsSelected || tabTSection.IsSelected) { IInputElement previousFocusedElement = FocusManager.GetFocusedElement(this); tabWall.Focus(); if (previousFocusedElement != null) { previousFocusedElement.Focus(); } } wallDescription.DoBinding(elementInfo.Walls.AsElement, revitUnitsUI ? null : (Autodesk.Revit.DB.DisplayUnit?)unitSystem); break; case ElementType.Unknown: default: elementSizeLabel.Content = ""; elementSizeValue.Content = ""; tabProfile.Visibility = System.Windows.Visibility.Collapsed; tabSlab.Visibility = System.Windows.Visibility.Collapsed; tabTSection.Visibility = System.Windows.Visibility.Collapsed; tabWall.Visibility = System.Windows.Visibility.Collapsed; if (tabProfile.IsSelected || tabSlab.IsSelected || tabTSection.IsSelected || tabWall.IsSelected) { IInputElement previousFocusedElement = FocusManager.GetFocusedElement(this); tabMaterial.Focus(); if (previousFocusedElement != null) { previousFocusedElement.Focus(); } } break; } MaterialLayerDescription layerDescription = null; Layer structuralLayer = null; if (elementInfo.Type == ElementType.Slab) { if (elementInfo.Slabs.AsElement != null) { structuralLayer = elementInfo.Slabs.AsElement.StructuralLayer(); } } if (elementInfo.Type == ElementType.Wall) { structuralLayer = elementInfo.Walls.AsElement.StructuralLayer(); } if (structuralLayer != null) { layerDescription = new MaterialLayerDescription(structuralLayer.Thickness, structuralLayer.Offset); } materialParameters.DoBinding(elementInfo.Material, layerDescription, revitUnitsUI ? null : (Autodesk.Revit.DB.DisplayUnit?)unitSystem); }