Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Having trouble filtering to OST_TitleBlocks

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Charles.Stokes
795 Views, 6 Replies

Having trouble filtering to OST_TitleBlocks

I'm trying to build a FilteredElementCollector that will filter down to a number of TitleBlocks we have preloaded into a project. To be clear there are no instances of these elements within the project, they have only been loaded in.

 

[Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class Snoop : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData,
            ref string message, ElementSet elements)
        {
            Document doc = commandData.Application.ActiveUIDocument.Document;
            UIDocument uidoc = commandData.Application.ActiveUIDocument;

            FilteredElementCollector collector = new FilteredElementCollector(doc);
            ICollection<Element> titleFrames = collector
                .OfCategory(BuiltInCategory.OST_TitleBlocks)
                .OfClass(typeof(Family))
                .ToElements();

            StringBuilder textMessage = new StringBuilder("Available titleframes: ");

            if (titleFrames.Count == 0)
                textMessage.AppendLine("Contains no titleframes.");
            else
            {
                foreach (Family titleFrame in titleFrames)
                {
                    textMessage.AppendLine("\nName: " + titleFrame.Name);
                }
            }

            File.WriteAllText(@"C:\Users\user\Documents\Test.txt", textMessage.ToString());
            TaskDialog.Show("Revit","Complete");
            return Result.Succeeded;
        }
    }

From this code block I recieve the following:

 

Available titleframes: Contains no titleframes.

I am 100% sure the TitleBlocks are loaded

 

Am I missing a call?

Or do I need to use a different method to find these elements?

 

Any help is appreciated.

Thanks

 

Charlie

6 REPLIES 6
Message 2 of 7

Dear Charlie,

 

You say "they have only been loaded in".

 

Does that mean that they live in linked project files?

 

In that case, you have to run your filtered element collectors in the linked documents, one for each one, not the main project document.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 7

Sorry thats not it.

What I meant was they have been loaded into the project file from a library but no instances of those families have been created in the project itself.

If that makes sense.

Message 4 of 7

Hi @Charles.Stokes,

This one stumped me once upon a time, and I've just re-learnt the answer (with the help of RevitLookup).

If you snoop a titleblock family, you will see that the category is <null>.

The *FamilyCategory* is OST_Titleblocks.

Crudely (using VB.NET), this can be achieved by:

       Dim titleFrames As List(Of DB.Family) = _
collector.OfClass(GetType(DB.Family)) _
.Cast(Of DB.Family) _
.Where(Function(fam) fam.FamilyCategoryId.IntegerValue = CInt(DB.BuiltInCategory.OST_TitleBlocks)).ToList

I am sure more efficient ways exist, but I'll leave that investigation to you.

 

 

Cheers,

 

-Matt

 

[edit]

Make sure you import and reference System.LINQ.

[/edit]


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
Message 5 of 7

Thanks alot

yeah I saw that in snoop but thought it was some kind of glitch or I was doing something wrong

nice to know it isn't just me.

 

Thanks 

Charlie

Message 6 of 7

Thank you for spotting that, Matt.

 

Another example of this age-old 'feature':

 

http://thebuildingcoder.typepad.com/blog/2015/09/change-type-iterate-elements-create-family.html#2

 

Note that the Category property is not always implemented on families, so you may have to use FamilyCategory instead, or the category of the family's first symbol.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 7 of 7

I summarised this rather fundamental 'feature' of families on The Building Coder for future reference:

 

http://thebuildingcoder.typepad.com/blog/2017/01/family-category-and-two-energy-model-types.html#2

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community