<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Retrieving Active Users in a Revit Central Model File (File-Based) in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/retrieving-active-users-in-a-revit-central-model-file-file-based/m-p/13658610#M74770</link>
    <description>&lt;P&gt;You could compile a list of all the users that have &lt;A href="https://www.revitapidocs.com/2025/205fa377-e6ad-aef0-e783-35b50152c336.htm" target="_blank" rel="noopener"&gt;elements checked out&lt;/A&gt; in the model. It's not going to be perfect (some users may have the model open, but nothing checked out while others may not have relinquished properly and even if they are not in the model, they will show up in the list), but it's a pretty good approximation of who is in the model.&lt;/P&gt;</description>
    <pubDate>Sat, 31 May 2025 00:37:39 GMT</pubDate>
    <dc:creator>eric.stimmel</dc:creator>
    <dc:date>2025-05-31T00:37:39Z</dc:date>
    <item>
      <title>Retrieving Active Users in a Revit Central Model File (File-Based)</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/retrieving-active-users-in-a-revit-central-model-file-file-based/m-p/13272841#M1362</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;I am working on a &lt;STRONG&gt;file-based central model&lt;/STRONG&gt; in Revit and am looking for a way to retrieve a list of active users currently working in the central model file. Specifically, I want to track which users are accessing the central model at any given time.&lt;/P&gt;&lt;P&gt;The scenario is as follows:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;We have a &lt;STRONG&gt;central model&lt;/STRONG&gt; that multiple users are working on.&lt;/LI&gt;&lt;LI&gt;Each user opens the central model and creates a local copy of the file.&lt;/LI&gt;&lt;LI&gt;I want to programmatically extract the list of &lt;STRONG&gt;active users&lt;/STRONG&gt; who currently have the &lt;STRONG&gt;central model file&lt;/STRONG&gt; open.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Is there any method or functionality within the &lt;STRONG&gt;Revit API&lt;/STRONG&gt; that allows me to access this information? Ideally, I would like to get a list of users who are actively working on the file or have the central model open.&lt;/P&gt;&lt;P&gt;I have explored some options such as &lt;STRONG&gt;worksets&lt;/STRONG&gt; and &lt;STRONG&gt;session users&lt;/STRONG&gt;, but I haven’t been able to find a direct API method to fetch this list.&lt;/P&gt;&lt;P&gt;Any guidance or suggestions would be greatly appreciated!&lt;/P&gt;&lt;P&gt;Thank you in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jan 2025 06:02:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/retrieving-active-users-in-a-revit-central-model-file-file-based/m-p/13272841#M1362</guid>
      <dc:creator>DesignGroup01</dc:creator>
      <dc:date>2025-01-21T06:02:38Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieving Active Users in a Revit Central Model File (File-Based)</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/retrieving-active-users-in-a-revit-central-model-file-file-based/m-p/13273068#M1363</link>
      <description>&lt;P&gt;Hello. I asked Gemini for you, and it replies:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;DIV id="model-response-message-contentr_b1ce0520662eb735" class="markdown markdown-main-panel stronger" dir="ltr"&gt;
&lt;P data-sourcepos="5:1-5:413"&gt;You're tackling a common challenge in multi-user Revit workflows. Unfortunately, the Revit API does &lt;EM&gt;not&lt;/EM&gt; provide a direct method to retrieve a list of active users currently working on a file-based central model. This information is managed at the file system level and not exposed through the API. Worksets and session users relate to in-Revit collaboration features (worksharing) and don't reflect file access.&lt;/P&gt;
&lt;P data-sourcepos="7:1-7:78"&gt;However, we can explore some workarounds, understanding they have limitations:&lt;/P&gt;
&lt;P data-sourcepos="9:1-9:60"&gt;&lt;STRONG&gt;1. File Locking Detection (Most Reliable but Imperfect):&lt;/STRONG&gt;&lt;/P&gt;
&lt;P data-sourcepos="11:1-11:221"&gt;The most reliable approach is to check for file locks. When a user opens a central model, Revit creates lock files (e.g., &lt;CODE&gt;.lock&lt;/CODE&gt;, &lt;CODE&gt;~$&lt;/CODE&gt; files on Windows). We can use .NET's &lt;CODE&gt;System.IO&lt;/CODE&gt; functionality to detect these locks.&lt;/P&gt;
&lt;DIV class="code-block ng-tns-c1602499850-18 ng-trigger ng-trigger-codeBlockRevealAnimation"&gt;
&lt;DIV class="code-block-decoration ng-tns-c1602499850-18 header-formatted gds-title-s ng-star-inserted"&gt;&lt;SPAN class="ng-tns-c1602499850-18"&gt;C#&lt;/SPAN&gt;
&lt;DIV class="buttons ng-tns-c1602499850-18 ng-star-inserted"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="ng-tns-c1602499850-18 formatted-code-block-internal-container"&gt;
&lt;DIV class="animated-opacity ng-tns-c1602499850-18"&gt;
&lt;PRE class="ng-tns-c1602499850-18"&gt;&lt;CODE class="code-container ng-tns-c1602499850-18 formatted" role="text" data-test-id="code-content" data-sourcepos="13:1-83:1"&gt;&lt;SPAN class="hljs-keyword"&gt;using&lt;/SPAN&gt; System;
&lt;SPAN class="hljs-keyword"&gt;using&lt;/SPAN&gt; System.Collections.Generic;
&lt;SPAN class="hljs-keyword"&gt;using&lt;/SPAN&gt; System.IO;
&lt;SPAN class="hljs-keyword"&gt;using&lt;/SPAN&gt; System.Linq;

&lt;SPAN class="hljs-keyword"&gt;public&lt;/SPAN&gt; &lt;SPAN class="hljs-keyword"&gt;static&lt;/SPAN&gt; &lt;SPAN class="hljs-keyword"&gt;class&lt;/SPAN&gt; &lt;SPAN class="hljs-title"&gt;RevitUtils&lt;/SPAN&gt;
{
    &lt;SPAN class="hljs-function"&gt;&lt;SPAN class="hljs-keyword"&gt;public&lt;/SPAN&gt; &lt;SPAN class="hljs-keyword"&gt;static&lt;/SPAN&gt; List&amp;lt;&lt;SPAN class="hljs-built_in"&gt;string&lt;/SPAN&gt;&amp;gt; &lt;SPAN class="hljs-title"&gt;GetUsersLockingCentralModel&lt;/SPAN&gt;(&lt;SPAN class="hljs-params"&gt;&lt;SPAN class="hljs-built_in"&gt;string&lt;/SPAN&gt; centralModelPath&lt;/SPAN&gt;)&lt;/SPAN&gt;
    {
        List&amp;lt;&lt;SPAN class="hljs-built_in"&gt;string&lt;/SPAN&gt;&amp;gt; lockingUsers = &lt;SPAN class="hljs-keyword"&gt;new&lt;/SPAN&gt; List&amp;lt;&lt;SPAN class="hljs-built_in"&gt;string&lt;/SPAN&gt;&amp;gt;();

        &lt;SPAN class="hljs-keyword"&gt;if&lt;/SPAN&gt; (!File.Exists(centralModelPath))
        {
            &lt;SPAN class="hljs-keyword"&gt;return&lt;/SPAN&gt; lockingUsers; &lt;SPAN class="hljs-comment"&gt;// Central model doesn't exist&lt;/SPAN&gt;
        }

        &lt;SPAN class="hljs-built_in"&gt;string&lt;/SPAN&gt; lockFilePath = Path.Combine(Path.GetDirectoryName(centralModelPath), &lt;SPAN class="hljs-string"&gt;"~$"&lt;/SPAN&gt; + Path.GetFileName(centralModelPath));
        &lt;SPAN class="hljs-keyword"&gt;if&lt;/SPAN&gt; (File.Exists(lockFilePath))
        {
            &lt;SPAN class="hljs-keyword"&gt;try&lt;/SPAN&gt;
            {
                &lt;SPAN class="hljs-keyword"&gt;&lt;SPAN class="citation-0"&gt;using&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="citation-0"&gt; (&lt;/SPAN&gt;&lt;SPAN class="hljs-keyword"&gt;&lt;SPAN class="citation-0"&gt;var&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="citation-0"&gt; stream = &lt;/SPAN&gt;&lt;SPAN class="hljs-keyword"&gt;&lt;SPAN class="citation-0"&gt;new&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="citation-0"&gt; FileStream(lockFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                &lt;/SPAN&gt;&lt;SPAN class="hljs-keyword"&gt;&lt;SPAN class="citation-0"&gt;using&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="citation-0"&gt; (&lt;/SPAN&gt;&lt;SPAN class="hljs-keyword"&gt;&lt;SPAN class="citation-0"&gt;var&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="citation-0"&gt; reader = &lt;/SPAN&gt;&lt;SPAN class="hljs-keyword"&gt;&lt;SPAN class="citation-0"&gt;new&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="citation-0 citation-end-0"&gt; StreamReader(stream))&lt;/SPAN&gt;
                {
                    &lt;SPAN class="hljs-built_in"&gt;string&lt;/SPAN&gt; firstLine = reader.ReadLine();
                    &lt;SPAN class="hljs-keyword"&gt;if&lt;/SPAN&gt; (!&lt;SPAN class="hljs-built_in"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(firstLine))
                    {
                        &lt;SPAN class="hljs-comment"&gt;// The first line often contains the username. This is *not* guaranteed by Autodesk though!&lt;/SPAN&gt;
                        lockingUsers.Add(firstLine);
                    }
                }

            }
            catch (Exception ex)
            {
                &lt;SPAN class="hljs-comment"&gt;// Handle exceptions (e.g., file access issues)&lt;/SPAN&gt;
                System.Diagnostics.Debug.WriteLine(&lt;SPAN class="hljs-string"&gt;$"Error reading lock file: &lt;SPAN class="hljs-subst"&gt;{ex.Message}&lt;/SPAN&gt;"&lt;/SPAN&gt;);
            }

        }

        &lt;SPAN class="hljs-comment"&gt;//Check for .lock file (less common with Revit but can happen)&lt;/SPAN&gt;
        &lt;SPAN class="hljs-built_in"&gt;string&lt;/SPAN&gt; legacyLockFilePath = centralModelPath + &lt;SPAN class="hljs-string"&gt;".lock"&lt;/SPAN&gt;;

        &lt;SPAN class="hljs-keyword"&gt;if&lt;/SPAN&gt; (File.Exists(legacyLockFilePath))
        {
            lockingUsers.Add(&lt;SPAN class="hljs-string"&gt;"Lock File Exists"&lt;/SPAN&gt;); &lt;SPAN class="hljs-comment"&gt;// Less info available here.&lt;/SPAN&gt;
        }

        &lt;SPAN class="hljs-keyword"&gt;return&lt;/SPAN&gt; lockingUsers;
    }
}

&lt;SPAN class="hljs-comment"&gt;// Example usage:&lt;/SPAN&gt;
&lt;SPAN class="hljs-built_in"&gt;string&lt;/SPAN&gt; centralModelPath = &lt;SPAN class="hljs-string"&gt;@"C:\Path\To\Your\CentralModel.rvt"&lt;/SPAN&gt;;
List&amp;lt;&lt;SPAN class="hljs-built_in"&gt;string&lt;/SPAN&gt;&amp;gt; activeUsers = RevitUtils.GetUsersLockingCentralModel(centralModelPath);

&lt;SPAN class="hljs-keyword"&gt;if&lt;/SPAN&gt; (activeUsers.Any())
{
    &lt;SPAN class="hljs-keyword"&gt;foreach&lt;/SPAN&gt;(&lt;SPAN class="hljs-built_in"&gt;string&lt;/SPAN&gt; user &lt;SPAN class="hljs-keyword"&gt;in&lt;/SPAN&gt; activeUsers)
    {
        TaskDialog.Show(&lt;SPAN class="hljs-string"&gt;"Active Users"&lt;/SPAN&gt;, &lt;SPAN class="hljs-string"&gt;$"User: &lt;SPAN class="hljs-subst"&gt;{user}&lt;/SPAN&gt; has the central model open"&lt;/SPAN&gt;);
    }

}
&lt;SPAN class="hljs-keyword"&gt;else&lt;/SPAN&gt;
{
    TaskDialog.Show(&lt;SPAN class="hljs-string"&gt;"Active Users"&lt;/SPAN&gt;, &lt;SPAN class="hljs-string"&gt;"No users currently have the central model open."&lt;/SPAN&gt;);
}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P data-sourcepos="85:1-85:38"&gt;&lt;STRONG&gt;Key Improvements and Explanations:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL data-sourcepos="87:1-92:0"&gt;
&lt;LI data-sourcepos="87:1-87:193"&gt;&lt;STRONG&gt;Handling &lt;CODE&gt;~$&lt;/CODE&gt; and &lt;CODE&gt;.lock&lt;/CODE&gt; Files:&lt;/STRONG&gt; The code now checks for both the primary &lt;CODE&gt;~$&lt;/CODE&gt; lock file and the less common &lt;CODE&gt;.lock&lt;/CODE&gt;file (sometimes seen in older Revit versions or specific scenarios).&lt;/LI&gt;
&lt;LI data-sourcepos="88:1-88:307"&gt;&lt;STRONG&gt;Reading Lock File Content:&lt;/STRONG&gt; The code attempts to read the &lt;EM&gt;first line&lt;/EM&gt; of the &lt;CODE&gt;~$&lt;/CODE&gt; lock file. Often, this line contains the username. However, &lt;EM&gt;this is not officially documented or guaranteed by Autodesk&lt;/EM&gt;. It's an observation based on common practice. Therefore, relying on this is not 100% reliable.&lt;/LI&gt;
&lt;LI data-sourcepos="89:1-89:158"&gt;&lt;STRONG&gt;Error Handling:&lt;/STRONG&gt; A &lt;CODE&gt;try-catch&lt;/CODE&gt; block is added to handle potential &lt;CODE&gt;IOException&lt;/CODE&gt;s (e.g., if the lock file is already being accessed by another process).&lt;/LI&gt;
&lt;LI data-sourcepos="90:1-90:139"&gt;&lt;STRONG&gt;Clearer Return Value:&lt;/STRONG&gt; The function returns a &lt;CODE&gt;List&amp;lt;string&amp;gt;&lt;/CODE&gt; to handle cases where multiple locks might be present (though rare).&lt;/LI&gt;
&lt;LI data-sourcepos="91:1-92:0"&gt;&lt;STRONG&gt;Example Usage with TaskDialog:&lt;/STRONG&gt; I have included a simple example of how to use the function and display the results using a &lt;CODE&gt;TaskDialog&lt;/CODE&gt; for better user feedback within Revit.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P data-sourcepos="93:1-93:16"&gt;&lt;STRONG&gt;Limitations:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL data-sourcepos="95:1-98:0"&gt;
&lt;LI data-sourcepos="95:1-95:196"&gt;&lt;STRONG&gt;Accuracy:&lt;/STRONG&gt; Relying on file locks only indicates that a Revit process has the file open. It doesn't guarantee active work. A user might have Revit open with the model loaded but be inactive.&lt;/LI&gt;
&lt;LI data-sourcepos="96:1-96:167"&gt;&lt;STRONG&gt;Username Extraction Unreliable:&lt;/STRONG&gt; As mentioned, extracting the username from the lock file is not officially supported and should be treated as an approximation.&lt;/LI&gt;
&lt;LI data-sourcepos="97:1-98:0"&gt;&lt;STRONG&gt;File System Dependency:&lt;/STRONG&gt; This approach is inherently tied to the file system and might not be suitable for cloud-based or other non-standard file storage solutions.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P data-sourcepos="99:1-99:57"&gt;&lt;STRONG&gt;2. Revit Server or Cloud Worksharing (If Applicable):&lt;/STRONG&gt;&lt;/P&gt;
&lt;P data-sourcepos="101:1-101:300"&gt;If you're using Revit Server or BIM 360/Autodesk Construction Cloud (ACC), there are more robust ways to track user activity, often through server logs or cloud platform APIs. These are outside the scope of file-based worksharing but are worth considering if you have those infrastructure components.&lt;/P&gt;
&lt;P data-sourcepos="103:1-103:15"&gt;&lt;STRONG&gt;Conclusion:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P data-sourcepos="105:1-105:238"&gt;While a perfect solution doesn't exist within the Revit API for file-based central models, the file locking method provides a reasonably effective workaround. Remember to clearly communicate the limitations of this approach to your users.&lt;/P&gt;
&lt;P data-sourcepos="107:1-107:125"&gt;I hope this detailed explanation and enhanced code example are helpful. Please let me know if you have any further questions.&lt;/P&gt;
&lt;P data-sourcepos="109:1-109:13"&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 21 Jan 2025 08:35:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/retrieving-active-users-in-a-revit-central-model-file-file-based/m-p/13273068#M1363</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2025-01-21T08:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieving Active Users in a Revit Central Model File (File-Based)</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/retrieving-active-users-in-a-revit-central-model-file-file-based/m-p/13274622#M1364</link>
      <description>&lt;P&gt;so kind of a hack approach, but it works, for both local and cloud based central models. consists of two apps. First, installed on every user machines, upon&amp;nbsp; opening the project, writes/appends to a text file to a network location, file name is the users name an contains the model name(s) only. Upon closing the model, deletes that file. Second part is the reader, this may or may not be on everyone's machines depending on how you want to use the data.&amp;nbsp; we have a revit side app that parses through those text files and displays everyone in the model you are in, and then and admin side client that does that same, but for all active models and users.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jan 2025 22:24:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/retrieving-active-users-in-a-revit-central-model-file-file-based/m-p/13274622#M1364</guid>
      <dc:creator>ctm_mka</dc:creator>
      <dc:date>2025-01-21T22:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieving Active Users in a Revit Central Model File (File-Based)</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/retrieving-active-users-in-a-revit-central-model-file-file-based/m-p/13658610#M74770</link>
      <description>&lt;P&gt;You could compile a list of all the users that have &lt;A href="https://www.revitapidocs.com/2025/205fa377-e6ad-aef0-e783-35b50152c336.htm" target="_blank" rel="noopener"&gt;elements checked out&lt;/A&gt; in the model. It's not going to be perfect (some users may have the model open, but nothing checked out while others may not have relinquished properly and even if they are not in the model, they will show up in the list), but it's a pretty good approximation of who is in the model.&lt;/P&gt;</description>
      <pubDate>Sat, 31 May 2025 00:37:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/retrieving-active-users-in-a-revit-central-model-file-file-based/m-p/13658610#M74770</guid>
      <dc:creator>eric.stimmel</dc:creator>
      <dc:date>2025-05-31T00:37:39Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieving Active Users in a Revit Central Model File (File-Based)</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/retrieving-active-users-in-a-revit-central-model-file-file-based/m-p/13666429#M84067</link>
      <description>&lt;P&gt;Workshare monitor from Autodesk itself?&lt;/P&gt;&lt;P&gt;If you have a local open, it will show all users that have the model open and status (syncing, last sync etc)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any reason you would want to access it with API manually?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jun 2025 19:29:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/retrieving-active-users-in-a-revit-central-model-file-file-based/m-p/13666429#M84067</guid>
      <dc:creator>TripleM-Dev.net</dc:creator>
      <dc:date>2025-06-04T19:29:14Z</dc:date>
    </item>
  </channel>
</rss>

