Hi ,

i am new to python scripting in dynamo. so please excuse me if my question looks silly and shed some light on me :slight_smile:
what i understood from some tutorial in internet is, we have to use CurrentDBDocument method to accesses current open revit file. if i need to know the syntax i have to check the RevirServices.dll.
So i have opened dll file in visual studio community navigated to DocumentManager class from RevitServices.Persistence namespace in RevitServices assembly, i am clear till this point.
Now when i click on CurrentDBDocument Method i expect to see the syntax of that method which shows as CurrentDBDocument { get; } but what i learn from tutorial is i need to enter something like this
line1 - Clr.AddReference(‘RevitServices’)
line2 - from RevitServices.Persistence import DocumentManager
line3 - from RevitServices.Persistence import TransactionManager
line4 - doc = DocumentManager.Instance.CurrentDBDocument
mu confusion is in line 4 , “doc” is the variable, i need to store this value in some variable so i have created a variable. now which i didn’t understand is **DocumentManager.Instance.**CurrentDBDocument
can someone explain me why i need to write DocumentManager.Instance why can’t i directly use CurrentDBDocument

Thanks a lot

You can not use it directly because you have to do it over DocumentManager. Only over DocumentManager you can access CurrentDBDocument.

1 Like

as i have stated in line 2 i have imported the DocumentManager class into current file
1)in general while working with any other module if we import the specific class in the module all the methods of that class will be imported to current program. to call the methods its not required to call with class name.
2)what about instance why i need to use that ?

From what I understand you cannot directly use the DocumentManager, you first need to instantiate it through the Instance property and then use it. It seems that this step is required for document resources handling.

I hope that makes sense to you,

gotcha but how can i know for which methods i need to use instance property. what i am looking is is there a way that i can know this from revit API or from somewhere else.

I guess it’s pretty simple : all of them. To my knowledge, this information is not specified in the revit API as DocumentManager is tied to Dynamo.

Your best shot is looking up the DocumentManager class but it appears logical that the methods are meant to be called from an instance of DocumentManager.

From my understanding, DocumentManager uses the Singleton Pattern, which prevents you from creating a new instance but instead that is handled within the class itself and always uses the same throughout the same execution context. That’s why you cannot do

#This would generally create a new instance of a class
docManager = DocumentManager() 


docManager = DocumentManager.Instance

In summary, to use any property/method from DocumentManager you need an instance of it and the only way to get one is through DocumentManager.Instance


Singleton pattern :man_facepalming: but yeah, @alvpickmans is correct.