Double import statements

Can someone explain to me why it is necessary to follow the statement

import Autodesk

with

from Autodesk.Revit.DB import *

Seems to me like a double import statement isn’t it?

Doesnt import Autodesk import everything inside Autodesk?

This would be redundant in a sense. Doing import Autodesk would allow you to use all of the API, but you would have to type Autodesk.Revit.DB preceding every function call. Doing from Autodesk.Revit.DB import * allows you to access the entire API directly.

With import Autodesk:

new_id = Autodesk.Revit.DB.ElementId(1234567)

With from Autodesk.Revit.DB import *:

new_id = ElementId(1234567)

If you are only importing from Autodesk.Revit.DB, this is generally acceptable to do since it is clear which methods/properties/etc. are from the Revit API, but can become problematic if you start importing from other modules e.g. DesignScript.

3 Likes