Unable to load DB if using windows form

It is fine if I use windows form:

import clr
from System.Windows.Forms import *
from System.Drawing import *


but once I import this:
from Autodesk.Revit.DB import *

It will have error:

Does anyone know why?

There is probably something in the DB module that’s overwriting a class already imported with your other imports. I would recommend not importing with the ‘*’ method of importing. Instead, you can import and assign each namespace to a variable, like this:

import System.Windows.Forms as sf
import System.Drawing as sd
import Autodesk.Revit.DB as DB

This way, nothing gets overwritten. You just have to adjust your code to add the variable when you are calling a class. For example:

#instead of XYZ(0,0,1), use:

it works!! thanks, this problem troubled me for a long time!! :grinning: :grinning: :grinning:

1 Like