当前位置: 首页>>代码示例>>C#>>正文


C# FilteredElementCollector类代码示例

本文整理汇总了C#中FilteredElementCollector的典型用法代码示例。如果您正苦于以下问题:C# FilteredElementCollector类的具体用法?C# FilteredElementCollector怎么用?C# FilteredElementCollector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FilteredElementCollector类属于命名空间,在下文中一共展示了FilteredElementCollector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetAllViews

        /// <summary>
        /// Finds all the views in the active document.
        /// </summary>
        /// <param name="doc">the active document</param>
        public static ViewSet GetAllViews (Document doc)
        {
            ViewSet allViews = new ViewSet();

            FilteredElementCollector fec = new FilteredElementCollector(doc);
            ElementClassFilter elementsAreWanted = new ElementClassFilter(typeof(FloorType));
            fec.WherePasses(elementsAreWanted);
            List<Element> elements = fec.ToElements() as List<Element>;

            foreach (Element element in elements)
            {
               Autodesk.Revit.DB.View view = element as Autodesk.Revit.DB.View;

               if (null == view)
               {
                  continue;
               }
               else
               {
                  
                  ElementType objType = doc.GetElement(view.GetTypeId()) as ElementType;
                  if (null == objType || objType.Name.Equals("Drawing Sheet"))
                  {
                     continue;
                  }
                  else
                  {
                     allViews.Insert(view);
                  }
               }
            }

            return allViews;
        }
开发者ID:15921050052,项目名称:RevitLookup,代码行数:38,代码来源:View.cs

示例2: Form1_Load

        private void Form1_Load(object sender, EventArgs e)
        {
            //read from exportOptions for project
            if (Helpers.GetExportOptionsInfo(m_doc, m_neo))
            {
                //

                lblFolderPath.Text = Options._folderExport;

                FilteredElementCollector fec = new FilteredElementCollector(m_doc).OfClass(typeof(View3D));

                foreach (Element elem in fec)
                {
                    View3D v = elem as View3D;
                    cbViewList.Items.Add(v);
                }
                cbViewList.DisplayMember = "ViewName";

                //Set selection to property
                //cbViewList.SelectedItem = selectedView;
                cbViewList.Text = Options._exportView.Name;
            }
            else
                this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }
开发者ID:kmorin,项目名称:nwcautoviewexporter,代码行数:25,代码来源:Form1.cs

示例3: changeFamiliesNames

        public void changeFamiliesNames(Document doc)
        {
            //Gets the families
            Family familyNames = null;
            FilteredElementCollector collector = new FilteredElementCollector(doc);
            ICollection<Element> collection = collector.OfClass(typeof(Family)).ToElements();

            ValueDictionary dictionaryList = new ValueDictionary();
            var dictionary = dictionaryList.GetRenameFamilies();

            using (Transaction t = new Transaction(doc))
            {
                t.Start("new name");

                foreach (Element e in collection)
                {
                    familyNames = e as Family;
                    string familyName = familyNames.Name;

                    //Checks the dictionary and if found renames the family
                    if (dictionary.ContainsKey(familyName))
                    {
                        string value = dictionary[familyName];
                        familyNames.Name = value;
                        count++;
                    }
                }
                t.Commit();
                string message = "Number of Families Renamed: ";
                MessageBox.Show(message + count.ToString());
            }
        }
开发者ID:dannysbentley,项目名称:Family-Rename,代码行数:32,代码来源:changeFamilyNames.cs

示例4: GetClosestFace

        public static Tuple<Face, Reference> GetClosestFace(Document document, XYZ p)
        {
            Face resultFace = null;
            Reference resultReference = null;

            double min_distance = double.MaxValue;
            FilteredElementCollector collector = new FilteredElementCollector(document);
            var walls = collector.OfClass(typeof (Wall));
            foreach (Wall wall in walls)
            {
                IList<Reference> sideFaces =
                    HostObjectUtils.GetSideFaces(wall, ShellLayerType.Interior);
                // access the side face
                Face face = document.GetElement(sideFaces[0]).GetGeometryObjectFromReference(sideFaces[0]) as Face;
                var intersection = face.Project(p);

                if (intersection != null)
                {
                    if (intersection.Distance < min_distance)
                    {
                        resultFace = face;
                        resultReference = sideFaces[0];
                        min_distance = intersection.Distance;
                    }
                }
            }
            //resultFace.
            return new Tuple<Face,Reference>( resultFace, resultReference);
        }
开发者ID:KonbOgonb,项目名称:revit-psElectro-bridge,代码行数:29,代码来源:FindWallHelper.cs

示例5: Execute

        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            Document doc = commandData.Application
            .ActiveUIDocument.Document;

              FilteredElementCollector collector
            = new FilteredElementCollector( doc );

              collector.OfClass( typeof( Level ) );
              Level level = collector.FirstElement() as Level;

              Transaction t = new Transaction( doc );

              t.Start( "Create unbounded room" );

              FailureHandlingOptions failOpt
            = t.GetFailureHandlingOptions();

              failOpt.SetFailuresPreprocessor(
            new RoomWarningSwallower() );

              t.SetFailureHandlingOptions( failOpt );

              doc.Create.NewRoom( level, new UV( 0, 0 ) );

              t.Commit();

              return Result.Succeeded;
        }
开发者ID:jeremytammik,项目名称:the_building_coder_samples,代码行数:32,代码来源:CmdPreprocessFailure.cs

示例6: TestOne

        public void TestOne()
        {
            using (var t = new Transaction(DocumentManager.Instance.CurrentDBDocument))
            {
                if (t.Start("Test one.") == TransactionStatus.Started)
                {
                    //create a reference point
                    var pt = DocumentManager.Instance.CurrentDBDocument.FamilyCreate.NewReferencePoint(new XYZ(5, 5, 5));

                    if (t.Commit() != TransactionStatus.Committed)
                    {
                        t.RollBack();
                    }
                }
                else
                {
                    throw new Exception("Transaction could not be started.");
                }
            }

            //verify that the point was created
            var collector = new FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument);
            collector.OfClass(typeof (ReferencePoint));

            Assert.AreEqual(1, collector.ToElements().Count);
        }
开发者ID:algobasket,项目名称:Dynamo,代码行数:26,代码来源:TestExamples.cs

示例7: DividedSurface

        public void DividedSurface()
        {
            var model = ViewModel.Model;

            string samplePath = Path.Combine(workingDirectory, @".\DividedSurface\DividedSurface.dyn");
            string testPath = Path.GetFullPath(samplePath);
            
            ViewModel.OpenCommand.Execute(testPath);
            ViewModel.Model.RunExpression();

            FilteredElementCollector fec = new FilteredElementCollector(DocumentManager.Instance.CurrentUIDocument.Document);
            fec.OfClass(typeof(DividedSurface));

            //did it create a divided surface?
            Assert.AreEqual(1, fec.ToElements().Count());

            var ds = (DividedSurface)fec.ToElements()[0];
            Assert.AreEqual(5, ds.USpacingRule.Number);
            Assert.AreEqual(5, ds.VSpacingRule.Number);

            //can we change the number of divisions
            var numNode = ViewModel.Model.Nodes.OfType<DoubleInput>().First();
            numNode.Value = "10";
            ViewModel.Model.RunExpression();

            //did it create a divided surface?
            Assert.AreEqual(10, ds.USpacingRule.Number);
            Assert.AreEqual(10, ds.VSpacingRule.Number);

            //ensure there is a warning when we try to set a negative number of divisions
            numNode.Value = "-5";
            ViewModel.Model.RunExpression();
            Assert.Greater(ViewModel.Model.EngineController.LiveRunnerCore.RuntimeStatus.WarningCount, 0);
        }
开发者ID:whztt07,项目名称:Dynamo,代码行数:34,代码来源:DividedSurfaceTests.cs

示例8: Create

        /// <summary>
        /// Set a Revit Curtain Panel
        /// </summary>
        /// <param name="setCurtainPanel"></param>
        /// <returns></returns>
        public static Element Create(this Grevit.Types.SetCurtainPanel setCurtainPanel)
        {
            // If there arent any valid properties return null
            if (setCurtainPanel.panelID == 0 || setCurtainPanel.panelType == "") return null;

            // Get the panel to change
            Panel panel = (Panel)GrevitCommand.document.GetElement(new ElementId(setCurtainPanel.panelID));

            // get its host wall
            Element wallElement = panel.Host;

            if (wallElement.GetType() == typeof(Autodesk.Revit.DB.Wall))
            {
                // Cast the Wall
                Autodesk.Revit.DB.Wall wall = (Autodesk.Revit.DB.Wall)wallElement;

                // Try to get the curtain panel type
                FilteredElementCollector collector = new FilteredElementCollector(GrevitCommand.document).OfClass(typeof(PanelType));
                Element paneltype = collector.FirstElement();
                foreach (Element em in collector.ToElements()) if (em.Name == setCurtainPanel.panelType) paneltype = em;

                // Cast the Element type
                ElementType type = (ElementType)paneltype;

                // Change the panel type
                wall.CurtainGrid.ChangePanelType(panel, type);
            }

            return panel;
        }
开发者ID:bbrangeo,项目名称:Grevit,代码行数:35,代码来源:CreateExtension.cs

示例9: ReferenceCurve

        public void ReferenceCurve()
        {
            var model = dynSettings.Controller.DynamoModel;

            string samplePath = Path.Combine(_testPath, @".\ReferenceCurve\ReferenceCurve.dyn");
            string testPath = Path.GetFullPath(samplePath);

            model.Open(testPath);
            dynSettings.Controller.RunExpression(true);

            FilteredElementCollector fec = new FilteredElementCollector(dynRevitSettings.Doc.Document);
            fec.OfClass(typeof(CurveElement));

            //verify five model curves created
            int count = fec.ToElements().Count;
            Assert.IsInstanceOf(typeof(ModelCurve), fec.ToElements().First());
            Assert.IsTrue(((ModelCurve)fec.ToElements().First()).IsReferenceLine);
            Assert.AreEqual(5, count);

            ElementId id = fec.ToElements().First().Id;

            //update any number node and verify
            //that the element gets updated not recreated
            var doubleNodes = dynSettings.Controller.DynamoModel.Nodes.Where(x => x is DoubleInput);
            var node = doubleNodes.First() as DoubleInput;

            Assert.IsNotNull(node);

            node.Value = node.Value + .1;
            dynSettings.Controller.RunExpression(true);
            Assert.AreEqual(5, fec.ToElements().Count);
        }
开发者ID:riteshchandawar,项目名称:Dynamo,代码行数:32,代码来源:ReferenceCurveTests.cs

示例10: application_DocumentOpened

        public void application_DocumentOpened(object sender, DocumentOpenedEventArgs args)
        {
            Document doc = args.Document;
            //add new parameter when a document opens
            Transaction transaction = new Transaction(doc, "Add PhaseGraphics");
            if (transaction.Start() == TransactionStatus.Started)
            {
                var fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"Autodesk\Revit\Addins\2012\PhaseSyncSharedParams.txt");
                SetNewParameterToInstances(doc, fileName.ToString());
                transaction.Commit();
            }
            //sync phasegraphics param with Phases of all empty PhaseGraphics objects
            Transaction transaction2 = new Transaction(doc, "Sync PhaseGraphics");
            ICollection<Element> types = null;
            if (transaction2.Start() == TransactionStatus.Started)
            {

                  // Apply the filter to the elements in the active document
                FilteredElementCollector collector = new FilteredElementCollector(doc);
                types = collector.WherePasses(PhaseGraphicsTypeFilter()).ToElements();
                foreach (Element elem in types)

                {
                    //get the phasegraphics parameter from its guid
                    if (elem.get_Parameter(new Guid(PhaseGraphicsGUID)).HasValue == false)
                    {
                        SyncPhaseGraphics(doc, elem);
                    }

                }
                transaction2.Commit();
            }
        }
开发者ID:Tadwork,项目名称:PhaseGraphicsAddin,代码行数:33,代码来源:App.cs

示例11: Execute

        /// <summary>
        /// Adds 1 to the mark of every column in the document
        /// </summary>
        /// <param name="commandData">the revit command data</param>
        /// <param name="message">a message to return</param>
        /// <param name="elements">Elements to display in a failed message dialog</param>
        /// <returns>Suceeded, Failed or Cancelled</returns>
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //we want the 'database' document, which represents the Revit Model itself.
            Document dbDoc = commandData.Application.ActiveUIDocument.Document;

            //Use a FilteredElementCollector to get all the columns in the model.
            FilteredElementCollector collector = new FilteredElementCollector(dbDoc);

            //for this, we use a Category Filter which finds all elements in the Column category
            ElementCategoryFilter columnFilter = new ElementCategoryFilter(BuiltInCategory.OST_Columns);

            //structural columns have a different category
            ElementCategoryFilter structuralColumnFilter =new ElementCategoryFilter(BuiltInCategory.OST_StructuralColumns);

            //to get elements that match either of these categories, we us a logical 'Or' filter.
            LogicalOrFilter orFilter = new LogicalOrFilter(columnFilter, structuralColumnFilter);

            //you can then get these elements as a list.
            //we also specify WhereElementIsNotElementType() so that we don't get FamilySymbols
            IList<Element> allColumns = collector.WherePasses(orFilter).WhereElementIsNotElementType().ToElements();

            string results = "Updated Marks For : " + Environment.NewLine;
            //loop through this list and update the mark
            foreach (Element element in allColumns)
            {
                UpdateMark(element);
                results += element.Id + Environment.NewLine;
            }

            TaskDialog.Show("Updated Elements", results);
            return Result.Succeeded;
        }
开发者ID:RodH257,项目名称:IntroToRevitSamples,代码行数:39,代码来源:ModifyingParameters.cs

示例12: RoomSpace

        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="spaceReference"></param>
        public RoomSpace(Document doc, Reference spaceReference)
        {
            m_doc = doc;
            LightFixtures = new List<LightFixture>();
            Space refSpace = m_doc.GetElement(spaceReference) as Space;

            // Set properties of newly create RoomSpace object from Space
            AverageEstimatedIllumination = refSpace.AverageEstimatedIllumination;
            Area = refSpace.Area;
            CeilingReflectance = refSpace.CeilingReflectance;
            FloorReflectance = refSpace.FloorReflectance;
            WallReflectance = refSpace.WallReflectance;
            CalcWorkPlane = refSpace.LightingCalculationWorkplane;
            ParentSpaceObject = refSpace;

            // Populate light fixtures list for RoomSpace
            FilteredElementCollector fec = new FilteredElementCollector(m_doc)
            .OfCategory(BuiltInCategory.OST_LightingFixtures)
            .OfClass(typeof(FamilyInstance));
            foreach (FamilyInstance fi in fec)
            {
                if (fi.Space.Id == refSpace.Id)
                {
                    ElementId eID = fi.GetTypeId();
                    Element e = m_doc.GetElement(eID);
                    //TaskDialog.Show("C","LF: SPACEID " + fi.Space.Id.ToString() + "\nSPACE ID: " + refSpace.Id.ToString());
                    LightFixtures.Add(new LightFixture(e,fi));
                }
            }
        }
开发者ID:kmorin,项目名称:LightingAnalysis,代码行数:35,代码来源:RoomSpace.cs

示例13: GetSchedules

        public static IEnumerable<ViewSchedule> GetSchedules(this ViewSheet viewSheet)
        {
            var doc = viewSheet.Document;

            FilteredElementCollector collector =
                new FilteredElementCollector(doc, viewSheet.Id);

            var scheduleSheetInstances =
                collector
                    .OfClass(typeof(ScheduleSheetInstance))
                    .ToElements()
                    .OfType<ScheduleSheetInstance>();

            foreach (var scheduleSheetInstance in
                scheduleSheetInstances)
            {
                var scheduleId =
                    scheduleSheetInstance
                        .ScheduleId;
                if (scheduleId == ElementId.InvalidElementId)
                    continue;

                var viewSchedule =
                    doc.GetElement(scheduleId)
                    as ViewSchedule;

                if (viewSchedule != null)
                    yield return viewSchedule;
            }
        }
开发者ID:vchekalin,项目名称:ScheduleAPIDemo,代码行数:30,代码来源:GetSchedulesOnSheetCommand.cs

示例14: AddNewLevels

 /// <summary>
 /// Bind to combobox's DropDownOpened Event, add new levels that created by user.
 /// </summary>
 /// <param name="evnetArgs">Autodesk.Revit.UI.Events.ComboBoxDropDownOpenedEventArgs</param>
 public void AddNewLevels(object sender, ComboBoxDropDownOpenedEventArgs args)
 {
     Autodesk.Revit.UI.ComboBox comboboxLevel = sender as Autodesk.Revit.UI.ComboBox;
     if (null == comboboxLevel) { return; }
     FilteredElementCollector collector = new FilteredElementCollector(uiApplication.ActiveUIDocument.Document);
     ICollection<Element> founds = collector.OfClass(typeof(Level)).ToElements();
     foreach (Element elem in founds)
     {
        Level level = elem as Level;
        bool alreadyContained = false;
        foreach (ComboBoxMember comboboxMember in comboboxLevel.GetItems())
        {
           if (comboboxMember.Name == level.Name)
           {
              alreadyContained = true;
           }
        }
        if (!alreadyContained)
        {
           ComboBoxMemberData comboBoxMemberData = new ComboBoxMemberData(level.Name, level.Name);
           ComboBoxMember comboboxMember = comboboxLevel.AddItem(comboBoxMemberData);
           comboboxMember.Image = new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "LevelsSelector.png"), UriKind.Absolute));
        }
     }
 }
开发者ID:AMEE,项目名称:revit,代码行数:29,代码来源:Ribbon.cs

示例15: ProjectSettingsManager

        private ProjectSettingsManager(Document document)
        {
            var col = new FilteredElementCollector(document).OfClass(typeof(ProjectInfo));
            _element = col.ToElements().First();
            _schema = Schema.Lookup(_schemaGuid) ?? GetStorageSchema();

            //get entity from element if it exists in there already or create new otherwise
            _entity = _element.GetEntity(_schema);
            if (_entity == null || _entity.Schema == null)
                _entity = new Entity(_schema);

            LoadData(document);

            //static cache management
            Cache.Add(document, this);
            document.DocumentClosing += new EventHandler<DocumentClosingEventArgs>(OnDocumentClosing);
            document.Application.DocumentSynchronizedWithCentral += new EventHandler<DocumentSynchronizedWithCentralEventArgs>(OnDocumentSynchronized);
            document.Application.DocumentChanged += new EventHandler<DocumentChangedEventArgs>((sender, args) =>
                {
                    if (args.Operation == UndoOperation.TransactionUndone || args.Operation == UndoOperation.TransactionRedone)
                    {

                    }
                });
        }
开发者ID:martin1cerny,项目名称:BIM-Library-CZ-Revit,代码行数:25,代码来源:ProjectSettingsManager.cs


注:本文中的FilteredElementCollector类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。