/// <summary> /// Get the handles of Grid Axes. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="sameDirectionAxes">The grid axes in the same direction of one level.</param> /// <param name="representations">The representation of grid axis.</param> /// <returns>The list of handles of grid axes.</returns> private static List <IFCAnyHandle> CreateIFCGridAxisAndRepresentations(ExporterIFC exporterIFC, ProductWrapper productWrapper, IList <Grid> sameDirectionAxes, IList <IFCAnyHandle> representations, GridRepresentationData gridRepresentationData) { if (sameDirectionAxes.Count == 0) { return(null); } IDictionary <ElementId, List <IFCAnyHandle> > gridAxisMap = new Dictionary <ElementId, List <IFCAnyHandle> >(); IDictionary <ElementId, List <IFCAnyHandle> > gridRepMap = new Dictionary <ElementId, List <IFCAnyHandle> >(); IFCFile ifcFile = exporterIFC.GetFile(); Grid baseGrid = sameDirectionAxes[0]; Transform lcs = Transform.Identity; List <IFCAnyHandle> ifcGridAxes = new List <IFCAnyHandle>(); foreach (Grid grid in sameDirectionAxes) { // Because the IfcGrid is a collection of Revit Grids, any one of them can override the IFC CAD Layer. // We will take the first name, and not do too much checking. if (string.IsNullOrWhiteSpace(gridRepresentationData.m_IFCCADLayer)) { ParameterUtil.GetStringValueFromElementOrSymbol(grid, "IFCCadLayer", out gridRepresentationData.m_IFCCADLayer); } // Get the handle of curve. XYZ projectionDirection = lcs.BasisZ; IFCAnyHandle axisCurve; if (ExporterCacheManager.ExportOptionsCache.ExportAs4ReferenceView) { axisCurve = GeometryUtil.CreatePolyCurveFromCurve(exporterIFC, grid.Curve, lcs, projectionDirection); } else { IFCGeometryInfo info = IFCGeometryInfo.CreateCurveGeometryInfo(exporterIFC, lcs, projectionDirection, false); ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, grid.Curve, XYZ.Zero, false); IList <IFCAnyHandle> curves = info.GetCurves(); if (curves.Count != 1) { throw new Exception("IFC: expected 1 curve when export curve element."); } axisCurve = curves[0]; } bool sameSense = true; if (baseGrid.Curve is Line) { Line baseLine = baseGrid.Curve as Line; Line axisLine = grid.Curve as Line; sameSense = (axisLine.Direction.IsAlmostEqualTo(baseLine.Direction)); } IFCAnyHandle ifcGridAxis = IFCInstanceExporter.CreateGridAxis(ifcFile, grid.Name, axisCurve, sameSense); ifcGridAxes.Add(ifcGridAxis); HashSet <IFCAnyHandle> AxisCurves = new HashSet <IFCAnyHandle>(); AxisCurves.Add(axisCurve); IFCAnyHandle repItemHnd = IFCInstanceExporter.CreateGeometricCurveSet(ifcFile, AxisCurves); // get the weight and color from the GridType to create the curve style. GridType gridType = grid.Document.GetElement(grid.GetTypeId()) as GridType; IFCData curveWidth = null; if (ExporterCacheManager.ExportOptionsCache.ExportAnnotations) { int outWidth; double width = (ParameterUtil.GetIntValueFromElement(gridType, BuiltInParameter.GRID_END_SEGMENT_WEIGHT, out outWidth) != null) ? outWidth : 1; curveWidth = IFCDataUtil.CreateAsPositiveLengthMeasure(width); } if (!ExporterCacheManager.ExportOptionsCache.ExportAs4ReferenceView) { int outColor; int color = (ParameterUtil.GetIntValueFromElement(gridType, BuiltInParameter.GRID_END_SEGMENT_COLOR, out outColor) != null) ? outColor : 0; double blueVal = 0.0; double greenVal = 0.0; double redVal = 0.0; GeometryUtil.GetRGBFromIntValue(color, out blueVal, out greenVal, out redVal); IFCAnyHandle colorHnd = IFCInstanceExporter.CreateColourRgb(ifcFile, null, redVal, greenVal, blueVal); BodyExporter.CreateCurveStyleForRepItem(exporterIFC, repItemHnd, curveWidth, colorHnd); } HashSet <IFCAnyHandle> curveSet = new HashSet <IFCAnyHandle>(); curveSet.Add(repItemHnd); gridRepresentationData.m_Grids.Add(grid); gridRepresentationData.m_curveSets.Add(curveSet); } return(ifcGridAxes); }
/// <summary> /// Get the handles of Grid Axes. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="sameDirectionAxes">The grid axes in the same direction of one level.</param> /// <param name="representations">The representation of grid axis.</param> /// <returns>The list of handles of grid axes.</returns> private static List<IFCAnyHandle> CreateIFCGridAxisAndRepresentations(ExporterIFC exporterIFC, ProductWrapper productWrapper, IList<Grid> sameDirectionAxes, IList<IFCAnyHandle> representations, GridRepresentationData gridRepresentationData) { if (sameDirectionAxes.Count == 0) return null; IDictionary<ElementId, List<IFCAnyHandle>> gridAxisMap = new Dictionary<ElementId, List<IFCAnyHandle>>(); IDictionary<ElementId, List<IFCAnyHandle>> gridRepMap = new Dictionary<ElementId, List<IFCAnyHandle>>(); IFCFile ifcFile = exporterIFC.GetFile(); Grid baseGrid = sameDirectionAxes[0]; Plane plane = new Plane(XYZ.BasisX, XYZ.BasisY, XYZ.Zero); List<IFCAnyHandle> ifcGridAxes = new List<IFCAnyHandle>(); foreach (Grid grid in sameDirectionAxes) { // Because the IfcGrid is a collection of Revit Grids, any one of them can override the IFC CAD Layer. // We will take the first name, and not do too much checking. if (string.IsNullOrWhiteSpace(gridRepresentationData.m_IFCCADLayer)) ParameterUtil.GetStringValueFromElementOrSymbol(grid, "IFCCadLayer", out gridRepresentationData.m_IFCCADLayer); // Get the handle of curve. XYZ projectionDirection = plane.Normal; IFCGeometryInfo info = IFCGeometryInfo.CreateCurveGeometryInfo(exporterIFC, plane, projectionDirection, false); ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, grid.Curve, XYZ.Zero, false); IList<IFCAnyHandle> curves = info.GetCurves(); if (curves.Count != 1) throw new Exception("IFC: expected 1 curve when export curve element."); IFCAnyHandle axisCurve = curves[0]; bool sameSense = true; if (baseGrid.Curve is Line) { Line baseLine = baseGrid.Curve as Line; Line axisLine = grid.Curve as Line; sameSense = (axisLine.Direction.IsAlmostEqualTo(baseLine.Direction)); } IFCAnyHandle ifcGridAxis = IFCInstanceExporter.CreateGridAxis(ifcFile, grid.Name, axisCurve, sameSense); ifcGridAxes.Add(ifcGridAxis); HashSet<IFCAnyHandle> AxisCurves = new HashSet<IFCAnyHandle>(); AxisCurves.Add(axisCurve); IFCAnyHandle repItemHnd = IFCInstanceExporter.CreateGeometricCurveSet(ifcFile, AxisCurves); // get the weight and color from the GridType to create the curve style. GridType gridType = grid.Document.GetElement(grid.GetTypeId()) as GridType; IFCData curveWidth = null; if (ExporterCacheManager.ExportOptionsCache.ExportAnnotations) { int outWidth; double width = (ParameterUtil.GetIntValueFromElement(gridType, BuiltInParameter.GRID_END_SEGMENT_WEIGHT, out outWidth) != null) ? outWidth : 1; curveWidth = IFCDataUtil.CreateAsPositiveLengthMeasure(width); } int outColor; int color = (ParameterUtil.GetIntValueFromElement(gridType, BuiltInParameter.GRID_END_SEGMENT_COLOR, out outColor) != null) ? outColor : 0; double blueVal = 0.0; double greenVal = 0.0; double redVal = 0.0; GeometryUtil.GetRGBFromIntValue(color, out blueVal, out greenVal, out redVal); IFCAnyHandle colorHnd = IFCInstanceExporter.CreateColourRgb(ifcFile, null, redVal, greenVal, blueVal); BodyExporter.CreateCurveStyleForRepItem(exporterIFC, repItemHnd, curveWidth, colorHnd); HashSet<IFCAnyHandle> curveSet = new HashSet<IFCAnyHandle>(); curveSet.Add(repItemHnd); gridRepresentationData.m_Grids.Add(grid); gridRepresentationData.m_curveSets.Add(curveSet); } return ifcGridAxes; }
/// <summary> /// Export one IFCGrid in one level. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="levelId">The level ID.</param> /// <param name="sameDirectionAxesU">The U axes of grids.</param> /// <param name="sameDirectionAxesV">The V axes of grids.</param> /// <param name="sameDirectionAxesW">The W axes of grids.</param> public static void ExportGrid(ExporterIFC exporterIFC, ElementId levelId, string gridName, List <Grid> sameDirectionAxesU, List <Grid> sameDirectionAxesV, List <Grid> sameDirectionAxesW) { List <IFCAnyHandle> axesU = null; List <IFCAnyHandle> axesV = null; List <IFCAnyHandle> axesW = null; List <IFCAnyHandle> representations = new List <IFCAnyHandle>(); using (ProductWrapper productWrapper = ProductWrapper.Create(exporterIFC, true)) { IFCFile ifcFile = exporterIFC.GetFile(); using (IFCTransaction transaction = new IFCTransaction(ifcFile)) { GridRepresentationData gridRepresentationData = new GridRepresentationData(); axesU = CreateIFCGridAxisAndRepresentations(exporterIFC, productWrapper, sameDirectionAxesU, representations, gridRepresentationData); axesV = CreateIFCGridAxisAndRepresentations(exporterIFC, productWrapper, sameDirectionAxesV, representations, gridRepresentationData); if (sameDirectionAxesW != null) { axesW = CreateIFCGridAxisAndRepresentations(exporterIFC, productWrapper, sameDirectionAxesW, representations, gridRepresentationData); } IFCAnyHandle contextOfItemsFootPrint = exporterIFC.Get3DContextHandle("FootPrint"); string identifierOpt = "FootPrint"; string representationTypeOpt = "GeometricCurveSet"; int numGridsToExport = gridRepresentationData.m_Grids.Count; if (numGridsToExport == 0) { return; } bool useIFCCADLayer = !string.IsNullOrWhiteSpace(gridRepresentationData.m_IFCCADLayer); IFCAnyHandle shapeRepresentation = null; HashSet <IFCAnyHandle> allCurves = new HashSet <IFCAnyHandle>(); for (int ii = 0; ii < numGridsToExport; ii++) { allCurves.UnionWith(gridRepresentationData.m_curveSets[ii]); } if (useIFCCADLayer) { shapeRepresentation = RepresentationUtil.CreateShapeRepresentation(exporterIFC, contextOfItemsFootPrint, identifierOpt, representationTypeOpt, allCurves, gridRepresentationData.m_IFCCADLayer); } else { ElementId catId = CategoryUtil.GetSafeCategoryId(gridRepresentationData.m_Grids[0]); shapeRepresentation = RepresentationUtil.CreateShapeRepresentation(exporterIFC, gridRepresentationData.m_Grids[0], catId, contextOfItemsFootPrint, identifierOpt, representationTypeOpt, allCurves); } representations.Add(shapeRepresentation); IFCAnyHandle productRep = IFCInstanceExporter.CreateProductDefinitionShape(ifcFile, null, null, representations); // We will associate the grid with its level, unless there are no levels in the file, in which case we'll associate it with the building. IFCLevelInfo levelInfo = ExporterCacheManager.LevelInfoCache.GetLevelInfo(exporterIFC, levelId); bool useLevelInfo = (levelInfo != null); string gridGUID = GUIDUtil.CreateGUID(); //// Get the first grid's override name, if cannot find it, use null. //string gridName = GetGridName(sameDirectionAxesU, sameDirectionAxesV, sameDirectionAxesW); IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle; IFCAnyHandle gridLevelHandle = useLevelInfo ? levelInfo.GetBuildingStorey() : ExporterCacheManager.BuildingHandle; IFCAnyHandle levelObjectPlacement = IFCAnyHandleUtil.GetObjectPlacement(gridLevelHandle); double elev = useLevelInfo ? levelInfo.Elevation : 0.0; double elevation = UnitUtil.ScaleLength(elev); XYZ orig = new XYZ(0.0, 0.0, elevation); IFCAnyHandle copyLevelPlacement = ExporterUtil.CopyLocalPlacement(ifcFile, levelObjectPlacement); IFCAnyHandle ifcGrid = IFCInstanceExporter.CreateGrid(exporterIFC, gridGUID, ownerHistory, gridName, copyLevelPlacement, productRep, axesU, axesV, axesW); productWrapper.AddElement(null, ifcGrid, levelInfo, null, true, null); transaction.Commit(); } } }
/// <summary> /// Export one IFCGrid in one level. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="levelId">The level ID.</param> /// <param name="sameDirectionAxesU">The U axes of grids.</param> /// <param name="sameDirectionAxesV">The V axes of grids.</param> /// <param name="sameDirectionAxesW">The W axes of grids.</param> public static void ExportGrid(ExporterIFC exporterIFC, ElementId levelId, List<Grid> sameDirectionAxesU, List<Grid> sameDirectionAxesV, List<Grid> sameDirectionAxesW) { List<IFCAnyHandle> axesU = null; List<IFCAnyHandle> axesV = null; List<IFCAnyHandle> axesW = null; List<IFCAnyHandle> representations = new List<IFCAnyHandle>(); using (ProductWrapper productWrapper = ProductWrapper.Create(exporterIFC, true)) { IFCFile ifcFile = exporterIFC.GetFile(); using (IFCTransaction transaction = new IFCTransaction(ifcFile)) { GridRepresentationData gridRepresentationData = new GridRepresentationData(); axesU = CreateIFCGridAxisAndRepresentations(exporterIFC, productWrapper, sameDirectionAxesU, representations, gridRepresentationData); axesV = CreateIFCGridAxisAndRepresentations(exporterIFC, productWrapper, sameDirectionAxesV, representations, gridRepresentationData); if (sameDirectionAxesW != null) axesW = CreateIFCGridAxisAndRepresentations(exporterIFC, productWrapper, sameDirectionAxesW, representations, gridRepresentationData); IFCAnyHandle contextOfItemsFootPrint = exporterIFC.Get3DContextHandle("FootPrint"); string identifierOpt = "FootPrint"; string representationTypeOpt = "GeometricCurveSet"; int numGridsToExport = gridRepresentationData.m_Grids.Count; if (numGridsToExport == 0) return; bool useIFCCADLayer = !string.IsNullOrWhiteSpace(gridRepresentationData.m_IFCCADLayer); IFCAnyHandle shapeRepresentation = null; HashSet<IFCAnyHandle> allCurves = new HashSet<IFCAnyHandle>(); for (int ii = 0; ii < numGridsToExport; ii++) allCurves.UnionWith(gridRepresentationData.m_curveSets[ii]); if (useIFCCADLayer) { shapeRepresentation = RepresentationUtil.CreateShapeRepresentation(exporterIFC, contextOfItemsFootPrint, identifierOpt, representationTypeOpt, allCurves, gridRepresentationData.m_IFCCADLayer); } else { ElementId catId = CategoryUtil.GetSafeCategoryId(gridRepresentationData.m_Grids[0]); shapeRepresentation = RepresentationUtil.CreateShapeRepresentation(exporterIFC, gridRepresentationData.m_Grids[0], catId, contextOfItemsFootPrint, identifierOpt, representationTypeOpt, allCurves); } representations.Add(shapeRepresentation); IFCAnyHandle productRep = IFCInstanceExporter.CreateProductDefinitionShape(ifcFile, null, null, representations); IFCLevelInfo levelInfo = ExporterCacheManager.LevelInfoCache.GetLevelInfo(exporterIFC, levelId); string gridGUID = GUIDUtil.CreateGUID(); // Get the first grid's override name, if cannot find it, use null. string gridName = GetGridName(sameDirectionAxesU, sameDirectionAxesV, sameDirectionAxesW); IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle(); IFCAnyHandle gridLevelHandle = levelInfo.GetBuildingStorey(); IFCAnyHandle levelObjectPlacement = IFCAnyHandleUtil.GetInstanceAttribute(gridLevelHandle, "ObjectPlacement"); double elev = levelInfo.Elevation; double scaleFactor = exporterIFC.LinearScale; double elevation = elev * scaleFactor; XYZ orig = new XYZ(0.0, 0.0, elevation); IFCAnyHandle copyLevelPlacement = ExporterUtil.CopyLocalPlacement(ifcFile, levelObjectPlacement); IFCAnyHandle ifcGrid = IFCInstanceExporter.CreateGrid(ifcFile, gridGUID, ownerHistory, gridName, null, null, copyLevelPlacement, productRep, axesU, axesV, axesW); productWrapper.AddElement(null, ifcGrid, levelInfo, null, true); transaction.Commit(); } } }