如何在 AutoCAD 2019 中自动加载 .dll 插件?

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

如何在 AutoCAD 2019 中自动加载 .dll 插件? 最好不要更改 AutoCAD 目录中的任何文件(我不是管理员)。 当 AutoCAD 关闭时,我正在尝试加载这个在 excel 文件中注册的插件。它是在 vb.

中使用 .net 创建的

我试过了但失败了,因为我不是管理员,无法更改 AutoCAD 目录中的文件:

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

必须有一个不涉及手动编辑 AutoCAD 目录中文件的解决方案。特别是因为这意味着要在我工作的公司的 200 多台计算机上使用。

我在visual studio用.net在vb创建了这个插件,如下:

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

如果我可以在这里写一些别的东西来至少自动启用事件注册,而不是总是必须通过在 AutoCAD 中点击 "AddAppEvent" 命令来启用它,那就太好了。而且我还想自动加载插件,而不是每次打开 autoCAD 文件时都必须手动点击 "netload" 并选择 .dll 文件。

非常感谢。

据我所知,AutoCAD 插件只能通过编辑注册表或编辑 link 中提到的文件来自动加载。 没有管理员权限,据我所知将无法解决此问题

只需使用 ApplicationPlugins 文件夹即可。

这就是 AutoCAD 加载插件的方式。 (可以是Dll的)

请参阅此处的示例:

https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2018/ENU/AutoCAD-Customization/files/GUID-40F5E92C-37D8-4D54-9497-CD9F0659F9BB-htm.html

我想出了如何自动加载。其实很简单:

  1. 我创建了一个名为 acad.lsp

  2. 的 lsp 文件
  3. 文件调用 netload 命令加载我的 .dll(以及我创建的其他命令)。

  4. 我把文件存放在C:\Program Files\Autodesk\AutoCAD 2019\Support

  5. 现在每次我打开 AutoCAD 它都会自动加载我的插件!