Python - Cant get View Family Types Name in one script

Hi,

I’m writing some Python code in Dynamo to set up elevations.

As part of this I need to find a certain ViewFamilyTypes - to do this I need to return the ViewFamilyTypes Name, which I can do with the following two pieces of code:

(Note that the code picks out the fifth ViewFamilyTypes - which is the one I need, I will eventually write some code which evaluates the list).

And then:

This returns:

Which is what I want.

But I want don’t want two pieces of code, I want to add them together, so I did this:

But this generates the error:

Am I missing something, I cant work out why two pieces of code works, whereas one doesn’t.

I would appreciate some advise.
Thanks.

Hi @Kevin_Bell

If you wrap your element you’ll be able to access it’s name :

Make sure to import all the required extensions:

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import*
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

doc = DocumentManager.Instance.CurrentDBDocument
a = []

viewfamilies = FilteredElementCollector(doc).OfClass(ViewFamilyType).ToElements()

pickone = viewfamilies[5].ToDSType(True)

name = pickone.Name


OUT = name
3 Likes

I see, I thought wrapping was either the WrapElements or UnWrapElements command - ToDSType is new to me.

Where can I find information about the Revit.Elements namespace? Looking through the Revit 2015 API.chm help file I cannot seem to find anything in there. Guess its a Dynamo thing then…

Yes It’s a Dynamo thing. You can read about it here: https://github.com/DynamoDS/Dynamo/wiki/Python-0.6.3-to-0.7.x-Migration#revitapi (and maybe here http://dynamoprimer.com/09_Custom-Nodes/9-5_Python-Revit.html)

2 Likes

Thank you @Mostafa_El_Ayoubi this is helpful. But I was wondering if want to get the name of a ViewFamily in a python script but outside dynamo will this work?
Since I far as I know that unwrapping Elements is only a dynamo thing right?