/// <summary> /// Add all plan view boundary loops from /// given solid to the list of loops. /// The creation application argument is used to /// reverse the extrusion analyser output curves /// in case they are badly oriented. /// </summary> /// <returns>Number of loops added</returns> static int AddLoops( Autodesk.Revit.Creation.Application creapp, JtLoops loops, GeometryObject obj, ref int nExtrusionAnalysisFailures) { int nAdded = 0; Solid solid = obj as Solid; if (null != solid && 0 < solid.Faces.Size) { //Plane plane = new Plane(XYZ.BasisX, // XYZ.BasisY, XYZ.Zero); // 2016 Plane plane = Plane.CreateByOriginAndBasis( XYZ.Zero, XYZ.BasisX, XYZ.BasisY); // 2017 ExtrusionAnalyzer extrusionAnalyzer = null; try { extrusionAnalyzer = ExtrusionAnalyzer.Create( solid, plane, XYZ.BasisZ); } catch (Autodesk.Revit.Exceptions .InvalidOperationException) { ++nExtrusionAnalysisFailures; return(nAdded); } Face face = extrusionAnalyzer .GetExtrusionBase(); loops.Add(GetLoop(creapp, face)); ++nAdded; } return(nAdded); }
/// <summary> /// Set the ExtrusionBase from the ExtrusionAnalyzer /// </summary> /// <param name="extrusionAnalyzer">Extrusion Analyzer</param> /// <param name="lcs">the LCS</param> /// <param name="baseLoopOffset">offset</param> public FootPrintInfo(ExtrusionAnalyzer extrusionAnalyzer, Transform lcs = null, XYZ baseLoopOffset = null) { Face extrusionBase = extrusionAnalyzer.GetExtrusionBase(); IList <GeometryUtil.FaceBoundaryType> boundaryTypes; if (lcs == null) { lcs = Transform.Identity; } if (baseLoopOffset == null) { baseLoopOffset = XYZ.Zero; } IList <CurveLoop> extrusionBoundaryLoops = GeometryUtil.GetFaceBoundaries(extrusionBase, baseLoopOffset, out boundaryTypes); if (extrusionBoundaryLoops == null || extrusionBoundaryLoops.Count == 0 || extrusionBoundaryLoops[0] == null) { return; } // Move base plane to start parameter location. Plane extrusionBasePlane = null; try { extrusionBasePlane = extrusionBoundaryLoops[0].GetPlane(); } catch { return; } // Only the first CurveLoop will be used as the foorprint ExtrusionBaseLoops = extrusionBoundaryLoops; ExtrusionBaseLCS = lcs; }
/// <summary> /// Generates an IFCExtrusionCreationData from ExtrusionAnalyzer results /// </summary> /// <remarks>This will be used to populate certain property sets.</remarks> /// <param name="exporterIFC">The exporter.</param> /// <param name="projDir">The projection direction of the extrusion.</param> /// <param name="analyzer">The extrusion analyzer.</param> /// <returns>The IFCExtrusionCreationData information.</returns> public static IFCExtrusionCreationData GetExtrusionCreationDataFromAnalyzer(ExporterIFC exporterIFC, XYZ projDir, ExtrusionAnalyzer analyzer) { IFCExtrusionCreationData exportBodyParams = new IFCExtrusionCreationData(); XYZ extrusionDirection = analyzer.ExtrusionDirection; double zOff = MathUtil.IsAlmostEqual(Math.Abs(projDir[2]), 1.0) ? (1.0 - Math.Abs(extrusionDirection[2])) : Math.Abs(extrusionDirection[2]); double scaledAngle = UnitUtil.ScaleAngle(MathUtil.SafeAsin(zOff)); exportBodyParams.Slope = scaledAngle; exportBodyParams.ScaledLength = UnitUtil.ScaleLength(analyzer.EndParameter - analyzer.StartParameter); exportBodyParams.ExtrusionDirection = extrusionDirection; // no opening data support yet. Face extrusionBase = analyzer.GetExtrusionBase(); if (extrusionBase == null) return null; IList<GeometryUtil.FaceBoundaryType> boundaryTypes; IList<CurveLoop> boundaries = GeometryUtil.GetFaceBoundaries(extrusionBase, XYZ.Zero, out boundaryTypes); if (boundaries.Count == 0) return null; Plane plane = null; double height = 0.0, width = 0.0; if (ExtrusionExporter.ComputeHeightWidthOfCurveLoop(boundaries[0], plane, out height, out width)) { exportBodyParams.ScaledHeight = UnitUtil.ScaleLength(height); exportBodyParams.ScaledWidth = UnitUtil.ScaleLength(width); } double area = extrusionBase.Area; if (area > 0.0) { exportBodyParams.ScaledArea = UnitUtil.ScaleArea(area); } double innerPerimeter = ExtrusionExporter.ComputeInnerPerimeterOfCurveLoops(boundaries); double outerPerimeter = ExtrusionExporter.ComputeOuterPerimeterOfCurveLoops(boundaries); if (innerPerimeter > 0.0) exportBodyParams.ScaledInnerPerimeter = UnitUtil.ScaleLength(innerPerimeter); if (outerPerimeter > 0.0) exportBodyParams.ScaledOuterPerimeter = UnitUtil.ScaleLength(outerPerimeter); return exportBodyParams; }