ViewPort Filtering

ViewPort Filtering

Anonymous
Not applicable
1,293 Views
8 Replies
Message 1 of 9

ViewPort Filtering

Anonymous
Not applicable

Hi All,

 

I am trying to filter all the viewports that I have inside a Revit project (used or not used). So far I have written something like this (It is in Python and it is based on the follwoing link https://forums.autodesk.com/t5/revit-api-forum/filtering-viewport-types/m-p/9287944#M44258:

 

viewport_list = []

viewports = FilteredElementCollector(doc).OfClass(ElementType)

for element in viewports:

       if element.FamilyName == 'Viewport':

              viewport_list.append(element)

 

When I try to print the name of these viewports it gives me the actuall system family name which is Viewport!:

 

for vp in viewport_list:

      print(vp.FamilyName) 

 

So the only thing printed is Viewport. 

So the thing is I want to find an specific viewport with the name "XXXX" . But i don't know how to do that cause I can't get access to the names of the viewports!

 

Any help would be much appreciated.

 

Thanks,

Dave  

 

0 Likes
Accepted solutions (1)
1,294 Views
8 Replies
Replies (8)
Message 2 of 9

jeremytammik
Autodesk
Autodesk

Use RevitLookup and other database navigation tools to explore your model and research what criteria you can use to identify the desired viewport:

 

https://thebuildingcoder.typepad.com/blog/2017/01/virtues-of-reproduction-research-mep-settings-onto...

 

https://thebuildingcoder.typepad.com/blog/2013/11/intimate-revit-database-exploration-with-the-pytho...

 



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

0 Likes
Message 3 of 9

BenoitE&A
Collaborator
Collaborator

See Jeremy's post, it answers most of questions.

In your case element.Name could be the solution.

In addition, you can access to the parameters of an Element using :

Parameter p = elem.LookupParameter("nameOfParameter");

And then get the value of the parameter using

if(p != null)
{ 
if(p.StorageType == StorageType.ElementId)
{
string valeur = elem.LookupParameter(nom).AsElementId();
}

 


Benoit FAVRE
CEO of etudes & automates
www.etudesetautomates.com/
0 Likes
Message 4 of 9

Yien_Chao
Advisor
Advisor

try this :

 

viewport_list = []
viewports = FilteredElementCollector(doc).OfClass(Viewport)
      
OUT = [i.get_Parameter(BuiltInParameter.VIEWPORT_VIEW_NAME).AsString() for i in viewports]

0 Likes
Message 5 of 9

Anonymous
Not applicable

Thanks for the reply Yien_Chao,

 

I used the code, but the result is just an empty list, The reason is, I haven't used any of the viewports inside the project so there is nothing to filter. I want to filter all the viewports that are inside the Revit project (even those that are not used).

 

So the code below gives me all the viewports inside the project but as I said I can't access their name, the error says there is no attribute Name!

 

col = FilteredElementCollector(doc).OfClass(ElementType)
for c in col:
     if c.FamilyName == 'Viewport':
     print(c.Name))

0 Likes
Message 6 of 9

Anonymous
Not applicable

Thanks BenoitE&A:

 

My Original problem was that the "Name'' attribute is not accessible, when I try to use it it gives me an error that there is no Name attribute.   

So I tried to use your code, it still doesn't give me anything, maybe I am doing something wrong!

viewports = FilteredElementCollector(doc).OfClass(ElementType)
     for vp in viewports:
      if vp.FamilyName == 'Viewport':
           p = vp.LookupParameter('Title')
           if p.StorageType == StorageType.ElementId:

                 print(p.AsString())

         

This gives me multiple ''Nones''

0 Likes
Message 7 of 9

Yien_Chao
Advisor
Advisor

Oh! Then its not a viewport but a view.

Viewport is only placed view on sheet i believe.

 

0 Likes
Message 8 of 9

Anonymous
Not applicable

Thanks Jeremy,

 

I will look into it more but still haven't found anything that helps me with my probelm, used all the BuiltInParameters available for view ports:

 

VIEWPORT_ATTR_ORIENTATION_ON_SHEET

VIEWPORT_ATTR_SHOW_BOX

VIEWPORT_ATTR_SHOW_EXTENSION_LINE

...

VIEWPORT_ATTR_LABEL_TAG

 

So the only one that actually gives me something is the last one, when I try to print it shows that there is something available but when I use AsString(), it gives me ''none''. Here is the code:

 

col = FilteredElementCollector(doc).OfClass(ElementType)
for c in col:
     if c.FamilyName == 'Viewport':
            print(c.get_Parameter(BuiltInParameter.VIEWPORT_ATTR_LABEL_TAG).AsString())

 

This gives me ''none''.

 

Apparently the only way to access the viewports that are available but not used inside the project is to filter through the ElementType like the code I have written above.

I tried to filter by the category or class:

 

col = FilteredElementCollector(doc).OfCategory(OST_Viewports)

This is empty

 

col = FilteredElementCollector(doc).OfCLass(Viewport)

This is also empty

 

col = FilteredElementCollector(doc).OfClass(ElementType)
for c in col:
     if c.FamilyName == 'Viewport':

           print(c.FamilyName)

 

This is not empty and it gives me exactly ''Viewport", but when I try to access the Name it gives me error:

 

          print(c.Name)

 

This is the error:

line 166, in <module>
AttributeError: Name

 

 

 

 

 

 

0 Likes
Message 9 of 9

Anonymous
Not applicable
Accepted solution

So Finally I managed to do it, thanks for the help all,

 

I did it like this:

 

list = []

collection_ports = FilteredElementCollector(doc).OfClass(ElementType)
for c in collection_ports:
       if c.FamilyName == 'Viewport':
       list = c.GetOrderedParameters()
       for l in list:
            try:
                  if l.AsValueString() == 'tile of your desired viewport':
                           nominated_viewport_type = c
            except:
                  print('parameter does not have name')

 

I also received an answer form Spage which is more efficient than my approach that works perfectly. see the link below: 

https://forums.autodesk.com/t5/revit-api-forum/filtering-viewport-types/m-p/9294167#M44333

 

Thanks for your help all.

0 Likes