2.24.2010

startup.lsp: Adding to AutoCAD's Startup Suite programmatically using Lisp

At one time or another, it becomes desirable to add a .lsp file or otherwise to AutoCAD's Startup Suite programmatically. The following Lisp function adds a given file to the current profile's Startup Suite. This is accomplished by manipulating registry values and can be done with VBScript, PowerShell, or just about any other Windows-aware programming language.

In HKEY_CURRENT_USER\Software\Autodesk\AutoCAD, there is a value called "CurVer" which contains the main revision of AutoCAD in use. In that revision's key, there is another "CurVer" value which is the main version of AutoCAD in use. In that version's key, there is a "Profiles" key whose default value is the current profile. Inside that, inside \Dialogs\Appload\Startup\, there are several values. There are "nStartup" values for every startup entry, (i.e. "1Startup","2Startup","3Startup") and a "NumStartup" key containing the number of startup entries.

In summary, the startup entries are contained in:
HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\[Revision]\[Version]\Profiles\[CurrentProfile]\Dialogs\Appload\Startup\

Edit: If working with a fresh installation, there may not be a Startup key. The code now accounts for this.

Download startup.lsp
(defun addToStartupSuite (filename / regpath revision version default ct numstartup n)
(setq regpath "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD"
revision (vl-registry-read regpath "CurVer")
version (vl-registry-read (setq regpath (strcat regpath "\\" revision)) "CurVer")
default (vl-registry-read (setq regpath (strcat regpath "\\" version "\\Profiles")))
regpath (strcat regpath "\\" default "\\Dialogs\\Appload\\Startup")
ct 1
)
(if (setq numstartup (vl-registry-read regpath "NumStartup"))
(progn
(setq n (1+ (atoi numstartup)))
(while (and
(< ct n)
(/= filename (vl-registry-read regpath (strcat (itoa ct) "Startup")))
)
(setq ct (1+ ct))
)
)
(setq n 1)
)
(if (= n ct)
(progn
(vl-registry-write regpath (strcat (itoa n) "Startup") filename)
(vl-registry-write regpath "NumStartup" (itoa n))
)
)
)

Comments are welcome.

3 comments:

  1. One thing brought to my attention today that I was already aware of is that if you run this and it adds a new entry (as opposed to finding an existing entry and doing nothing), and then subsequently open up the Startup Suite dialog, the changes will be discarded.

    This is of little concern though because if this is being called from a .lsp that was already in the Startup Suite, then it will eventually be loaded, if not on the first attempt. The user isn't going to open up the Startup Suite dialog every single time they use AutoCAD.

    If you are using this in something that will be manually loaded only once, then tell the user to restart AutoCAD after you load it manually.

    Thanks to Mike for bringing this to my attention.

    ReplyDelete
  2. Hi - I was wondering if it was possible to check the registry to see if known LISPs are already added to the Startup Suite - and if it finds them, it removes them...

    ReplyDelete
  3. Yes, there is a vl-registry-delete function and you would just delete that key and change the NumStartup value to match. Using lisp to do this isn't very reliable though because AutoCAD tends to write over the changes you've made if someone opens up the Appload dialog. You're better off adding a VBScript to the Windows user startup to remove lisps.

    ReplyDelete