Selecting Current Document - Python vs Dynamo Node

I am trying to get the current document and I see there are 2 options:

  1. Document.Current that returns a Revit.Application.Document.
  2. Call it from the RevitServices which return a Autodesk.Revit.DB.Document.

When writing a python code to perform the basic FilteredElementCollector, the first doesn’t work and the latter does work.

Can anyone explain the difference between the two and what is the approach to use them?

First option - Revit.Application.Document

Second option - Autodesk.Revit.DB.Document

The first is a Dynamo object and the second is a Revit object. Although Dynamo uses the same Revit API that Python does, it uses a wrapper for handling objects in the workspace. This allows Dynamo nodes to interact with each other regardless of whether the objects are from Revit or from Dynamo itself. In python, you’ll often see the UnwrapElement() method. This method converts the Dynamo object back into the appropriate Revit object. There are a number of other methods used for specific type conversions. You can find more information in the Dynamo Primer and here on the forums.

2 Likes

That is what I thought, that it is a dynamo object. I tried unwraping the element (see marked attached) but it still doesn’t work.

I don’t believe the wrapper works for documents in all (any?) builds…

2 Likes

I would say why not do the get current document within python instead. There are some examples of this with the filterelementcollector that should help to guide you on understanding things.

dynamoPython/revitAPI at master · Amoursol/dynamoPython

I will add that there has been previous issues which includes this one and is one reason not to add current document via dynamo node and to do it within python - Python Error: Expected Document, Got Document - Developers - Dynamo

3 Likes