Hi,
Is there a way to find the AutoCAD Application folder when AutoCAD is not running? I need to copy an ACADDoc.lsp file to the support folder on Installs.
Thanks
Solved! Go to Solution.
Solved by _gile. Go to Solution.
Hi,
You can get it via the registry.
Look for the 'AcadLocation' value in the 'HKLM\SOFTWARE\Autodesk\AutoCAD\R20.0\ACAD-E001:409' key.
This path may differ according to the AutoCAD version but you can get it from the HKCU\Software\Autodesk\AutoCAD\<CurVer value>\<Curver value>.
// Get the AutoCAD current version registry key private static string GetAcadCurVerKey() { StringBuilder sb = new StringBuilder(@"Software\Autodesk\AutoCAD\"); using (RegistryKey acad = Registry.CurrentUser.OpenSubKey(sb.ToString())) { sb.Append(acad.GetValue("CurVer")).Append(@"\"); using (RegistryKey curVer = Registry.CurrentUser.OpenSubKey(sb.ToString())) { return sb.Append(curVer.GetValue("CurVer")).ToString(); } } } // Get the acad.exe location for the AutoCAD current version private static string GetAcadLocation() { using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(GetAcadCurVerKey())) { return (string)rk.GetValue("AcadLocation"); } }
Maybe this is more readable.
C#
// Get the AutoCAD current version registry key public string GetAcadCurVerKey() { RegistryKey rkcu = Registry.CurrentUser; string path = @"Software\Autodesk\AutoCAD\"; using (RegistryKey rk1 = rkcu.OpenSubKey(path)) { path += rk1.GetValue("CurVer"); using (RegistryKey rk2 = rkcu.OpenSubKey(path)) { return path + "\\" + rk2.GetValue("CurVer"); } } } // Get the acad.exe location for the AutoCAD current version public string GetAcadLocation() { RegistryKey rklm = Registry.LocalMachine; string path = GetAcadCurVerKey(); using (RegistryKey rk = rklm.OpenSubKey(path)) { return (string)rk.GetValue("AcadLocation"); } }
VB
' Get the AutoCAD current version registry key Private Function GetAcadCurVerKey() As String Dim rkcu As RegistryKey = Registry.CurrentUser Dim path As String = "Software\Autodesk\AutoCAD\" Using rk1 As RegistryKey = rkcu.OpenSubKey(path) path += rk1.GetValue("CurVer") Using rk2 As RegistryKey = rkcu.OpenSubKey(path) Return path & "\" & rk2.GetValue("CurVer") End Using End Using End Function ' Get the acad.exe location for the AutoCAD current version Private Function GetAcadLocation() As String Dim rklm As RegistryKey = Registry.LocalMachine Dim path As String = GetAcadCurVerKey() Using rk As RegistryKey = rklm.OpenSubKey(path) Return DirectCast(rk.GetValue("AcadLocation"), String) End Using End Function
If you do not want to have to open up the registry
Dim objapp As Object = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication
objapp.path
appears to work
GeeHaa wrote:
Thanks,
I like that better.
GeeHaa,
that code requires AutoCAD to be running, which is contrary to the request in your original post.
Regards,
// Called Kerry in my other life.
Everything will work just as you expect it to, unless your expectations are incorrect.
Sometimes the question is more important than the answer.
class keyThumper<T> : Lazy<T>; another Swamper
I had to change one line in order for windows to find the entire registry path
RegistryKey rklm = Registry.LocalMachine;
RegistryKey rklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
Can't find what you're looking for? Ask the community or share your knowledge.