// // (C) Copyright 2003-2019 by Autodesk, Inc. // // Permission to use, copy, modify, and distribute this software in // object code form for any purpose and without fee is hereby granted, // provided that the above copyright notice appears in all copies and // that both that copyright notice and the limited warranty and // restricted rights notice below appear in all supporting // documentation. // // AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. // AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF // MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC. // DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE // UNINTERRUPTED OR ERROR FREE. // // Use, duplication, or disclosure by the U.S. Government is subject to // restrictions set forth in FAR 52.227-19 (Commercial Computer // Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) // (Rights in Technical Data and Computer Software), as applicable. // using System; using System.Collections.Generic; using System.Text; using System.Drawing; using System.Drawing.Drawing2D; using System.Collections.ObjectModel; using System.Linq; using Autodesk.Revit; using Autodesk.Revit.DB; using Autodesk.Revit.DB.Structure; using Element = Autodesk.Revit.DB.Element; using GeomElement = Autodesk.Revit.DB.GeometryElement; using GeomInstance = Autodesk.Revit.DB.Instance; namespace Revit.SDK.Samples.ObjectViewer.CS { /// /// generate GraphicsData by give geometry object /// public class ModelData { // BoundingBox of the geometry private BoundingBoxXYZ m_bbox; private List> m_curve3Ds = new List>(); private List> m_curve2Ds = new List>(); /// /// 3D graphics data of the geometry /// public Graphics3DData Data3D { get { return new Graphics3DData(new List>(m_curve3Ds), m_bbox); } } /// /// 2D graphics data of the geometry /// public Graphics2DData Data2D { get { return new Graphics2DData(new List>(m_curve2Ds)); } } /// /// Generate appropriate graphics data object from exact analytical model type. /// /// The selected element maybe has analytical model lines /// A graphics data object appropriate for GDI. public ModelData(Element element) { try { AnalyticalElement analyticalMode = GetAnalyticalElement(element); View currentView = Command.CommandData.Application.ActiveUIDocument.Document.ActiveView; m_bbox = element.get_BoundingBox(currentView); if (null == analyticalMode) { return; } GetModelData(analyticalMode); } catch (Exception) { } } /// /// Get the analytical model object from an element. /// /// The selected element maybe has analytical model lines /// Return analytical model object, or else return null. private AnalyticalElement GetAnalyticalElement(Element element) { Document document = element.Document; AnalyticalElement analyticalElement = null; AnalyticalToPhysicalAssociationManager assocManager = AnalyticalToPhysicalAssociationManager.GetAnalyticalToPhysicalAssociationManager(document); if (assocManager != null) { ElementId associatedElementId = assocManager.GetAssociatedElementId(element.Id); if (associatedElementId != ElementId.InvalidElementId) { Element associatedElement = document.GetElement(associatedElementId); if (associatedElement != null && associatedElement is AnalyticalElement) { analyticalElement = associatedElement as AnalyticalElement; } } } return analyticalElement; } /// /// create GraphicsData of give AnalyticalElement /// /// AnalyticalElement contains geometry data /// A graphics data object appropriate for GDI. private void GetModelData(AnalyticalElement model) { if (model == null) return; if (model is AnalyticalMember) { m_curve3Ds.Add(model.GetCurve().Tessellate() as List); } else if (model is AnalyticalPanel) { foreach (Curve curve in (model as AnalyticalPanel).GetOuterContour()) { try { m_curve3Ds.Add(curve.Tessellate() as List); } catch { } } } } } }