コード例 #1
0
        /// <summary>
        /// The command implementation.
        /// </summary>
        /// <param name="commandData"></param>
        /// <param name="message"></param>
        /// <param name="elements"></param>
        /// <returns></returns>
        public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Autodesk.Revit.ApplicationServices.Application application = commandData.Application.Application;
            Document doc = commandData.Application.ActiveUIDocument.Document;

            // Find target document - it must be the only other open document in session
            Document toDocument = null;
            IEnumerable <Document> documents = application.Documents.Cast <Document>();

            if (documents.Count <Document>() != 2)
            {
                TaskDialog.Show("No target document",
                                "This tool can only be used if there are two documents (a source document and target document).");
                return(Result.Cancelled);
            }
            foreach (Document loadedDoc in documents)
            {
                if (loadedDoc.Title != doc.Title)
                {
                    toDocument = loadedDoc;
                    break;
                }
            }

            // Collect schedules and drafting views
            FilteredElementCollector collector = new FilteredElementCollector(doc);

            List <Type> viewTypes = new List <Type>();

            viewTypes.Add(typeof(ViewSchedule));
            viewTypes.Add(typeof(ViewDrafting));
            ElementMulticlassFilter filter = new ElementMulticlassFilter(viewTypes);

            collector.WherePasses(filter);

            collector.WhereElementIsViewIndependent(); // skip view-specfic schedules (e.g. Revision Schedules);
            // These should not be copied as they are associated to another view that cannot be copied

            // Copy all schedules together so that any dependency elements are copied only once
            IEnumerable <ViewSchedule> schedules = collector.OfType <ViewSchedule>();

            DuplicateViewUtils.DuplicateSchedules(doc, schedules, toDocument);
            int numSchedules = schedules.Count <ViewSchedule>();

            // Copy drafting views together
            IEnumerable <ViewDrafting> draftingViews = collector.OfType <ViewDrafting>();
            int numDraftingElements =
                DuplicateViewUtils.DuplicateDraftingViews(doc, draftingViews, toDocument);
            int numDrafting = draftingViews.Count <ViewDrafting>();

            // Show results
            TaskDialog.Show("Statistics",
                            String.Format("Copied: \n" +
                                          "\t{0} schedules.\n" +
                                          "\t{1} drafting views.\n" +
                                          "\t{2} new drafting elements created.",
                                          numSchedules, numDrafting, numDraftingElements));

            return(Result.Succeeded);
        }
コード例 #2
0
        /// <summary>
        /// Checks if the curtain element can be exported as container.
        /// </summary>
        /// <remarks>
        /// It checks if all sub elements to be exported have geometries.
        /// </remarks>
        /// <param name="allSubElements">
        /// Collection of elements contained in the host curtain element.
        /// </param>
        /// <param name="document">
        /// The Revit document.
        /// </param>
        /// <returns>
        /// True if it can be exported as container, false otherwise.
        /// </returns>
        private static bool CanExportCurtainWallAsContainer(ICollection <ElementId> allSubElements, Document document)
        {
            Options geomOptions = GeometryUtil.GetIFCExportGeometryOptions();

            FilteredElementCollector collector = new FilteredElementCollector(document, allSubElements);

            List <Type> curtainWallSubElementTypes = new List <Type>();

            curtainWallSubElementTypes.Add(typeof(FamilyInstance));
            curtainWallSubElementTypes.Add(typeof(CurtainGridLine));
            curtainWallSubElementTypes.Add(typeof(Wall));

            ElementMulticlassFilter multiclassFilter = new ElementMulticlassFilter(curtainWallSubElementTypes, true);

            collector.WherePasses(multiclassFilter);
            ICollection <ElementId> filteredSubElemments = collector.ToElementIds();

            foreach (ElementId subElemId in filteredSubElemments)
            {
                Element         subElem  = document.GetElement(subElemId);
                GeometryElement geomElem = subElem.get_Geometry(geomOptions);
                if (geomElem == null)
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #3
0
        private static IEnumerable <Autodesk.Revit.DB.View> FindAllViewsThatCanDisplayElements(Autodesk.Revit.DB.Document doc)
        {
            ElementMulticlassFilter filter = new ElementMulticlassFilter(new List <Type> {
                typeof(View3D), typeof(ViewPlan), typeof(ViewSection)
            });

            return(new FilteredElementCollector(doc).WherePasses(filter).Cast <View>().Where(v => !v.IsTemplate));
        }
コード例 #4
0
      /// <summary>
      /// Gets element filter for specific views.
      /// </summary>
      /// <param name="exporter">The ExporterIFC object.</param>
      /// <returns>The element filter.</returns>
      private static ElementFilter GetViewSpecificTypesFilter(ExporterIFC exporter)
      {
         ElementFilter ownerViewFilter = GetOwnerViewFilter(exporter);

         List<Type> viewSpecificTypes = new List<Type>();
         viewSpecificTypes.Add(typeof(TextNote));
         viewSpecificTypes.Add(typeof(FilledRegion));
         ElementMulticlassFilter classFilter = new ElementMulticlassFilter(viewSpecificTypes);


         LogicalAndFilter viewSpecificTypesFilter = new LogicalAndFilter(ownerViewFilter, classFilter);
         return viewSpecificTypesFilter;
      }
コード例 #5
0
ファイル: IFCImportCache.cs プロジェクト: zhoyq/revit-ifc
        /// <summary>
        /// Create the GUIDToElementMap and the GridNameToElementMap to reuse elements by GUID and Grid name.
        /// </summary>
        /// <param name="document">The document.</param>
        public void CreateExistingElementMaps(Document document)
        {
            FilteredElementCollector collector = new FilteredElementCollector(document);

            // These are the only element types currently created in .NET code.  This list needs to be updated when a new
            // type is created.
            List <Type> supportedElementTypes = new List <Type>();

            supportedElementTypes.Add(typeof(DirectShape));
            supportedElementTypes.Add(typeof(DirectShapeType));
            supportedElementTypes.Add(typeof(Level));
            supportedElementTypes.Add(typeof(Grid));

            ElementMulticlassFilter multiclassFilter = new ElementMulticlassFilter(supportedElementTypes);

            collector.WherePasses(multiclassFilter);

            foreach (Element elem in collector)
            {
                string guid = IFCGUIDUtil.GetGUID(elem);
                if (string.IsNullOrWhiteSpace(guid))
                {
                    continue; // This Element was generated by other means.
                }
                if (elem is Grid)
                {
                    string gridName = elem.Name;
                    if (GridNameToElementMap.ContainsKey(gridName))
                    {
                        // If the Grid has a duplicate grid name, assign an arbitrary one to add to the map.  This will mean
                        // that the Grid will be deleted at the end of reloading.
                        // TODO: warn the user about this, and/or maybe allow for some duplication based on category.
                        gridName = Guid.NewGuid().ToString();
                    }

                    GridNameToElementMap.Add(new KeyValuePair <string, ElementId>(gridName, elem.Id));
                }
                else
                {
                    if (GUIDToElementMap.ContainsKey(guid))
                    {
                        // If the Element contains a duplicate GUID, assign an arbitrary one to add to the map.  This will mean
                        // that the Element will be deleted at the end of reloading.
                        // TODO: warn the user about this, and/or maybe allow for some duplication based on category.
                        guid = Guid.NewGuid().ToString();
                    }

                    GUIDToElementMap.Add(new KeyValuePair <string, ElementId>(guid, elem.Id));
                }
            }
        }
コード例 #6
0
        FindAllViewsThatCanDisplayElements(
            this Document doc)
        {
            ElementMulticlassFilter filter
                = new ElementMulticlassFilter(
                      new List <Type> {
                typeof(View3D),
                typeof(ViewPlan),
                typeof(ViewSection)
            });

            return(new FilteredElementCollector(doc)
                   .WherePasses(filter)
                   .Cast <View>()
                   .Where(v => !v.IsTemplate));
        }
コード例 #7
0
        private List <Element> GetElementListInModel()
        {
            var MultiClassFilter = new ElementMulticlassFilter(new List <Type>
            {
                typeof(TextNote),
                typeof(FilledRegion),
                typeof(Dimension),
                typeof(FamilyInstance),
                typeof(Wall),
                typeof(Floor),
                typeof(RevitLinkInstance),
                typeof(IndependentTag),
                typeof(Group)
            }
                                                               );
            List <Element> ListElement = new FilteredElementCollector(_doc).WherePasses(MultiClassFilter).ToList();

            return(ListElement);
        }
コード例 #8
0
        private void GetTemplates()
        {
            try
            {
                var types = new List <Type>();
                types.Add(typeof(View3D));
                types.Add(typeof(ViewPlan));
                var multiClassFilter = new ElementMulticlassFilter(types);

                var sCollector = new FilteredElementCollector(sModelInfo.ModelDoc);
                var sViews     = sCollector.WherePasses(multiClassFilter).ToElements().Cast <View>().ToList();
                var sTemplates = from view in sViews where view.IsTemplate select view;
                foreach (var view in sTemplates)
                {
                    var iInfo = new ItemInfo(view, MapType.ViewTemplate);
                    if (!sourceItems.ContainsKey(iInfo.ItemId))
                    {
                        sourceItems.Add(iInfo.ItemId, iInfo);
                    }
                }

                var rCollector = new FilteredElementCollector(rModelInfo.ModelDoc);
                var rViews     = sCollector.WherePasses(multiClassFilter).ToElements().Cast <View>().ToList();
                var rTemplates = from view in rViews where view.IsTemplate select view;
                foreach (Element elem in rTemplates)
                {
                    var iInfo = new ItemInfo(elem, MapType.ViewTemplate);
                    if (!recipientItems.ContainsKey(iInfo.ItemId))
                    {
                        recipientItems.Add(iInfo.ItemId, iInfo);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to get view templates.\n" + ex.Message, "Get View Templates", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
コード例 #9
0
        /// <summary>
        /// Gets element filter that match certain types.
        /// </summary>
        /// <param name="forSpatialElements">True if to get filter for spatial element, false for other elements.</param>
        /// <returns>The element filter.</returns>
        private static ElementFilter GetClassFilter(bool forSpatialElements)
        {
            if (forSpatialElements)
            {
                return new ElementClassFilter(typeof(SpatialElement));
            }
            else
            {
                List<Type> excludedTypes = new List<Type>();

                // FamilyInstances are handled in separate filter.
                excludedTypes.Add(typeof(FamilyInstance));

                excludedTypes.Add(typeof(SpatialElement));

                if (!ExporterCacheManager.ExportOptionsCache.ExportAnnotations)
                    excludedTypes.Add(typeof(CurveElement));

                excludedTypes.Add(typeof(ElementType));
                excludedTypes.Add(typeof(Group));

                excludedTypes.Add(typeof(BaseArray));

                excludedTypes.Add(typeof(FillPatternElement));
                excludedTypes.Add(typeof(LinePatternElement));
                excludedTypes.Add(typeof(Material));
                excludedTypes.Add(typeof(GraphicsStyle));
                excludedTypes.Add(typeof(Family));
                excludedTypes.Add(typeof(SketchPlane));
                excludedTypes.Add(typeof(View));
                excludedTypes.Add(typeof(Autodesk.Revit.DB.Structure.LoadBase));
                excludedTypes.Add(typeof(BeamSystem));

                // curtain wall sub-types we are ignoring.
                excludedTypes.Add(typeof(CurtainGridLine));
                // excludedTypes.Add(typeof(Mullion));

                // this will be gotten from the element(s) it cuts.
                excludedTypes.Add(typeof(Opening));

                // 2D types we are ignoring
                excludedTypes.Add(typeof(SketchBase));
                excludedTypes.Add(typeof(FaceSplitter));

                // 2D types covered by the element owner view filter
                excludedTypes.Add(typeof(TextNote));
                excludedTypes.Add(typeof(FilledRegion));

                // exclude levels that are covered in BeginExport
                excludedTypes.Add(typeof(Level));

                // exclude analytical models
                excludedTypes.Add(typeof(Autodesk.Revit.DB.Structure.AnalyticalModel));

                ElementFilter excludedClassFilter = new ElementMulticlassFilter(excludedTypes, true);

                List<BuiltInCategory> excludedCategories = new List<BuiltInCategory>();


                // Native Revit types without match in API
                excludedCategories.Add(BuiltInCategory.OST_Property);
                excludedCategories.Add(BuiltInCategory.OST_SiteProperty);
                excludedCategories.Add(BuiltInCategory.OST_SitePropertyLineSegment);
                excludedCategories.Add(BuiltInCategory.OST_Viewports);
                excludedCategories.Add(BuiltInCategory.OST_Views);
                excludedCategories.Add(BuiltInCategory.OST_IOS_GeoLocations);
                excludedCategories.Add(BuiltInCategory.OST_RvtLinks);
                excludedCategories.Add(BuiltInCategory.OST_DecalElement);
                //excludedCategories.Add(BuiltInCategory.OST_Parts);
                excludedCategories.Add(BuiltInCategory.OST_DuctCurvesCenterLine);
                excludedCategories.Add(BuiltInCategory.OST_DuctFittingCenterLine);
                excludedCategories.Add(BuiltInCategory.OST_PipeCurvesCenterLine);
                excludedCategories.Add(BuiltInCategory.OST_PipeFittingCenterLine);
                excludedCategories.Add(BuiltInCategory.OST_ConduitCenterLine);
                excludedCategories.Add(BuiltInCategory.OST_ConduitFittingCenterLine);
                excludedCategories.Add(BuiltInCategory.OST_FlexDuctCurvesCenterLine);
                excludedCategories.Add(BuiltInCategory.OST_FlexPipeCurvesCenterLine);

                ElementMulticategoryFilter excludedCategoryFilter = new ElementMulticategoryFilter(excludedCategories, true);

                LogicalAndFilter exclusionFilter = new LogicalAndFilter(excludedClassFilter, excludedCategoryFilter);

                ElementOwnerViewFilter ownerViewFilter = new ElementOwnerViewFilter(ElementId.InvalidElementId);

                LogicalAndFilter returnedFilter = new LogicalAndFilter(exclusionFilter, ownerViewFilter);

                return returnedFilter;
            }
        }
コード例 #10
0
        /// <summary>
        /// Gets element filter for specific views.
        /// </summary>
        /// <param name="exporter">The ExporterIFC object.</param>
        /// <returns>The element filter.</returns>
        private static ElementFilter GetViewSpecificTypesFilter(ExporterIFC exporter)
        {
            ElementFilter ownerViewFilter = GetOwnerViewFilter(exporter);

            List<Type> viewSpecificTypes = new List<Type>();
            viewSpecificTypes.Add(typeof(TextNote));
            viewSpecificTypes.Add(typeof(FilledRegion));
            ElementMulticlassFilter classFilter = new ElementMulticlassFilter(viewSpecificTypes);


            LogicalAndFilter viewSpecificTypesFilter = new LogicalAndFilter(ownerViewFilter, classFilter);
            return viewSpecificTypesFilter;
        }
コード例 #11
0
        /// <summary>
        /// Gets element filter that match certain types.
        /// </summary>
        /// <param name="forSpatialElements">True if to get filter for spatial element, false for other elements.</param>
        /// <returns>The element filter.</returns>
        private static ElementFilter GetClassFilter(bool forSpatialElements)
        {
            if (forSpatialElements)
            {
                return(new ElementClassFilter(typeof(SpatialElement)));
            }
            else
            {
                List <Type> excludedTypes = new List <Type>();

                // FamilyInstances are handled in separate filter.
                excludedTypes.Add(typeof(FamilyInstance));

                // Spatial element are exported in a separate pass.
                excludedTypes.Add(typeof(SpatialElement));

                // AreaScheme elements are exported as groups after all Areas have been exported.
                excludedTypes.Add(typeof(AreaScheme));
                // FabricArea elements are exported as groups after all FabricSheets have been exported.
                excludedTypes.Add(typeof(FabricArea));

                if (!ExporterCacheManager.ExportOptionsCache.ExportAnnotations)
                {
                    excludedTypes.Add(typeof(CurveElement));
                }

                excludedTypes.Add(typeof(ElementType));

                excludedTypes.Add(typeof(BaseArray));

                excludedTypes.Add(typeof(FillPatternElement));
                excludedTypes.Add(typeof(LinePatternElement));
                excludedTypes.Add(typeof(Material));
                excludedTypes.Add(typeof(GraphicsStyle));
                excludedTypes.Add(typeof(Family));
                excludedTypes.Add(typeof(SketchPlane));
                excludedTypes.Add(typeof(View));
                excludedTypes.Add(typeof(Autodesk.Revit.DB.Structure.LoadBase));

                // curtain wall sub-types we are ignoring.
                excludedTypes.Add(typeof(CurtainGridLine));
                // excludedTypes.Add(typeof(Mullion));

                // this will be gotten from the element(s) it cuts.
                excludedTypes.Add(typeof(Opening));

                // 2D types we are ignoring
                excludedTypes.Add(typeof(SketchBase));
                excludedTypes.Add(typeof(FaceSplitter));

                // 2D types covered by the element owner view filter
                excludedTypes.Add(typeof(TextNote));
                excludedTypes.Add(typeof(FilledRegion));

                // exclude levels that are covered in BeginExport
                excludedTypes.Add(typeof(Level));

                // exclude analytical models
                excludedTypes.Add(typeof(Autodesk.Revit.DB.Structure.AnalyticalElement));
                ElementFilter excludedClassFilter = new ElementMulticlassFilter(excludedTypes, true);

                List <BuiltInCategory> excludedCategories = new List <BuiltInCategory>();

                // Native Revit types without match in API
                excludedCategories.Add(BuiltInCategory.OST_ConduitCenterLine);
                excludedCategories.Add(BuiltInCategory.OST_ConduitFittingCenterLine);
                excludedCategories.Add(BuiltInCategory.OST_DecalElement);
                //excludedCategories.Add(BuiltInCategory.OST_Parts);
                //excludedCategories.Add(BuiltInCategory.OST_RvtLinks);
                excludedCategories.Add(BuiltInCategory.OST_DuctCurvesCenterLine);
                excludedCategories.Add(BuiltInCategory.OST_DuctFittingCenterLine);
                excludedCategories.Add(BuiltInCategory.OST_FlexDuctCurvesCenterLine);
                excludedCategories.Add(BuiltInCategory.OST_FlexPipeCurvesCenterLine);
                excludedCategories.Add(BuiltInCategory.OST_IOS_GeoLocations);
                excludedCategories.Add(BuiltInCategory.OST_PipeCurvesCenterLine);
                excludedCategories.Add(BuiltInCategory.OST_PipeFittingCenterLine);
                excludedCategories.Add(BuiltInCategory.OST_Property);
                excludedCategories.Add(BuiltInCategory.OST_SiteProperty);
                excludedCategories.Add(BuiltInCategory.OST_SitePropertyLineSegment);
                excludedCategories.Add(BuiltInCategory.OST_TopographyContours);
                excludedCategories.Add(BuiltInCategory.OST_Viewports);
                excludedCategories.Add(BuiltInCategory.OST_Views);

                // Exclude elements with no category.
                excludedCategories.Add(BuiltInCategory.INVALID);

                ElementMulticategoryFilter excludedCategoryFilter = new ElementMulticategoryFilter(excludedCategories, true);

                LogicalAndFilter exclusionFilter = new LogicalAndFilter(excludedClassFilter, excludedCategoryFilter);

                ElementOwnerViewFilter ownerViewFilter = new ElementOwnerViewFilter(ElementId.InvalidElementId);

                LogicalAndFilter returnedFilter = new LogicalAndFilter(exclusionFilter, ownerViewFilter);

                return(returnedFilter);
            }
        }
コード例 #12
0
        /// <summary>
        /// Return an enumeration of all views in this
        /// document that can display elements at all.
        /// </summary>
        static IEnumerable<View> FindAllViewsThatCanDisplayElements(
            this Document doc)
        {
            ElementMulticlassFilter filter
            = new ElementMulticlassFilter(
              new List<Type> {
            typeof( View3D ),
            typeof( ViewPlan ),
            typeof( ViewSection ) } );

              return new FilteredElementCollector( doc )
            .WherePasses( filter )
            .Cast<View>()
            .Where( v => !v.IsTemplate );
        }
コード例 #13
0
        /// <summary>
        /// Checks if the curtain element can be exported as container.
        /// </summary>
        /// <remarks>
        /// It checks if all sub elements to be exported have geometries.
        /// </remarks>
        /// <param name="allSubElements">
        /// Collection of elements contained in the host curtain element.
        /// </param>
        /// <param name="document">
        /// The Revit document.
        /// </param>
        /// <returns>
        /// True if it can be exported as container, false otherwise.
        /// </returns>
        private static bool CanExportCurtainWallAsContainer(ICollection<ElementId> allSubElements, Document document)
        {
            Options geomOptions = GeometryUtil.GetIFCExportGeometryOptions();

            FilteredElementCollector collector = new FilteredElementCollector(document, allSubElements);

            List<Type> curtainWallSubElementTypes = new List<Type>();
            curtainWallSubElementTypes.Add(typeof(FamilyInstance));
            curtainWallSubElementTypes.Add(typeof(CurtainGridLine));

            ElementMulticlassFilter multiclassFilter = new ElementMulticlassFilter(curtainWallSubElementTypes, true);
            collector.WherePasses(multiclassFilter);
            ICollection<ElementId> filteredSubElemments = collector.ToElementIds();
            foreach (ElementId subElemId in filteredSubElemments)
            {
                Element subElem = document.GetElement(subElemId);
                GeometryElement geomElem = subElem.get_Geometry(geomOptions);
                if (geomElem == null)
                    return false;
            }
            return true;
        }
コード例 #14
0
ファイル: App.cs プロジェクト: Tadwork/PhaseGraphicsAddin
        private static ElementMulticlassFilter PhaseGraphicsTypeFilter()
        {
            List<Type> types = new List<Type>(4);

            types.Add(typeof(ContFooting));
            types.Add(typeof(Wall));
            types.Add(typeof(Floor));
            types.Add(typeof(RoofBase));
            ElementMulticlassFilter Filter = new ElementMulticlassFilter(types);
            return Filter;
        }