Possible to open Autocad from a dynamo script?

Is this possible?

Background, my company is very heavily reliant on importing dwg’s into their sheet sets (boo!!). We constantly have to (1)open the same file (2)make small updates (3) reimport. It would be nice if I could just keep a path to the dwg as a project param and press a button to open when needed (or script).

You should be able to create a custom Python script node that can launch AutoCAD.
Add these lines:

import subprocess
subprocess.check_call([r"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"])

If you want to open a specific file:
subprocess.check_call([r"C:\Program Files (x86)\Mozilla Firefox\firefox.exe",“https://www.google.com”])

You can make the filename a variable and pass that to the node if you want.

Good luck!

@Jpeele_JDB if you’re referring to AutoCAD Sheet Sets, you might check out the sheet set manager package from @AdammReilly.



Works perfect. The only thing I changed was using Popen instead of check_call so the script doesn’t stay open until AutoCAD closes.

And…then I changed it to just open up the windows explorer folder instead of ACAD since there are multiple files.

Here is Python to open ACAD with file path input:

import sys
sys.path.append(r’C:\Program Files (x86)\IronPython 2.7\Lib’)

import subprocess
subprocess.Popen([r"C:\Program Files\Autodesk\AutoCAD 2020\acad.exe",IN[0]])
OUT = IN[0]

Here is what I went with:

import sys
sys.path.append(r’C:\Program Files (x86)\IronPython 2.7\Lib’)
import subprocess

title = ‘Schedule’
filename = subprocess.Popen([‘explorer’, IN[0]])

OUT = IN[0]

Hope this helps out anybody looking to do something similar in the future

Those are great tweaks—will definitely be adding this to our Dynamo library!

Actually a little more thoughts on this. We can just make a script to open the selected import instance.

Open Selected DWG.dyn (14.6 KB)

That’s fantastic! I’ve added it our library already—will certainly be using this quite a lot!

FYI, here is another tweak that might be useful.

By changing the subprocess command to automatically use the current
program associated with the filetype, you don’t need to hard-code the current
version of AutoCAD (which may change in the future or may be different on
other user’s systems):

subprocess.Popen([r"cmd.exe","/c start " + IN[0]])

Good tweak. Haven’t had a chance to test it out, would that work on other imports like pdf’s and images as well?

The Python command would work, yes—I think you have to change the “Element.Category” node to “Element.Name” to get the filename from a PDF or image.

I did run into a bug which I haven’t been able to fix—if the filename contains spaces, it won’t pass the correct filename. In Windows, the command would be start "" "filename with spaces.dwg" but the Python command doesn’t seem to be able to pass double quotes correctly (I tried the standard escape character, using single outer quotes, and using chr(34)—none seem to work).