/// <summary> /// Exports an element as an annotation. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="filledRegion">The filled region element.</param> /// <param name="geometryElement">The geometry element.</param> /// <param name="productWrapper">The ProductWrapper.</param> public static void Export(ExporterIFC exporterIFC, FilledRegion filledRegion, GeometryElement geometryElement, ProductWrapper productWrapper) { if (filledRegion == null || geometryElement == null) { return; } // Check the intended IFC entity or type name is in the exclude list specified in the UI Common.Enums.IFCEntityType elementClassTypeEnum = Common.Enums.IFCEntityType.IfcAnnotation; if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum)) { return; } IFCFile file = exporterIFC.GetFile(); using (IFCTransaction transaction = new IFCTransaction(file)) { IList <CurveLoop> boundaries = filledRegion.GetBoundaries(); if (boundaries.Count == 0) { return; } Plane plane = null; try { plane = boundaries[0].GetPlane(); } catch { return; } Transform orientTrf = GeometryUtil.CreateTransformFromPlane(plane); XYZ projectionDirection = plane.Normal; IList <IList <CurveLoop> > sortedLoops = ExporterIFCUtils.SortCurveLoops(boundaries); if (sortedLoops.Count == 0) { return; } FilledRegionType filledRegionType = filledRegion.Document.GetElement(filledRegion.GetTypeId()) as FilledRegionType; Color color = filledRegionType != null?CategoryUtil.GetSafeColor(filledRegionType.ForegroundPatternColor) : new Color(0, 0, 0); ElementId foregroundPatternId = filledRegionType != null ? filledRegionType.ForegroundPatternId : ElementId.InvalidElementId; ElementId categoryId = CategoryUtil.GetSafeCategoryId(filledRegion); using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, filledRegion, null, orientTrf)) { foreach (IList <CurveLoop> curveLoopList in sortedLoops) { IFCAnyHandle outerCurve = null; HashSet <IFCAnyHandle> innerCurves = null; for (int ii = 0; ii < curveLoopList.Count; ii++) { IFCAnyHandle ifcCurve = GeometryUtil.CreateIFCCurveFromCurveLoop(exporterIFC, curveLoopList[ii], orientTrf, projectionDirection); if (ii == 0) { outerCurve = ifcCurve; } else { if (innerCurves == null) { innerCurves = new HashSet <IFCAnyHandle>(); } innerCurves.Add(ifcCurve); } } IFCAnyHandle representItem = IFCInstanceExporter.CreateAnnotationFillArea(file, outerCurve, innerCurves); file.CreateStyle(exporterIFC, representItem, color, foregroundPatternId); HashSet <IFCAnyHandle> bodyItems = new HashSet <IFCAnyHandle>(); bodyItems.Add(representItem); IFCAnyHandle bodyRepHnd = RepresentationUtil.CreateAnnotationSetRep(exporterIFC, filledRegion, categoryId, exporterIFC.Get2DContextHandle(), bodyItems); if (IFCAnyHandleUtil.IsNullOrHasNoValue(bodyRepHnd)) { return; } List <IFCAnyHandle> shapeReps = new List <IFCAnyHandle>(); shapeReps.Add(bodyRepHnd); IFCAnyHandle productShape = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, shapeReps); IFCAnyHandle annotation = IFCInstanceExporter.CreateAnnotation(exporterIFC, filledRegion, GUIDUtil.CreateGUID(), ExporterCacheManager.OwnerHistoryHandle, setter.LocalPlacement, productShape); productWrapper.AddAnnotation(annotation, setter.LevelInfo, true); } } transaction.Commit(); } }
/// <summary> /// Exports an element as an annotation. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="filledRegion">The filled region element.</param> /// <param name="geometryElement">The geometry element.</param> /// <param name="productWrapper">The ProductWrapper.</param> public static void Export(ExporterIFC exporterIFC, FilledRegion filledRegion, GeometryElement geometryElement, ProductWrapper productWrapper) { if (filledRegion == null || geometryElement == null) { return; } IFCFile file = exporterIFC.GetFile(); using (IFCTransaction transaction = new IFCTransaction(file)) { IList <CurveLoop> boundaries = filledRegion.GetBoundaries(); if (boundaries.Count == 0) { return; } Plane plane = null; try { plane = boundaries[0].GetPlane(); } catch { return; } Transform orientTrf = Transform.Identity; orientTrf.BasisX = plane.XVec; orientTrf.BasisY = plane.YVec; orientTrf.BasisZ = plane.Normal; orientTrf.Origin = plane.Origin; XYZ projectionDirection = plane.Normal; IList <IList <CurveLoop> > sortedLoops = ExporterIFCUtils.SortCurveLoops(boundaries); if (sortedLoops.Count == 0) { return; } FilledRegionType filledRegionType = filledRegion.Document.GetElement(filledRegion.GetTypeId()) as FilledRegionType; Color color = filledRegionType != null?CategoryUtil.GetSafeColor(filledRegionType.Color) : new Color(0, 0, 0); ElementId fillPatternId = filledRegionType != null ? filledRegionType.FillPatternId : ElementId.InvalidElementId; ElementId categoryId = CategoryUtil.GetSafeCategoryId(filledRegion); using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, filledRegion, null, orientTrf)) { foreach (IList <CurveLoop> curveLoopList in sortedLoops) { IFCAnyHandle outerCurve = null; HashSet <IFCAnyHandle> innerCurves = null; for (int ii = 0; ii < curveLoopList.Count; ii++) { IFCAnyHandle ifcCurve = GeometryUtil.CreateIFCCurveFromCurveLoop(exporterIFC, curveLoopList[ii], plane, projectionDirection); if (ii == 0) { outerCurve = ifcCurve; } else { if (innerCurves == null) { innerCurves = new HashSet <IFCAnyHandle>(); } innerCurves.Add(ifcCurve); } } IFCAnyHandle representItem = IFCInstanceExporter.CreateAnnotationFillArea(file, outerCurve, innerCurves); file.CreateStyle(exporterIFC, representItem, color, fillPatternId); HashSet <IFCAnyHandle> bodyItems = new HashSet <IFCAnyHandle>(); bodyItems.Add(representItem); IFCAnyHandle bodyRepHnd = RepresentationUtil.CreateAnnotationSetRep(exporterIFC, filledRegion, categoryId, exporterIFC.Get2DContextHandle(), bodyItems); if (IFCAnyHandleUtil.IsNullOrHasNoValue(bodyRepHnd)) { return; } List <IFCAnyHandle> shapeReps = new List <IFCAnyHandle>(); shapeReps.Add(bodyRepHnd); IFCAnyHandle productShape = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, shapeReps); IFCAnyHandle annotation = IFCInstanceExporter.CreateAnnotation(file, GUIDUtil.CreateGUID(), exporterIFC.GetOwnerHistoryHandle(), null, null, null, setter.LocalPlacement, productShape); productWrapper.AddAnnotation(annotation, setter.LevelInfo, true); } } transaction.Commit(); } }