Esempio n. 1
0
        public void ByCurves_ValidArgs()
        {
            Autodesk.Revit.DB.FilteredElementCollector collector = new Autodesk.Revit.DB.FilteredElementCollector(Revit.Application.Document.Current.InternalDocument).OfClass(typeof(Autodesk.Revit.DB.FilledRegionType));
            FilledRegionType type = FilledRegionType.FromExisting((Autodesk.Revit.DB.FilledRegionType)collector.FirstOrDefault(), true);

            Assert.NotNull(type);

            Polygon polygon = Polygon.RegularPolygon(Circle.ByCenterPointRadius(Point.ByCoordinates(0, 0, 0), 10), 4);

            Assert.NotNull(polygon);

            var reg = FilledRegion.ByCurves(Revit.Application.Document.Current.ActiveView, polygon.Curves().ToList(), type);

            Assert.NotNull(reg);
        }
Esempio n. 2
0
 bool ISelectionFilter.AllowElement(Element elem)
 {
     if (elem is FilledRegion)
     {
         FilledRegionType _filledRegionType = Doc.GetElement(elem.GetTypeId()) as FilledRegionType;
         if (_filledRegionType.Name.Contains("地库外墙范围"))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
Esempio n. 3
0
        public void ByCircle_ValidArgs()
        {
            Autodesk.Revit.DB.FilteredElementCollector collector = new Autodesk.Revit.DB.FilteredElementCollector(Revit.Application.Document.Current.InternalDocument).OfClass(typeof(Autodesk.Revit.DB.FilledRegionType));
            FilledRegionType type = FilledRegionType.FromExisting((Autodesk.Revit.DB.FilledRegionType)collector.FirstOrDefault(), true);

            Assert.NotNull(type);

            Circle c = Circle.ByCenterPointRadius(Point.ByCoordinates(0, 0, 0), 10);

            Assert.NotNull(c);

            Curve[] curves = c.ApproximateWithArcAndLineSegments();

            // Approximate With Arc and Lines returns one Curve which is not closed. Seems odd.
            if (curves.Count() > 0 && curves[0].IsClosed)
            {
                var reg = FilledRegion.ByCurves(Revit.Application.Document.Current.ActiveView, curves, type);
                Assert.NotNull(reg);
            }
        }
        /// <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();
            }
        }
Esempio n. 5
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();
            }
        }
Esempio n. 6
0
        /***************************************************/

        private static Element ToRevitElement(this DraftingInstance draftingInstance, FilledRegionType regionType, View view, RevitSettings settings)
        {
            ISurface location = draftingInstance.Location as ISurface;

            List <PlanarSurface> surfaces = new List <PlanarSurface>();

            if (location is PlanarSurface)
            {
                surfaces.Add((PlanarSurface)location);
            }
            else if (location is PolySurface)
            {
                PolySurface polySurface = (PolySurface)location;
                if (polySurface.Surfaces.Any(x => !(x is PlanarSurface)))
                {
                    draftingInstance.InvalidRegionSurfaceError();
                    return(null);
                }

                surfaces = polySurface.Surfaces.Cast <PlanarSurface>().ToList();
            }
            else
            {
                draftingInstance.InvalidRegionSurfaceError();
                return(null);
            }

            List <CurveLoop> loops = new List <CurveLoop>();

            foreach (PlanarSurface surface in surfaces)
            {
                foreach (ICurve curve in surface.Edges())
                {
                    loops.Add(curve.ToRevitCurveLoop());
                }
            }

            if (loops.Count != 0)
            {
                return(FilledRegion.Create(view.Document, regionType.Id, view.Id, loops));
            }

            return(null);
        }
Esempio n. 7
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);
        }