Get view that generic annotation resides on

Get view that generic annotation resides on

seanUFNGF
Participant Participant
1,953 Views
2 Replies
Message 1 of 3

Get view that generic annotation resides on

seanUFNGF
Participant
Participant

I'm very new to the Revit API and C#, so all the usual noob disclaimers are relevant here.  I'll describe what I've got working so far, and then describe where I'm having difficulty.

 

I have a generic annotation that includes a label into which you can type whatever you'd like.  This content is kept as the value for a parameter I've created called "Note Content".  I've successfully implemented a Revit ribbon button that returns all annotations with the "Note Content" parameter and the associated value and lists these notes in a WPF window.

 

And now the "I'm stumped" part...

I'd like to include the location (view/sheet) in the set where the annotation resides.  I'm using the OwnerViewId property to do this, and when implemented in code, it just returns an integer.  However, when I snoop the annotation element using Revit Lookup, I see the OwnerViewId property, but it lists more than just an integer value.  It actually lists 3 values.  For example, the OwnerViewId property for one of these annotations has a value of '<ViewPlan  Level 1  356>'  I've only been able to get the '356' part of that to return, but I can see what I want right there!  I want the 'Level 1' part.  And when I click on the OwnerViewId property in the Revit Lookup window to go deeper, it opens another window, and there's a property called Name that has a value of 'Level 1'.  So again, I can see what I want to return.  But I can't for the life of me figure out how to get to it and pull it out.  Anyone have any insight?

 

(Revit 2019.2, Windows 10 Pro)

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

architect.bim
Collaborator
Collaborator
Accepted solution

Hello!

OwnerViewId property returns ElementId object of View/Sheet on which your annotation element is placed. If you need the actual name or number of that view/sheet you should first get view/sheet object. It can be done with GetElement method of Document class. After you get view/sheet you can retrieve necessary properties from it. I show you example in Python:

 

>>> view = doc.GetElement(g_annotation.OwnerViewId)
>>> view
<Autodesk.Revit.DB.ViewSheet object at 0x000000000000002E [Autodesk.Revit.DB.ViewSheet]>
>>> view.Name
'Floor Plan'
>>> view.SheetNumber
'A1'
>>> view.ViewType
Autodesk.Revit.DB.ViewType.DrawingSheet

 

 


Maxim Stepannikov | Architect, BIM Manager, Instructor
0 Likes
Message 3 of 3

seanUFNGF
Participant
Participant

Thanks so much, Maxim!  That gave me what I needed!