krispy 的个人资料Kristian's Space日志列表留言簿更多 ![]() | 帮助 |
Kristian's Space |
||||||||||||||||
|
10月15日 Deploying DLLs Over the NetworkAfter initially "installing" my .net app's to users computers via lisp within AutoCAD I ran into the problem of updating a dll. The problem lies with one of my applications that sets reactors in each drawing, as such it needs to be loaded at AutoCAD startup. Obviously if the dll is loaded it cannot be deleted because it is in use. So we have decided to use a vbscript file to install and update dlls, so far so good.
I have created a script file that sits on the network that contains a sub which will install/update a dll file onto the user's local machine and setup registry keys for demand loading. This network script file is then called by a local script file in each user's startup folder.
The local user's file contains:
ExecuteGlobal _ WScript.Quit
The network file contains:
SetupApp "APP_NAME", "Application Description", "FILENAME.dll", LOADCTRLS, "COMMAND_NAME", "GROUP_NAME", True Const APPLICATION_DATA = &H1a& If DEBUGGING Then WScript.Echo "AutoCAD add-ons installed" Sub SetupApp(sAppName, sDescription, sFileName, iLoadCtrls, sCommandName, sGroupName, bUpdate) Function FileInUse(sFileName)
Basically what this file does is to copy a central (network) version of the dll to the user's local machine. If the dll already exists it will delete it first and replace it with the new one. It will then write the appropriate keys to the registry to set up the application for demand loading within AutoCAD. A brief description of the Sub's arguments:
If the dll does not contain any commands you will still need to include an argument for sCommandName and sGroupName but they should both be vbNullString.
10月9日 *error* handlingSomething I have been playing around with lately in the LISP world is error handling. Previously I would create a separate error function and set values for olderr and *error* within the main function. I have since discovered the joys of declaring the *error* function local and nesting it within the main function:
(defun MAIN (/ *error* xCmdEcho)
(setq xCmdEcho (getvar "CMDECHO")) (defun *error* (msg) (if (or (= msg "Function cancelled") (= msg "quit / exit abort") ) (princ) (princ (strcat "\nError: " msg)) );end if (setvar "CMDECHO" xCmdEcho) );end error function ;main function contents
(exit nil)
);end defun MAIN
The advantage of this, besides having the code encapsulated and local so it is destroyed at the end of the main function, is that not only can you use the *error* function to reset system variables in case of an error, you can also explicitly call the function at the end of the main function like so: (exit nil).
This ability to call (exit nil) can be used anywhere within the main function and can be used to terminate execution if invalid input is detected from the user, rather than having multiple nested if's and progn's.
The example above simply exits quietly (and resets CMDECHO) if it is called with (exit nil) or if the user hits [ESC], or displays the error message if something unexpected happened. 10月8日 Registry Keys for Demand LoadingThese can be set with a registry file (i.e. *.reg) like so:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R17.1\ACAD-6001:409\Applications\<Application Name>]
"DESCRIPTION"="<Application Description>" "LOADCTRLS"=dword:00000002 "MANAGED"=dword:00000001 "LOADER"="<Location of dll on local machine>" [HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R17.1\ACAD-6001:409\Applications\<Application Name>\Commands]
"<Command Name>"="<Command Name>" [HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R17.1\ACAD-6001:409\Applications\<Application Name>\Groups]
"<Command Group>"="<Command Group>" A few points:
The AutoCAD keys R17.1 and ACAD-6001:409 refer to the build and region of the AutoCAD application. For example, the values shown above are for AutoCAD 2008, english. (AutoCAD 2007 would be R17.0).
The <Application Name> and <Application Description> are not referred to within the dll so can be any value that is descriptive.
The LOADCTRLS value should be set according to the desired loading behaviour. See my previous post on LOADCTRLS.
The MANAGED key is always set to 1 for .NET dlls
The LOADER key is the path to the dll file on the local machine. Any backslashes used in the path should be escaped, i.e. \ becomes \\
The Commands key is only used if there is a command created within the dll. So if the dll only has reactors then this part can be left out. The Key Name and Value sould be the same as the command name specified within the dll.
The Groups key is optional.
LOADCTRLSOne of the things I am continuously forgetting is the value of LOADCTRLS I need to add to the registry. Below are the possible values (taken straight from the ObjectARX documentation):
0x01 = Load application on detection of proxy object
0x02 = Load the application on AutoCAD startup 0x04 = Load the application on command invocation 0x08 = Load the application on request by user or other application 0x10 = Do not load the application 0x20 = Load the application transparently Of course, these values can be added when required.
Generally I will use either the 0x02 value when I have reactors that need to be added to all documents, or will combine 0x04 & 0x08 for applications that simply add a command.
I have not yet tried creating proxy objects, so have not had to play with these values. WelcomeWelcome to Kristian's Space.
I am starting this blog primarily to keep track of the code snippets and tricks I discover as I continue to learn more about programming for AutoCAD. Hopefully others will also find it useful.
Most of the information I gather is either from the built in documentation within the relevant packages, or from discussion groups. If I have a specific block of code or quote from someone I will try to credit the author here. Mostly I will be talking about AutoCAD and Revit programming and I rely on the Autodesk discussion groups for a lot of help: Autodesk Discussion Groups
Cheers,
Kris |
|
|||||||||||||||
|
|