I started learning Python (and coding all together) this week and i'm stuck on a simple task i want to do.
The functionality i'm looking for is this:
- Print all
.dwg
files in a specified directory in the console. - Open an instance of AutoCAD.
- For every
.dwg
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.dwg
file)
The code i wrote now:
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)))
What happens when i run this:
- Two instances of autocad open.
- The last printed drawing opens in both instances
- It tries to open the first printed file but only in the second instance of AutoCAD and it doesn't find the file.
(I only have 2 .dwg
files in de directory.)
I hope someone can help me out with this.