Solution exception:expected Document, got Document

Hi,

I have created a python code for creating rooms by point. But got the following error:

  1. Solution exception:expected Document, got Document

Do you have any idea why I am getting this error. Here is the code I am trying:

import clr
clr.AddReference('System.Core')
clr.AddReference('RhinoInside.Revit')
clr.AddReference('RevitAPI') 
clr.AddReference('RevitAPIUI')

from System import Enum

import rhinoscriptsyntax as rs
import Rhino
import RhinoInside
import Grasshopper
from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML
from RhinoInside.Revit import Revit, Convert
from Autodesk.Revit import DB
from Autodesk.Revit import Creation

clr.ImportExtensions(RhinoInside.Revit.Convert.Geometry)

# access the active document object
doc = Revit.ActiveDBDocument

def show_warning(msg):
    ghenv.Component.AddRuntimeMessage(RML.Warning, msg)

def show_error(msg):
    ghenv.Component.AddRuntimeMessage(RML.Error, msg)

def show_remark(msg):
    ghenv.Component.AddRuntimeMessage(RML.Remark, msg)

if RUN:
    with DB.Transaction(doc, "Create Rooms by Point") as t:
        t.Start()
        new_rooms = []
        for l, p in zip(level, point):
            new_room = Creation.Document.NewRoom(doc, l, p.ToXYZ())
            new_rooms.append(new_room)
        
        t.Commit()```

@kike , maybe you would help?

I can’t call

__revit__.ActiveUIDocument.Document

either.

Got same error again when I try to create shaft openings through API.

Create is a property of DB.Document, and NewRoom takes a DB.UV.

Try this.

import clr
clr.AddReference('RevitAPI')
clr.AddReference('RhinoInside.Revit')

from Autodesk.Revit import DB
from Rhino.Geometry import Point2d

import RhinoInside
from RhinoInside.Revit import Revit
clr.ImportExtensions(RhinoInside.Revit.Convert.Geometry)

# access the active document object
doc = Revit.ActiveDBDocument

if RUN:
    with DB.Transaction(doc, "Create Rooms by Point") as t:
        t.Start()
        new_rooms = []
        for l, p in zip(level, point):
            new_room = doc.Create.NewRoom(l, Point2d(p).ToUV())
            new_rooms.append(new_room)
        
        t.Commit()
1 Like

Thanks @kike,

I am quite new in Revit API. Excuse my simple questions :sweat_smile:

It’s totally fine :grinning:

I use this site as reference http://apidocs.co it has RhinoCommon and Revit API.

Yes, I know apidocs.co. But I don’t understand every reference or make mistakes like above since it is C based.