<?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 .NET Code to Get a Particular Running Instance of AutoCAD in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/net-code-to-get-a-particular-running-instance-of-autocad/m-p/5469639#M41694</link>
    <description>&lt;P&gt;I have some VB.NET code which checks for a running instance of AutoCAD and uses it. Trouble is several of our users like to open up 4 even 5 instances of AutoCAD when they are working. So, in that case, is there a way to filter through all five instances to find the particular drawing?&lt;/P&gt;</description>
    <pubDate>Wed, 14 Jan 2015 18:59:10 GMT</pubDate>
    <dc:creator>btillman</dc:creator>
    <dc:date>2015-01-14T18:59:10Z</dc:date>
    <item>
      <title>.NET Code to Get a Particular Running Instance of AutoCAD</title>
      <link>https://forums.autodesk.com/t5/net-forum/net-code-to-get-a-particular-running-instance-of-autocad/m-p/5469639#M41694</link>
      <description>&lt;P&gt;I have some VB.NET code which checks for a running instance of AutoCAD and uses it. Trouble is several of our users like to open up 4 even 5 instances of AutoCAD when they are working. So, in that case, is there a way to filter through all five instances to find the particular drawing?&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jan 2015 18:59:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/net-code-to-get-a-particular-running-instance-of-autocad/m-p/5469639#M41694</guid>
      <dc:creator>btillman</dc:creator>
      <dc:date>2015-01-14T18:59:10Z</dc:date>
    </item>
    <item>
      <title>Re : .NET Code to Get a Particular Running Instance of AutoCAD</title>
      <link>https://forums.autodesk.com/t5/net-forum/net-code-to-get-a-particular-running-instance-of-autocad/m-p/5473136#M41695</link>
      <description>&lt;P&gt;If you know the path of the drawing, you can use&amp;nbsp;Marshal.BindToMoniker:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;object acadDoc = Marshal.BindToMoniker("Path of the dwg");

// Calling the GetVariable method to read the system variable DWGNAME with late binding
var dwgName = (string)acadDoc.GetType().InvokeMember("GetVariable", BindingFlags.InvokeMethod, null, acadDoc, new[] {"DWGNAME"});&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;The drawing will be opened if it's not loaded. To test if the drawing is opened, you can read the ROT &amp;nbsp;(Running Object Table):&lt;/P&gt;&lt;PRE&gt;static bool DwgIsOpen(string path)
{
    IRunningObjectTable rot = null;
    IEnumMoniker monikerEnumerator = null;
    IBindCtx bindCtx = null;
    try
    {
        Marshal.ThrowExceptionForHR(GetRunningObjectTable(0, out rot));
        rot.EnumRunning(out monikerEnumerator);
        var pNumFetched = new IntPtr();
        var monikers = new IMoniker[1];
        Marshal.ThrowExceptionForHR(CreateBindCtx(0, out bindCtx));
        while (monikerEnumerator.Next(1, monikers, pNumFetched) == 0)
        {
            IMoniker moniker = monikers[0];

            string displayName;
            moniker.GetDisplayName(bindCtx, null, out displayName);
            if (displayName.Equals(path, StringComparison.OrdinalIgnoreCase))
                return true;
        }
    }
    finally
    {
        if (rot != null) Marshal.ReleaseComObject(rot);
        if (monikerEnumerator != null) Marshal.ReleaseComObject(monikerEnumerator);
        if (bindCtx != null) Marshal.ReleaseComObject(bindCtx);
    }

    return false;
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Jan 2015 10:23:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/net-code-to-get-a-particular-running-instance-of-autocad/m-p/5473136#M41695</guid>
      <dc:creator>FRFR1426</dc:creator>
      <dc:date>2015-01-17T10:23:01Z</dc:date>
    </item>
  </channel>
</rss>

