Name 'Viewport' is not defined-python

i don’t know what is wrong??

Please Help me…

It’s because you are only importing ElementID and XYZ classes from RevitDB namespace. So Viewport is not defined because you are not exposing that part of the RevitDB namespace. You can either import the Viewport class specifically, or import the whole namespace.


how to import whole namespace??

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

see also video

whole namespace are import then new error as below

’List[object]’ object has no attribute ‘Id’ as OUTPUT

Hi @robert12546358,

You asked the same question here. See my previous response.

Lists are a little like onions, to get to the elements at its core you need to strip the layers away. So, the first list contains a bunch of lists, but these are not the Elements, you need to loop through each sublist in the list to get to these.

You may need to do this multiple times depending on how many layers (or how deep) the list has.

This is why List object doesn’t have an attribute ID, as you are assuming in code that it’s a revit element, when its actually in fact a list of revit elements (or perhaps a list of lists of revit elements).

I hope this makes sense.


1 Like

Thanks for your reply :smiley::smiley::smiley:

You’re welcome! :blush: happy coding!