element.OwnerViewId Returns -1

Hey
I am trying locate the plan in which an element is skecthed(not originally my project) so I am trying to locate the owning view to a floor element.

I am using a python script of the element to get the property OwnerViewId and it is returning the number -1. I also tried selecting different elements which I know what plan they are on.

Any reason why I am getting this result? Any other suggested way to find the plan?

import clr
import sys
import System
from System import Array
from System.Collections.Generic import *
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')

import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = uiapp.ActiveUIDocument

l = UnwrapElement(IN[0])

OUT  = l.OwnerViewId

Floors are not specific to one view, so their ownerviewid will always return -1 (ElementId.InvalidElementId).

2 Likes

I would have assumed that it would return a list of views.
Thanks Gavin

Unfortunately not. The only way I know to achieve this is to run a filtered element collector for each view and check if the desired element is in the collected elements each time. Quite a slow process to run though…

Also keep in mind that elements will often be visible even if not ‘visible’ on a drawing in this manner. E.g. if a floor is behind an elevated wall and in its clip range, it will be counted as visible.

1 Like