OpenAndActivateDocument - How to know if document has been fully activated?

OpenAndActivateDocument - How to know if document has been fully activated?

vitalij.marcukov2BP2F
Advocate Advocate
124 Views
1 Reply
Message 1 of 2

OpenAndActivateDocument - How to know if document has been fully activated?

vitalij.marcukov2BP2F
Advocate
Advocate

Hello All,

I have a script that creates a new project, saves it, closes it, and then re-opens it. After reopening (using the OpenAndActivateDocument method), I proceed to enable worksharing and create worksets. My concern is whether the document is fully loaded and activated immediately after calling OpenAndActivateDocument. Specifically, is there a risk that the document is not yet fully activated when I attempt to enable worksharing and start a transaction? If so, what is the best practice to ensure the document is fully ready before performing these actions? I’m also aware it’s not allowed to have an open transaction in the active document when calling OpenAndActivateDocument.

 

doc_start = app.NewProjectDocument(template_path)
doc_start.SaveAs(save_path)
doc_start.Close()
uiapp = UIApplication(app)
uidoc = uiapp.OpenAndActivateDocument(save_path)
doc = uidoc.Document
doc.EnableWorksharing('Shared Levels and Grids', 'Workset1')
Then I also create predifined worksets

 

0 Likes
Accepted solutions (1)
125 Views
1 Reply
Reply (1)
Message 2 of 2

naveen.kumar.t
Autodesk Support
Autodesk Support
Accepted solution

Hi @vitalij.marcukov2BP2F ,

The Application.OpenAndActivateDocument(filePath) method blocks execution until the document has been fully loaded and activated. Once the call returns, the UIDocument and its underlying Document are ready for transactions.

Alternatively, you can use the DocumentOpened event, which is raised immediately after Revit finishes opening a document and is useful for handling post-open logic in a more event-driven manner.


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network