Thursday, March 03, 2011

Running EXE from AutoCAD

So I was trying to run an EXE from AutoCAD. During debugging the code would work properly, but once I went to run the code the EXE would attempt to run from the directory path of the current drawing. Frustrating to say the least. In order to run an EXE in it’s location you can utilize the WorkingDirectory Property to set the place where the EXE is going to run from.

        Using NewProcess As New Process
NewProcess.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location())
NewProcess.StartInfo.Arguments = sProgramInfo
NewProcess.StartInfo.FileName = sFileName

End Using

The System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location())  gets the path of the current DLL that is running, which happens to be the same location as the EXE program.

1 comment:

scratch project said...

This is a known issue! However, they haven’t yet been able to identify the root of the problem because of the very nature of the random behavior. It should go without saying that if Autodesk can’t reproduce the issue, they can’t fix it.


Blog Widget by LinkWithin