- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I would like for additional worksets to be created when a user enables worksets in a project model. DocumentWorksharingEnabled event seems the be the likely candidate for this job. Its documentation states thus:
Summary: Subscribe to the DocumentWorksharingEnabled event to be notified when a document has become workshared.
Remarks: This event is raised when Revit has just enabled worksharing in the document.
Handlers of this event are permitted to make modifications to any document (including the active document), except for documents that are currently in read-only mode.
I've written some code (attached) to subscribe to this event and provided an event handler like so:
private void CreateSomeWorksetsAtWorksharingStartup(object obj, DocumentWorksharingEnabledEventArgs e) { Document currentDoc = e.GetDocument(); if (!currentDoc.IsReadOnly) // Why is the model always read-only? { CreateSomeWorksets(currentDoc, new string[] { "Workset A", "Workset B", "Workset N" }); } }
The event fires as expected and the handler code executes, but the document is always read-only. I understand from the documentation that the document can only be modified if not in a read-only mode. However, the documentation also seems to indicate that there are times when the current document is editable and can be modified. Is it possible to find the document in a modifiable state when the DocumentWorksharingEnabled event fires in order to create additional worksets?
A related question has to do with how I have subscribed to the DocumentWorksharingEnabled event. Why must an Application level event be subscribed to at the Document level? It seems convoluted to use a DocumentOpened or DocumentCreated event to subscribe the DocumentWorksharingEnabled (and then have to set a flag so that I don't re-subscribe each time a new document is opened.)
Thank you in advance for your replies!
Solved! Go to Solution.