/// <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();
            }
        }
Exemplo n.º 3
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = commandData.Application.ActiveUIDocument.Document;

            View activeview = uidoc.ActiveView;

            //找plot视图
            FilteredElementCollector collector = new FilteredElementCollector(doc);
            IEnumerable <Element>    views     = collector.OfClass(typeof(View)).WhereElementIsNotElementType();
            IEnumerable <ElementId>  viewids   =
                from element in views
                let view = element as View
                           //where view.Name.Contains("PLOT")
                           let para = view.LookupParameter("VIEW-Content")
                                      where para != null
                                      where para.AsString() == "02.PLOT" || para.AsString() == "03.INTF"
                                      where !view.IsTemplate
                                      select view.Id;

            if (viewids == null || viewids.Count() == 0)
            {
                TaskDialog.Show("wrong", "未找到包含PLOT的视图"); return(Result.Failed);
            }

            OverrideGraphicSettings ogs = new OverrideGraphicSettings();

            Window1 window = new Window1();

            window.ShowDialog();
            if (window.i == 0)
            {
                return(Result.Cancelled);
            }
            if (window.i == 1)
            {
                ogs.SetProjectionLineColor(new Color(0, 0, 0));
            }

            using (Transaction transaction = new Transaction(doc))
            {
                transaction.Start("将线改色");
                foreach (ElementId viewid in viewids)
                {
                    View view = doc.GetElement(viewid) as View;
                    //找线
                    FilteredElementCollector linecollector = new FilteredElementCollector(doc);
                    linecollector.OfCategory(BuiltInCategory.OST_Lines).OwnedByView(viewid).WhereElementIsNotElementType();
                    List <ElementId> lineids = linecollector.ToElementIds().ToList();
                    //找填充
                    FilteredElementCollector filledregioncollector = new FilteredElementCollector(doc);
                    filledregioncollector.OfCategory(BuiltInCategory.OST_DetailComponents).OfClass(typeof(FilledRegion)).WhereElementIsNotElementType();
                    List <ElementId> filledregionids = filledregioncollector.ToElementIds().ToList();
                    for (int i = filledregionids.Count - 1; i >= 0; i--)
                    {
                        FilledRegion     fr      = doc.GetElement(filledregionids[i]) as FilledRegion;
                        FilledRegionType type_fr = doc.GetElement(fr.GetTypeId()) as FilledRegionType;
                        if (type_fr.Name == "A-MATE-CONC-PLAN")
                        {
                            filledregionids.RemoveAt(i); continue;
                        }
                        if (type_fr.Name == "A-MATE-CONC-50")
                        {
                            filledregionids.RemoveAt(i); continue;
                        }
                        if (type_fr.Name == "A-MATE-CONC-ARAT")
                        {
                            filledregionids.RemoveAt(i); continue;
                        }
                        if (type_fr.Name == "A-MATE-CONC-100")
                        {
                            filledregionids.RemoveAt(i); continue;
                        }
                    }

                    foreach (ElementId id in lineids)
                    {
                        view.SetElementOverrides(id, ogs);
                    }
                    foreach (ElementId id in filledregionids)
                    {
                        view.SetElementOverrides(id, ogs);
                    }
                }
                transaction.Commit();
            }



            return(Result.Succeeded);
        }
Exemplo n.º 4
0
        /// <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 ? 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();
            }
        }
Exemplo n.º 5
0
        /***************************************************/
        /****               Public Methods              ****/
        /***************************************************/

        public static DraftingInstance DraftingInstanceFromRevit(this FilledRegion filledRegion, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            settings = settings.DefaultIfNull();

            DraftingInstance draftingInstance = refObjects.GetValue <DraftingInstance>(filledRegion.Id);

            if (draftingInstance != null)
            {
                return(draftingInstance);
            }

            View view = filledRegion.Document.GetElement(filledRegion.OwnerViewId) as View;

            if (view == null)
            {
                return(null);
            }

            InstanceProperties instanceProperties = (filledRegion.Document.GetElement(filledRegion.GetTypeId()) as ElementType).InstancePropertiesFromRevit(settings, refObjects) as InstanceProperties;

            List <ICurve> curves = new List <oM.Geometry.ICurve>();

            foreach (CurveLoop loop in filledRegion.GetBoundaries())
            {
                curves.Add(loop.FromRevit());
            }

            List <PlanarSurface> surfaces = BH.Engine.Geometry.Create.PlanarSurface(curves);

            if (surfaces.Count == 1)
            {
                draftingInstance = new DraftingInstance {
                    Properties = instanceProperties, ViewName = view.Name, Location = surfaces[0]
                }
            }
            ;
            else
            {
                draftingInstance = new DraftingInstance {
                    Properties = instanceProperties, ViewName = view.Name, Location = new PolySurface {
                        Surfaces = surfaces.Cast <ISurface>().ToList()
                    }
                }
            };

            draftingInstance.Name = filledRegion.Name;

            //Set identifiers, parameters & custom data
            draftingInstance.SetIdentifiers(filledRegion);
            draftingInstance.CopyParameters(filledRegion, settings.ParameterSettings);
            draftingInstance.SetProperties(filledRegion, settings.ParameterSettings);

            refObjects.AddOrReplace(filledRegion.Id, draftingInstance);
            return(draftingInstance);
        }

        /***************************************************/
    }