2

In AutoCAD, I learned how to make a custom menu item via Customize User Interface by making a command with the following Macro:

enter image description here

After selecting the created custom menu, a "Security - Unsigned Executable File" dialog would launch:

enter image description here

How do I write the command where after selecting the custom menu and selecting [Load Once], a function within the DLL is called?

Is that possible?

libzz
  • 589
  • 2
  • 10
  • 29
  • I changed my mind on programagically selecting [Load Once]. It might be (ethically) wrong as this should be the choice of the user. So, I am going to scratch that one and change my question. – libzz Sep 21 '18 at 00:43

2 Answers2

0

One way to get around it is through a little tweak in the registry.

Open the registry editor by typing "RegEdit" into Windows search. Navigate to the following key (I am using AutoCAD 2015, so find the version you're using).

HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R20.0\ACAD-E005:409\Profiles\<<YourProfile>>\Variables

Now in the "Variables" key, set the SECURELOAD value to 0. This will disable the security dialog.

Alternatively, you can add your C:\ABC to your trusted locations (but admittedly I've had mixed success with this - I use the registry method). You can set the trusted location manually by opening AutoCAD, going to Options -> Files -> add path to "Trusted Locations". You can also do the same via interop (if needed).

If you want to run a command defined in your dll on startup/doc open, the best way is to add that to one of acad.lsp, acad2015.lsp, acaddoc.lsp, etc. These scripts are executed when starting app/opening documents automatically by AutoCAD

You can also use one of these lisp files to load your dll (as apposed to writing the macro). For example, this would probably do it:

(COMMAND "NETLOAD" "C:\\ABC\\VbXyz.dll")
(COMMAND "MyCommandToRun")

Here's some more information on using AutoLisp to automatically run commands from a dll.

Hope it helps.

Nik
  • 1,780
  • 1
  • 14
  • 23
0

In my VB.NET code, I added a command attribute before the function I want to call.

<CommandMethod("DOSOMETHING", CommandFlags.UsePickSet)>
Public Sub DoSomething()
...
...
End Sub

This makes it possible to call the function by typing-in DOSOMETHING in the AutoCAD Command Line.

After that, I changed the Macro to:

^C^C^P(command "_netload" "C:/ABC/VbXyz.dll");(command "DOSOMETHING")

I don't know if this is the optimal way, but I found a way to work around this problem but the resulting behavior is just as I wanted.

libzz
  • 589
  • 2
  • 10
  • 29