Distinguishing AnnotationSymbol from other FamilyInstance members

Distinguishing AnnotationSymbol from other FamilyInstance members

Anonymous
Not applicable
1,041 Views
3 Replies
Message 1 of 4

Distinguishing AnnotationSymbol from other FamilyInstance members

Anonymous
Not applicable

I have an addin that will copy all of the schedules and legends from one sheet to another.  I am trying to expand the functionality to also copy the key plan (which is not part of the titleblock . . . it could be, but it is the corporate standard to not have it be for a variety of good and bad reasons).  My problem is that when I get a list of the FamilyInstances for the sheet like so:

 

            RDB.FilteredElementCollector coll2 = new RDB.FilteredElementCollector(doc, v.Id);
            var symbolInst = coll2
                .OfClass(typeof(RDB.FamilyInstance))
                .ToElements();
//                .Where(x => );
            foreach(RDB.FamilyInstance anno in symbolInst)
            {
                RDB.BoundingBoxXYZ xyzLoc = anno.get_BoundingBox(v);
            }

I end up with symbolInst having 2 members, one is the keyplan symbol, and the other is the titleblock.  I would like to filter out the titleblock somehow with the where clause, but I don't know how to exclude something . . . I was hoping to do a not OfCategory, but I'm blanking on how to do that.

 

When I stop the debugger and look I see that the keyplan symbol shows a value of "Autodesk.Revit.DB.AnnotationSymbol" but that is not allowed in the OFClass(typeof(XXX)) (it throws an error, thus I am using the base class FamilyInstance instead.  I could filter out with a test in the loop that follows, but I can't figure out how to test anno for being an AnnotationSymbol (or not an AnnotationSymbol).

 

Any ideas? Attached is a screen shot from the debugger Autos showing symbolInst expanded with 2 members, the value fields are shown as "Autodesk.Revit.DB.FamilyInstance" and "Autodesk.Revit.DB.AnnotationSymbol", but I don't know how to test for what "type" anno is within the loop.

0 Likes
Accepted solutions (1)
1,042 Views
3 Replies
Replies (3)
Message 2 of 4

jeremytammik
Autodesk
Autodesk
Accepted solution

I was hoping to do a not OfCategory, but I'm blanking on how to do that.

 

You can do a NOT OfCategory.

 

LogicalAndFilter Class

 

http://www.revitapidocs.com/2017/3e334aaf-2b39-58bd-d2cc-94e9c89bac57.htm

 

ElementCategoryFilter Constructor (ElementId, Boolean), where the Boolean argument can specify 'inverted':

 

http://www.revitapidocs.com/2017/3590e7e3-3e05-2d1a-f2af-8033eeb8996b.htm

 

Cheers,

 

Jeremy



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

Message 3 of 4

Anonymous
Not applicable

Thanks Jeremy! As usual you provide good help.  It turns out that I can also just do this:

 

RDB.FilteredElementCollector coll2 = new RDB.FilteredElementCollector(doc, v.Id).OfClass(typeof(RDB.FamilyInstance));
var symbolInst = from e in coll2.ToElements() where e is RDB.AnnotationSymbol select e as RDB.AnnotationSymbol;
foreach(RDB.AnnotationSymbol s in symbolInst)
{
     // do stuff in here
}

which I adapted from one of your building coder posts dealing with filtering for non-native classes.

0 Likes
Message 4 of 4

jeremytammik
Autodesk
Autodesk

Ah yes, of course:

 

http://thebuildingcoder.typepad.com/blog/2010/08/filtering-for-a-nonnative-class.html

 

Sorry I did not spot that and point it out explicitly myself right away.

 

Cheers,

 

Jeremy



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

0 Likes