title: How to open all .dwg files in a directory in one instance of AutoCAD using Python
body: <p>I started learning Python (and coding all together) this week and i'm stuck on a simple task i want to do.</p>
  
  <p>The functionality i'm looking for is this:</p>
  
  <ol>
  <li>Print all <code>.dwg</code> files in a specified directory in the console.</li>
  <li>Open an instance of AutoCAD.</li>
  <li>For every <code>.dwg</code> file in said directory open a drawing in a new tab. (If i have an instance of AutoCAD open it automatically opens tabs when double clicking a <code>.dwg</code> file) </li>
  </ol>
  
  <p>The code i wrote now:</p>
  
  <pre class="lang-py prettyprint-override"><code>import os
  import subprocess
  
  autocadPath = r'C:\Program Files\Autodesk\AutoCAD 2019\acad.exe'     
  
  for file in os.listdir("D:\openFiles"):
      if file.endswith(".dwg"):
          print(os.path.join("D:\openFiles", file))
  
          subprocess.Popen("%s %s" % (autocadPath, os.path.join("D:\openFiles", file))) 
  </code></pre>
  
  <p>What happens when i run this: </p>
  
  <ol>
  <li>Two instances of autocad open.</li>
  <li>The last printed drawing opens in both instances</li>
  <li>It tries to open the first printed file but only in the second instance of AutoCAD and it doesn't find the file. </li>
  </ol>
  
  <p>(I only have 2 <code>.dwg</code> files in de directory.)</p>
  
  <p>I hope someone can help me out with this.</p>