Search code examples
.netvb.netdllautoloadautocad

How can I load automatically .dll plugins in AutoCAD 2019?


How can I load automatically .dll plugins in AutoCAD 2019? Preferably without changing any file in AutoCAD directory (I'm not the admin). I'm trying to load this plugin that registers, in an excel file, when AutoCAD is closed. It was created with .net in vb.

I've tried this but failed because i'm not the admin and cannot change files in AutoCAD directory:

https://knowledge.autodesk.com/support/autocad/troubleshooting/caas/sfdcarticles/sfdcarticles/How-to-autoload-DLLs-with-AutoCAD.html

There has to be a solution that does not involve manually editing files in AutoCAD's directory. Specially because this is meant to be used in 200+ computers at the company I work company.

I created this plug-in in visual studio with .net in vb, as follows:

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Excel = Microsoft.Office.Interop.Excel
Imports System.IO

Public Class Class1
    <CommandMethod("AddAppEvent")>
    Public Sub AddAppEvent()
        AddHandler Application.SystemVariableChanged, AddressOf appSysVarChanged
    End Sub

    <CommandMethod("RemoveAppEvent")>
    Public Sub RemoveAppEvent()
        RemoveHandler Application.SystemVariableChanged, AddressOf appSysVarChanged
    End Sub

    Public Sub appSysVarChanged(ByVal senderObj As Object,
                                ByVal sysVarChEvtArgs As Autodesk.AutoCAD.ApplicationServices.
                                SystemVariableChangedEventArgs)

        Dim oVal As Object = Application.GetSystemVariable(sysVarChEvtArgs.Name)

        Dim fileTest As String = "C:\Users\rita.aguiar\Documents\AutoCAD plug-in\Registo de Eventos.xlsx"
        If File.Exists(fileTest) Then
            File.Delete(fileTest)
        End If

        Dim oExcel As Object
        oExcel = CreateObject("Excel.Application")
        Dim oBook As Excel.Workbook
        Dim oSheet As Excel.Worksheet

        oBook = oExcel.Workbooks.Add
        oSheet = oExcel.Worksheets(1)

        oSheet.Name = "Fecho do AutoCAD"
        oSheet.Range("A1").Value = "O AutoCAD foi encerrado."
        oBook.SaveAs(fileTest)
        oBook.Close()
        oBook = Nothing
        oExcel.Quit()
        oExcel = Nothing
    End Sub

End Class

It would be lovely if there was something else I could write here to at least enable the register of events automatically, instead of always having to enable it by hitting "AddAppEvent" Command in AutoCAD. And I also wanted to automate the loading of the plugin, instead of having to manually hit "netload" and choose the .dll file everytime I open an autoCAD file.

Many thanks.


Solution

  • Just use the ApplicationPlugins folder.

    That's the way AutoCAD loads plugins. (which can be Dll's)

    Documentation is here: https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-5E50A846-C80B-4FFD-8DD3-C20B22098008

    See An example here: https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-40F5E92C-37D8-4D54-9497-CD9F0659F9BB