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


C# FilteredElementCollector.OfCategory方法代码示例

本文整理汇总了C#中FilteredElementCollector.OfCategory方法的典型用法代码示例。如果您正苦于以下问题:C# FilteredElementCollector.OfCategory方法的具体用法?C# FilteredElementCollector.OfCategory怎么用?C# FilteredElementCollector.OfCategory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FilteredElementCollector的用法示例。


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

示例1: GetInstanceParams

        private static IEnumerable<Parameter> GetInstanceParams(Document document, string familyName, IEnumerable<string> paramNames)
        {
            var collector =
                new FilteredElementCollector(document);

            var instances =
                collector.OfCategory(BuiltInCategory.OST_GenericAnnotation)
                    .WhereElementIsNotElementType()
                    .ToElements()
                    .ToList();

            var sheetNoteInst = 
                instances.FirstOrDefault(i => i.Name == familyName);

            if (null == sheetNoteInst) return null;

            var familyParams = sheetNoteInst.Parameters;

            var scheduleParams =
                familyParams
                    .OfType<Parameter>()
                    .Where(p => paramNames.Any(n => n == p.Definition.Name));

            return scheduleParams;
        }
开发者ID:dangwalsh,项目名称:Gensler.SheetNoteManager,代码行数:25,代码来源:Schedule.cs

示例2: ExtractObjects

 private static void ExtractObjects()
 {
     FilteredElementCollector fec = new FilteredElementCollector(_doc);
     IList<ElementFilter> StruMaterialFilterList = new List<ElementFilter>();
     StruMaterialFilterList.Add(new StructuralMaterialTypeFilter(StructuralMaterialType.Concrete));
     StruMaterialFilterList.Add(new StructuralMaterialTypeFilter(StructuralMaterialType.PrecastConcrete));
     LogicalOrFilter StruMaterialFilter = new LogicalOrFilter(StruMaterialFilterList);
     _slabs = fec.OfCategory(BuiltInCategory.OST_Floors).OfClass(typeof(Floor)).
         WherePasses(StruMaterialFilter).Cast<Floor>().ToList();
 }
开发者ID:Xiang-Zeng,项目名称:P58_Loss,代码行数:10,代码来源:PFlatSlab.cs

示例3: Evaluate

        public override Value Evaluate(FSharpList<Value> args)
        {
            var cat = (BuiltInCategory) ((Value.Container) args[0]).Item;

            //get the selected category and select all elements
            //in the document of that category
            var fec = new FilteredElementCollector(dynRevitSettings.Doc.Document);
            fec.OfCategory(cat);

            var results = fec.ToElements().Aggregate(FSharpList<Value>.Empty, (current, el) => FSharpList<Value>.Cons(Value.NewContainer(el), current));
            return Value.NewList(results);
        }
开发者ID:riteshchandawar,项目名称:Dynamo,代码行数:12,代码来源:Selection.cs

示例4: getTitleblockCurrentView

        //Retrives the titleblock in the active view.  The method is used to compare the size of the titlblock.
        public void getTitleblockCurrentView(Document doc)
        {
            FilteredElementCollector collector = new FilteredElementCollector(doc, doc.ActiveView.Id);
            collector.OfCategory(BuiltInCategory.OST_TitleBlocks).OfClass(typeof(FamilyInstance));

            //get the built in parameter parameters of titleblock in view.
            foreach (FamilyInstance tbk in collector)
            {
                FamilySymbol familySymbol = tbk.Symbol;
                familyName = tbk.Symbol.Name;
            }
        }
开发者ID:dannysbentley,项目名称:alignviewtosheetcell,代码行数:13,代码来源:Titleblock.cs

示例5: Execute

        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            _revit_window
            = new JtWindowHandle(
              ComponentManager.ApplicationWindow );

              UIApplication uiapp = commandData.Application;
              UIDocument uidoc = uiapp.ActiveUIDocument;
              Application app = uiapp.Application;
              Document doc = uidoc.Document;

              FilteredElementCollector collector
            = new FilteredElementCollector( doc );

              collector.OfCategory( BuiltInCategory.OST_Doors );
              collector.OfClass( typeof( FamilySymbol ) );

              FamilySymbol symbol = collector.FirstElement()
            as FamilySymbol;

              _added_element_ids.Clear();

              app.DocumentChanged
            += new EventHandler<DocumentChangedEventArgs>(
              OnDocumentChanged );

              //PromptForFamilyInstancePlacementOptions opt
              //  = new PromptForFamilyInstancePlacementOptions();

              uidoc.PromptForFamilyInstancePlacement( symbol );

              app.DocumentChanged
            -= new EventHandler<DocumentChangedEventArgs>(
              OnDocumentChanged );

              int n = _added_element_ids.Count;

              TaskDialog.Show(
            "Place Family Instance",
            string.Format(
              "{0} element{1} added.", n,
              ( ( 1 == n ) ? "" : "s" ) ) );

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

示例6: setCropBoxVisibility

        public static void setCropBoxVisibility(Document doc, bool visible)
        {
            FilteredElementCollector viewportCollector = new FilteredElementCollector(doc);
            IList<Element> viewports = viewportCollector.OfCategory(BuiltInCategory.OST_Viewports).ToElements();

            Transaction transaction = new Transaction(doc);
            transaction.Start(visible ? "Showing crop boxes" : "Hiding crop boxes");

            foreach (Element element in viewports)
            {
                if (element.get_Parameter("Crop Region Visible") != null)
                    element.get_Parameter("Crop Region Visible").Set(visible ? 1 : 0);
            }

            transaction.Commit();

            System.Media.SystemSounds.Asterisk.Play();
        }
开发者ID:pzurek,项目名称:QuickTools,代码行数:18,代码来源:CropBoxVisibility.cs

示例7: lock

        List<RevitParameter> ILyrebirdService.GetParameters(RevitObject revitFamily, string typeName)
        {
            lock (_locker)
            {
                TaskContainer.Instance.EnqueueTask(uiApp =>
                {
                    var doc = uiApp.ActiveUIDocument.Document;
                    parameters = new List<RevitParameter>();
                    if (revitFamily.CategoryId == -2000011)
                    {
                        // do stuff for walls
                        FilteredElementCollector wallCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document);
                        wallCollector.OfClass(typeof(WallType));
                        wallCollector.OfCategory(BuiltInCategory.OST_Walls);
                        foreach (WallType wt in wallCollector)
                        {
                            if (wt.Name == typeName)
                            {
                                // Get the type parameters
                                List<Parameter> typeParams = new List<Parameter>();
                                foreach (Parameter p in wt.Parameters)
                                {
                                    if(!p.IsReadOnly)
                                        typeParams.Add(p);
                                }

                                // Get the instance parameters
                                List<Parameter> instParameters = new List<Parameter>();
                                using (Transaction t = new Transaction(doc, "temp family"))
                                {
                                    t.Start();
                                    Wall wall = null;
                                    try
                                    {
                                        Curve c = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1, 0, 0));
                                        FilteredElementCollector lvlCollector = new FilteredElementCollector(doc);
                                        Level l = lvlCollector.OfClass(typeof(Level)).ToElements().OfType<Level>().FirstOrDefault();
                                        if (l != null) wall = Wall.Create(doc, c, l.Id, false);
                                    }
                                    catch (Exception exception)
                                    {
                                        // Failed to create the wall, no instance parameters will be found
                                        Debug.WriteLine(exception.Message);
                                    }

                                    if (wall != null)
                                    {
                                        foreach (Parameter p in wall.Parameters)
                                        {
                                            //if(!p.IsReadOnly)
                                                instParameters.Add(p);
                                        }
                                    }
                                    t.RollBack();
                                }
                                typeParams.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name));
                                instParameters.Sort((x, y) => String.CompareOrdinal(x.Definition.Name, y.Definition.Name));
                                foreach (Parameter p in typeParams)
                                {
                                    RevitParameter rp = new RevitParameter
                                    {
                                        ParameterName = p.Definition.Name,
                                        StorageType = p.StorageType.ToString(),
                                        IsType = true
                                    };
                                    parameters.Add(rp);
                                }
                                foreach (Parameter p in instParameters)
                                {
                                    RevitParameter rp = new RevitParameter
                                    {
                                        ParameterName = p.Definition.Name,
                                        StorageType = p.StorageType.ToString(),
                                        IsType = false
                                    };

                                    parameters.Add(rp);
                                }
                                break;
                            }
                        }
                    }
                    else if (revitFamily.CategoryId == -2000032)
                    {
                        // get parameters for floors
                        FilteredElementCollector floorCollector = new FilteredElementCollector(doc);
                        floorCollector.OfClass(typeof(FloorType));
                        floorCollector.OfCategory(BuiltInCategory.OST_Floors);
                        foreach (FloorType ft in floorCollector)
                        {
                            if (ft.Name == typeName)
                            {
                                // Get the type parameters
                                List<Parameter> typeParams = new List<Parameter>();
                                foreach (Parameter p in ft.Parameters)
                                {
                                    if(!p.IsReadOnly)
                                        typeParams.Add(p);
                                }

//.........这里部分代码省略.........
开发者ID:samuto,项目名称:Lyrebird,代码行数:101,代码来源:LyrebirdService.cs

示例8: Execute

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

              // retrieve all sheets

              FilteredElementCollector a
            = new FilteredElementCollector( doc );

              a.OfCategory( BuiltInCategory.OST_Sheets );
              a.OfClass( typeof( ViewSheet ) );

              // create a collection of all relevant data

              List<SheetData> data = new List<SheetData>();

              foreach( ViewSheet v in a )
              {
            // create some data for each sheet and add
            // to some serializable collection called Data
            SheetData item = new SheetData( v );
            data.Add( item );
              }

              // write out data collection to xml

              XmlTextWriter w = new XmlTextWriter(
            "C:/SheetData.xml", null );

              w.Formatting = Formatting.Indented;
              w.WriteStartDocument();
              w.WriteComment( string.Format(
            " SheetData from {0} on {1} by Jeremy ",
            doc.PathName, DateTime.Now ) );

              w.WriteStartElement( "ViewSheets" );

              foreach( SheetData item in data )
              {
            w.WriteStartElement( "ViewSheet" );

            w.WriteElementString( "IsPlaceholder",
              item.IsPlaceholder.ToString() );

            w.WriteElementString( "Name", item.Name );

            w.WriteElementString( "SheetNumber",
              item.SheetNumber );

            w.WriteEndElement();
              }
              w.WriteEndElement();
              w.WriteEndDocument();
              w.Close();

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

示例9: GetTargetInstances

        /// <summary>
        /// Return all element instances for a given 
        /// category, identified either by a built-in 
        /// category or by a category name.
        /// </summary>
        public static FilteredElementCollector GetTargetInstances(
            Document doc,
            object targetCategory)
        {
            FilteredElementCollector collector
            = new FilteredElementCollector( doc );

              bool isName = targetCategory.GetType().Equals(
            typeof( string ) );

              if ( isName )
              {
            Category cat = doc.Settings.Categories
              .get_Item( targetCategory as string );

            collector.OfCategoryId( cat.Id );
              }
              else
              {
            collector.WhereElementIsNotElementType();

            collector.OfCategory( (BuiltInCategory) targetCategory );

            //var model_elements
            //  = from e in collector
            //    where ( null != e.Category && e.Category.HasMaterialQuantities )
            //    select e;

            //elements = model_elements.ToList<Element>();
              }
              return collector;
        }
开发者ID:jeremytammik,项目名称:FireRatingCloud,代码行数:37,代码来源:Util.cs

示例10: GetTargetInstances

        /// <summary>
        /// Helper to get all instances for a given category,
        /// identified either by a built-in category or by a category name.
        /// </summary>
        public static List<Element> GetTargetInstances(
            Document doc,
            object targetCategory)
        {
            List<Element> elements;

              bool isName = targetCategory.GetType().Equals( typeof( string ) );

              if( isName )
              {
            Category cat = doc.Settings.Categories.get_Item( targetCategory as string );
            FilteredElementCollector collector = new FilteredElementCollector( doc );
            collector.OfCategoryId( cat.Id );
            elements = new List<Element>( collector );
              }
              else
              {
            FilteredElementCollector collector
              = new FilteredElementCollector( doc )
            .WhereElementIsNotElementType();

            collector.OfCategory( (BuiltInCategory) targetCategory );

            // I removed this to test attaching a shared
            // parameter to Material elements:
            //
            //var model_elements = from e in collector
            //                     where ( null != e.Category && e.Category.HasMaterialQuantities )
            //                     select e;

            //elements = model_elements.ToList<Element>();

            elements = collector.ToList<Element>();
              }
              return elements;
        }
开发者ID:jeremytammik,项目名称:AdnRevitApiLabsXtra,代码行数:40,代码来源:LabUtils.cs

示例11: GetProjectInfoElem

 /// <summary>
 /// Return the one and only project information element
 /// by searching for the "Project Information" category.
 /// Only one such element exists.
 /// </summary>
 public static Element GetProjectInfoElem( Document doc )
 {
     FilteredElementCollector collector = new FilteredElementCollector( doc );
       collector.OfCategory( BuiltInCategory.OST_ProjectInformation );
       return collector.FirstElement();
 }
开发者ID:jeremytammik,项目名称:AdnRevitApiLabsXtra,代码行数:11,代码来源:LabUtils.cs

示例12: FindExisting

        private List<ElementId> FindExisting(Document doc, Guid uniqueId, int categoryId, int runid)
        {
            // Find existing elements with a matching GUID from the GH component.
            List<ElementId> existingElems = new List<ElementId>();

            Schema instanceSchema = Schema.Lookup(instanceSchemaGUID);
            if (instanceSchema == null)
            {
                return existingElems;
            }

            // find the existing elements
            if (categoryId == -2000011)
            {
                FilteredElementCollector collector = new FilteredElementCollector(doc);
                collector.OfCategory(BuiltInCategory.OST_Walls);
                collector.OfClass(typeof(Wall));
                foreach (Wall w in collector)
                {
                    try
                    {
                        Entity entity = w.GetEntity(instanceSchema);
                        if (entity.IsValid())
                        {
                            Field f = instanceSchema.GetField("InstanceID");
                            string tempId = entity.Get<string>(f);
                            if (tempId == uniqueId.ToString())
                            {
                                if (runid == -1)
                                {
                                    existingElems.Add(w.Id);
                                }
                                else
                                {
                                    f = instanceSchema.GetField("RunID");
                                    int id = entity.Get<int>(f);
                                    if (id == runid)
                                    {
                                        existingElems.Add(w.Id);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }
            }
            else if (categoryId == -2000032)
            {
                FilteredElementCollector collector = new FilteredElementCollector(doc);
                collector.OfCategory(BuiltInCategory.OST_Floors);
                collector.OfClass(typeof(Floor));
                foreach (Floor flr in collector)
                {
                    try
                    {
                        Entity entity = flr.GetEntity(instanceSchema);
                        if (entity.IsValid())
                        {
                            Field f = instanceSchema.GetField("InstanceID");
                            string tempId = entity.Get<string>(f);
                            if (tempId == uniqueId.ToString())
                            {
                                if (runid == -1)
                                {
                                    existingElems.Add(flr.Id);
                                }
                                else
                                {
                                    f = instanceSchema.GetField("RunID");
                                    int id = entity.Get<int>(f);
                                    if (id == runid)
                                    {
                                        existingElems.Add(flr.Id);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }
            }
            else if (categoryId == -2000035)
            {
                FilteredElementCollector collector = new FilteredElementCollector(doc);
                collector.OfCategory(BuiltInCategory.OST_Roofs);
                collector.OfClass(typeof(FootPrintRoof));
                foreach (FootPrintRoof r in collector)
                {
                    try
                    {
                        Entity entity = r.GetEntity(instanceSchema);
                        if (entity.IsValid())
                        {
//.........这里部分代码省略.........
开发者ID:samuto,项目名称:Lyrebird,代码行数:101,代码来源:LyrebirdService.cs

示例13: FindElements

    /// <summary>
    /// Helper function: find a list of element with given Class, Name and Category (optional). 
    /// </summary>  
    public static IList<Element> FindElements(
      Document rvtDoc,
      Type targetType,
      string targetName,
      Nullable<BuiltInCategory> targetCategory)
    {
      // First, narrow down to the elements of the given type and category 
      var collector = new FilteredElementCollector(rvtDoc).OfClass(targetType);
      if (targetCategory.HasValue)
      {
        collector.OfCategory(targetCategory.Value);
      }

      // Parse the collection for the given names 
      // Using LINQ query here. 
      var elems =
          from element in collector
          where element.Name.Equals(targetName)
          select element;

      // Put the result as a list of element for accessibility. 

      return elems.ToList();
    }
开发者ID:vnoves,项目名称:RevitTrainingMaterial,代码行数:27,代码来源:3_ElementFiltering.cs

示例14: GetElementsOfType

      GetElementsOfType(
        Document doc,
        Type type,
        BuiltInCategory bic)
    {
      FilteredElementCollector collector
        = new FilteredElementCollector(doc);

      collector.OfCategory(bic);
      collector.OfClass(type);

      return collector;
    }
开发者ID:vnoves,项目名称:RevitTrainingMaterial,代码行数:13,代码来源:3_ElementFiltering.cs

示例15: GetLevel

        private Level GetLevel(List<LyrebirdPoint> controlPoints, Document doc)
        {
            Level lvl = null;

            FilteredElementCollector lvlCollector = new FilteredElementCollector(doc);
            lvlCollector.OfCategory(BuiltInCategory.OST_Levels);
            lvlCollector.OfClass(typeof(Level));
            foreach (Level l in lvlCollector)
            {
                try
                {
                    if (lvl == null)
                    {
                        lvl = l;
                    }
                    else
                    {
                        if (Math.Abs(l.Elevation - UnitUtils.ConvertToInternalUnits(controlPoints[0].Z, lengthDUT)) < Math.Abs(lvl.Elevation - UnitUtils.ConvertToInternalUnits(controlPoints[0].Z, lengthDUT)))
                        {
                            lvl = l;
                        }
                    }
                }
                catch { }
            }

            return lvl;
        }
开发者ID:samuto,项目名称:Lyrebird,代码行数:28,代码来源:LyrebirdService.cs


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