<?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: interop COM list all open DWG files from all running sessions in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/interop-com-list-all-open-dwg-files-from-all-running-sessions/m-p/8210971#M25016</link>
    <description>&lt;P&gt;You need to cast cs1 to an AcadDocument, not an AcadApplication. The objects in the ROT are documents, not application.&lt;/P&gt;</description>
    <pubDate>Mon, 20 Aug 2018 12:55:13 GMT</pubDate>
    <dc:creator>FRFR1426</dc:creator>
    <dc:date>2018-08-20T12:55:13Z</dc:date>
    <item>
      <title>interop COM list all open DWG files from all running sessions</title>
      <link>https://forums.autodesk.com/t5/net-forum/interop-com-list-all-open-dwg-files-from-all-running-sessions/m-p/8201032#M25010</link>
      <description>&lt;P&gt;New custom dev needed . Must be external,&amp;nbsp; must run outside AutoCAD. How would I list all DWG files opened by the user - the user may have more than one session running . Only one version of AutoCAD will need to be supported per year.&lt;/P&gt;&lt;P&gt;Thx for your patience,&lt;/P&gt;&lt;P&gt;Kevin.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Aug 2018 13:00:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/interop-com-list-all-open-dwg-files-from-all-running-sessions/m-p/8201032#M25010</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-08-15T13:00:19Z</dc:date>
    </item>
    <item>
      <title>Re: interop COM list all open DWG files from all running sessions</title>
      <link>https://forums.autodesk.com/t5/net-forum/interop-com-list-all-open-dwg-files-from-all-running-sessions/m-p/8204295#M25011</link>
      <description>&lt;P&gt;You can query the Runtime Object Table (ROT) for that. &lt;A href="http://alax.info/blog/1444" target="_blank"&gt;Here&lt;/A&gt;, you can download an utility named RotView which show you what is currently in the table. There will be an entry for each document opened in AutoCAD.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The documentation of the Windows API can be found &lt;A href="https://docs.microsoft.com/en-us/windows/desktop/api/objbase/nf-objbase-getrunningobjecttable" target="_blank"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Philippe has written a blog post which show how to enumerate the table in C# &lt;A href="http://adndevblog.typepad.com/autocad/2013/12/accessing-com-applications-from-the-running-object-table.html" target="_blank"&gt;here&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Aug 2018 15:00:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/interop-com-list-all-open-dwg-files-from-all-running-sessions/m-p/8204295#M25011</guid>
      <dc:creator>FRFR1426</dc:creator>
      <dc:date>2018-08-16T15:00:53Z</dc:date>
    </item>
    <item>
      <title>Re: interop COM list all open DWG files from all running sessions</title>
      <link>https://forums.autodesk.com/t5/net-forum/interop-com-list-all-open-dwg-files-from-all-running-sessions/m-p/8210606#M25012</link>
      <description>&lt;P&gt;did you get the ROT to work ? I tried using the code from the blog - did not work for me, it only displayed one of two sessions&amp;nbsp;&amp;nbsp; : (&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 10:08:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/interop-com-list-all-open-dwg-files-from-all-running-sessions/m-p/8210606#M25012</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-08-20T10:08:56Z</dc:date>
    </item>
    <item>
      <title>Re: interop COM list all open DWG files from all running sessions</title>
      <link>https://forums.autodesk.com/t5/net-forum/interop-com-list-all-open-dwg-files-from-all-running-sessions/m-p/8210629#M25013</link>
      <description>&lt;P&gt;Aha!&amp;nbsp; i have some success ... thx Max .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 10:23:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/interop-com-list-all-open-dwg-files-from-all-running-sessions/m-p/8210629#M25013</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-08-20T10:23:45Z</dc:date>
    </item>
    <item>
      <title>Re: interop COM list all open DWG files from all running sessions</title>
      <link>https://forums.autodesk.com/t5/net-forum/interop-com-list-all-open-dwg-files-from-all-running-sessions/m-p/8210689#M25014</link>
      <description>&lt;P&gt;this worked for me - for now ..&amp;nbsp; I just needed to list all DWG files opened in all sessions ... in the future I will need to add much more to edit DWG CAD objects ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        [DllImport("ole32.dll")]
        private static extern void CreateBindCtx(int reserved, out IBindCtx ppbc);

        [DllImport("ole32.dll")]
        private static extern int GetRunningObjectTable(int reserved, out IRunningObjectTable prot);

        public void allopendwgfiles()
        {
            string msg1 = "...\r\n";
            if (GetRunningObjectTable(0, out IRunningObjectTable pprot) == 0)
            {
                pprot.EnumRunning(out IEnumMoniker ppenumMoniker);
                ppenumMoniker.Reset();
                var moniker = new IMoniker[1];
                while (ppenumMoniker.Next(1, moniker, IntPtr.Zero) == 0)
                {
                    CreateBindCtx(0, out IBindCtx ppbc);
                    moniker[0].GetDisplayName(ppbc, null, out string ppszDisplayName);
                    Marshal.ReleaseComObject(ppbc);
                    if (ppszDisplayName.ToLower().Contains(".dwg")) // // .DWT .DWS maybe ...
                    {
                        pprot.GetObject(moniker[0], out object ppunkObject);
                        msg1 = msg1 + ppszDisplayName + "\r\n";
                    }
                }
            }
            System.Windows.Forms.MessageBox.Show(msg1);
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 10:57:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/interop-com-list-all-open-dwg-files-from-all-running-sessions/m-p/8210689#M25014</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-08-20T10:57:01Z</dc:date>
    </item>
    <item>
      <title>Re: interop COM list all open DWG files from all running sessions</title>
      <link>https://forums.autodesk.com/t5/net-forum/interop-com-list-all-open-dwg-files-from-all-running-sessions/m-p/8210956#M25015</link>
      <description>&lt;P&gt;error ... unable to cast COM ... to interface type Autodesk.AutoCAD.interop.AcadApplication ...&lt;/P&gt;&lt;P&gt;In trying to go further ... error occurs in the cast line of the list of COM objects AcadApplication acApp = (AcadApplication)cs1 ... why? The properties of cs1 show that it is AutoCAD - what have I missed? (AutoCAD 2018 , AutoCAD.Application.22 ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;            openDWGset = new List&amp;lt;string&amp;gt;();
            List&amp;lt;object&amp;gt; CADsessionSet = new List&amp;lt;object&amp;gt;();
            if (GetRunningObjectTable(0, out IRunningObjectTable pprot) == 0)
            {
                pprot.EnumRunning(out IEnumMoniker ppenumMoniker);
                ppenumMoniker.Reset();
                var moniker = new IMoniker[1];
                while (ppenumMoniker.Next(1, moniker, IntPtr.Zero) == 0)
                {
                    CreateBindCtx(0, out IBindCtx ppbc);
                    moniker[0].GetDisplayName(ppbc, null, out string ppszDisplayName);
                    if (ppszDisplayName.ToLower().Contains(".dwg")) 
                    {
                        object ComObject;
                        pprot.GetObject(moniker[0], out ComObject);
                        if (ComObject is null)
                            continue;
                        CADsessionSet.Add(ComObject);
                    }
                    Marshal.ReleaseComObject(ppbc);
                }
            }
            foreach(object cs1 in CADsessionSet)
            {
                try
                {
                    AcadApplication acApp = (AcadApplication)cs1;
                    foreach (AcadDocument doc1 in acApp.Documents)
                    {
                        if (!openDWGset.Contains(doc1.Name))
                            openDWGset.Add(doc1.Name);
                    }
                }
                catch(System.Exception ex1) {
                    System.Windows.Forms.MessageBox.Show(ex1.Message);
                };
            }&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Aug 2018 12:48:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/interop-com-list-all-open-dwg-files-from-all-running-sessions/m-p/8210956#M25015</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-08-20T12:48:26Z</dc:date>
    </item>
    <item>
      <title>Re: interop COM list all open DWG files from all running sessions</title>
      <link>https://forums.autodesk.com/t5/net-forum/interop-com-list-all-open-dwg-files-from-all-running-sessions/m-p/8210971#M25016</link>
      <description>&lt;P&gt;You need to cast cs1 to an AcadDocument, not an AcadApplication. The objects in the ROT are documents, not application.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 12:55:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/interop-com-list-all-open-dwg-files-from-all-running-sessions/m-p/8210971#M25016</guid>
      <dc:creator>FRFR1426</dc:creator>
      <dc:date>2018-08-20T12:55:13Z</dc:date>
    </item>
    <item>
      <title>Re: interop COM list all open DWG files from all running sessions</title>
      <link>https://forums.autodesk.com/t5/net-forum/interop-com-list-all-open-dwg-files-from-all-running-sessions/m-p/8212947#M25017</link>
      <description>&lt;P&gt;Thx Max!!!&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : )&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using Autodesk.AutoCAD.Interop;
namespace nsCADi
{
    public class cadinterop
    {
        [DllImport("ole32.dll")]
        private static extern void CreateBindCtx(int reserved, out IBindCtx ppbc);
        [DllImport("ole32.dll")]
        private static extern int GetRunningObjectTable(int reserved, out IRunningObjectTable prot);
        public void AllDWGbyROT(ref List&amp;lt;string&amp;gt; openDWGset)
        {
            openDWGset = new List&amp;lt;string&amp;gt;();
            List&amp;lt;object&amp;gt; COMDocSet = new List&amp;lt;object&amp;gt;();
            if (GetRunningObjectTable(0, out IRunningObjectTable pprot) == 0)
            {
                pprot.EnumRunning(out IEnumMoniker ppenumMoniker);
                ppenumMoniker.Reset();
                var moniker = new IMoniker[1];
                while (ppenumMoniker.Next(1, moniker, IntPtr.Zero) == 0)
                {
                    CreateBindCtx(0, out IBindCtx ppbc);
                    moniker[0].GetDisplayName(ppbc, null, out string ppszDisplayName);
                    if (ppszDisplayName.ToLower().Contains(".dwg")) 
                    {
                        object ComObject;
                        pprot.GetObject(moniker[0], out ComObject);
                        if (ComObject is null)
                            continue;
                        COMDocSet.Add(ComObject);
                    }
                    Marshal.ReleaseComObject(ppbc);
                }
            }
            foreach(object cd1 in COMDocSet)
            {
                try
                {
                    AcadDocument cdoc1 = (AcadDocument)cd1;
                    AcadApplication acApp = cdoc1.Application;
                    foreach (AcadDocument doc1 in acApp.Documents)
                    {
                        if (!openDWGset.Contains(doc1.FullName))
                            openDWGset.Add(doc1.FullName);
                    }
                }
                catch(System.Exception ex1) {
                };
            }
        }
    }
}&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Aug 2018 04:18:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/interop-com-list-all-open-dwg-files-from-all-running-sessions/m-p/8212947#M25017</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-08-21T04:18:02Z</dc:date>
    </item>
  </channel>
</rss>

