.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Finding the AutoCAd Application folder using VB.Net

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
GeeHaa
3133 Views, 8 Replies

Finding the AutoCAd Application folder using VB.Net

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

8 REPLIES 8
Message 2 of 9
_gile
in reply to: GeeHaa

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");
            }
        }

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 9
_gile
in reply to: _gile

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

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 9
GeeHaa
in reply to: GeeHaa

Thanks Very Much this works perfectly.

Message 5 of 9
Jedimaster
in reply to: GeeHaa

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

Message 6 of 9
GeeHaa
in reply to: Jedimaster

Thanks,

 

I like that better.

Message 7 of 9
kdub_nz
in reply to: GeeHaa

 


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,

//

Everything will work just as you expect it to, unless your expectations are incorrect.

class keyThumper<T> : Lazy<T>;      another  Swamper

Message 8 of 9
GeeHaa
in reply to: kdub_nz

Thanks,

 

Its been so long ago I forgot I was using it in an installer that runs outside of AutoCAD. You are correct.

Message 9 of 9
ThomasLongnecker
in reply to: GeeHaa

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.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost