Viewports - Listing Available Element Types

hi Everyone,

I’m looking for a bit of assistance with the below thread:

The method shown by Konrad is clear enough to follow, but it relies on the viewport type being in use (within the project) and using indexes to filter the element to obtain the element with the desired parameter value.

What I’m after is setting my viewports to a specific type by name “No Title”. Is there a way to list the value types like we can do with Family.Types Node?

Thanks,

This python code should work:

import clr

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
#The inputs to this node will be stored as a list in the IN variables.
clr.AddReference('RevitServices')
import RevitServices

from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

collector = FilteredElementCollector(doc).OfClass(ElementType).ToElements()

viewportTypes = []

for e in collector:
	p = e.get_Parameter("Title")
	if not p is None:
	  if p.AsValueString()=="M_View Title":
	  	viewportTypes.append(e)


#Assign your output to the OUT variable.
OUT = viewportTypes

Przechwytywanie

1 Like

hi @maciek.glowka,

Thanks for the quick response and with a custom piece of python!

I’ve tried using your python and I’m getting the following error…

I also tried it as you have it shown (nothing connected to the “IN[0]” Port).

Any ideas?

Thanks,

I was testing on a quite old Revit version. I think in a newer API you might wanna use LookupParameter instead of get_Parameter…Sorry about that.
As of the IN part - nothing should be connected

hi @maciek.glowka,

I have done as directed and replaced:

p = e.get_Parameter ("Title")

with

p = e.LookupParameter ("Title")

The code is erroring this time but its not finding any information either.

Thanks,

Hmm…I’ve tried on a newer Revit version and it worked…maybe your types have different title names eg.
Can you maybe upload the file to examine?

Or you could also change part of the code to this:

for e in collector:
  p = e.LookupParameter("Title")
  if not p is None:
    viewportTypes.append(p.AsValueString())

and see what titles come out

Przechwytywanie

hi @maciek.glowka,

I have modified the code as required. Getting information from the python script node but its erroring on the Element.Name as the output from the python are strings.

In regards this, I have a few types yes. The View Titles are duplicating as the option shown extension is checked in one and unchecked in the other.

The View Title that appears three titles as it covers the types: no line, with line and Show Title unchecked.

(Took me a while to work out that what is being shown is the “Title” value under the type properties for the viewports).

In regards to document upload…

View Title Assistance Sample.rvt (1.3 MB)

Thanks for your continued help. :slight_smile:

Hi @ben.dowling

HI @Kulkul,

Yes that looks like what i’m after. How did you get that list to appear?

As there are 9 “Element Types” with the 9 viewport type references were each assigned to a view prior to the extraction?

Thanks,

Hahaha That’s the magic with few lines of python :sunglasses:

import clr

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference('RevitServices')
import RevitServices

from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

fec = FilteredElementCollector(doc).OfClass(ElementType).ToElements()

vpt = []
names=[]
for f in fec:
  p = f.LookupParameter('Title')
  if not p is None:
    vpt.append(f)
    names = [Element.Name.__get__(i) for i in vpt]


OUT = vpt, names

Please mark the post as solved. You’re Welcome!

2 Likes

hi @Kulkul,

Would love to do so but I’ve got another error popping up…

Is there something I need to download or something?

Thanks,

Could you show me code inside Python Script?

Did you copy pasted above code inside python script?

This modification was for test purposes only…to see what kind of parameter values you have in your project. It seems that you should look for “View Title” string instead of “M_View Tilte” (as was in my code)…

so you can try this one…hope it works now for you

import clr

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
#The inputs to this node will be stored as a list in the IN variables.
clr.AddReference('RevitServices')
import RevitServices

from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

collector = FilteredElementCollector(doc).OfClass(ElementType).ToElements()

viewportTypes = []

for e in collector:
  p = e.LookupParameter("Title")
  if not p is None:
    if "View Title" in p.AsValueString():
      viewportTypes.append(e)

#Assign your output to the OUT variable.
OUT = viewportTypes

2 Likes

Why not just use OOTB nodes with Element Types and All Elements of Type?

hi @SeanP,

I was using this method originally, but I wanted to see the available options in the viewport types. This option requires there to be a viewport with the desired View Title Type to be in use in order for it to be used.

@Kulkul - Yes I pasted your code within the ‘Python Script’ Node. See below:

@maciek.glowka - That did it. Thanks so much. I have provided my graph below in case it is usual for another member of the forum. :slight_smile:

The completed graph’s function is to:

Select all Sheets within Active Document and insert [Legend] at a point indicated.
It then takes these newly added viewports and runs it through the second tier of the script. Changing their viewport types from the default to my preference of “No Title”

Place Legend on A1 Sheets.dyn (50.7 KB)

Thanks for all the help!

1 Like

@ben.dowling you didn’t paste completely. Please have closely look at my code above before you say it didn’t work, you missed to add output.

OUT = vpt, names

1 Like

@Kulkul,

Ah i didn’t notice the scroll bar to the side! :man_facepalming: Sorry about that.

I have added that script to the process and can confirm it works perfectly. :slight_smile: