Professional Documents
Culture Documents
NET Plug-ins
James E. Johnson – Synergis Software
CP5239 This class will discuss and illustrate required registry settings for demand-loading a .NET or
ObjectARX® plug-in. We will examine code samples that illustrate how to make an AutoCAD plug-in add
the demand-load registry settings when it is first loaded and how to create a command that removes the
registry settings. We will also discuss the new AutoCAD AutoLoader for automatic loading of ObjectARX
and .NET plug-ins.
Learning
Objectives
At the end of this class, you will be able to:
• Setting demand-load registry settings.
• Manage demand-load registry settings from your code.
• Prepare code and setups required for installers.
• Use the AutoCAD AutoLoader to automatically load plug-ins.
Email: james.e.johnson@me.com
Demand-Loading AutoCAD® .NET Plug-ins
To run you application during development you use the Netload command to run and debug
your application. When deploying a .NET plugin for AutoCAD you would not want your users to
need to run the Netload command to load the plugin every time they need to use it. There have
been several ways to load applications in AutoCAD from acad.lsp to the AutoCAD Appload
contents.
Demand loading the application is the most professional way and lends itself to installers better
than editing files or handling the Appload registry settings.
Demand load settings are stored in one of two places in the registry:
a. HKEY_LOCAL_MACHINE (for all users requires privileges for installers)
b. HKEY_CURRENT_USER (for current user only)
The decision on which will depend on if the application is to be shared across all users but also if using an
installer that the user has privileges to write to HKEY_LOCAL_MACHINE.
HKEY_LOCAL_MACHINE\Software\Autodesk\AutoCAD\R18.2\ACAD-A001:409
2
Demand-Loading AutoCAD® .NET Plug-ins
Under HKEY_LOCAL_MACHINE\Software\Autodesk\AutoCAD\R18.2\ACAD-A001:409\Applications we
add a registry key for our application.
A registry reg file could be created to create this file with the following contents, in the next section we will
look at some code examples to create these settings with code and later with an installer:
3
Demand-Loading AutoCAD® .NET Plug-ins
Creating a sub key under the Application key named commands allows setting up the demand loading to
load the application on command invocation.
In addition to the “Commands” key you can also create a key named “Groups” then add string settings for
any command groups that your application uses.
Note:
In AutoCAD the DEMANDLOAD system variable controls the demand loading options of ObjectARX
applications. The legitimate for the system variable may be used in combination. They are defined as
follows:
0 Disables demand loading of all ObjectARX applications.
1 Enables demand loading of ObjectARX applications upon detection of proxy objects.
2 Enables demand loading of ObjectARX applications upon command invocation.
3 Enables demand loading for both proxy objects and command invocation
4
Demand-Loading AutoCAD® .NET Plug-ins
Commands:
[CommandMethod("LOADGROUP","myPlugLoad",CommandFlags.Session)]
public
void
myPlug()
{
setDemandLoad(true);
}
[CommandMethod("LOADGROUP","myPlugUnLoad",CommandFlags.Session)]
public
void
myUnPlug()
{
setDemandLoad(false);
}
5
Demand-Loading AutoCAD® .NET Plug-ins
The above code example creates two commands one that will create the registry keys and
settings to load the application on command invocation and the other to remove the registry
keys.
6
Demand-Loading AutoCAD® .NET Plug-ins
In Visual Studio Create a new setup project and open the registry editor...
7
Demand-Loading AutoCAD® .NET Plug-ins
The plug-in defined by each package is loaded into AutoCAD by placing it in one of the ApplicationPlugins
folders on your local drive.
There are two different ApplicationPlugins folders that you can use:
When AutoCAD starts, both ApplicationPlugins folders are checked for plug-in applications.
Packages found are automatically registered and loaded based on the metadata in the XML file of each
package.
In AutoCAD a command and a system variable are associated with the plug-in autoloader:
1. APPAUTOLOADER - Command
LIST - displays a list of plugins
Reload - reloads plugins
8 Load plug-in applications when they appear in the plug-ins folder (initial)
With a default setting of 14 plug-ins are automatically registered with AutoCAD and when a new plug-in is
installed during the current session.
When APPAUTOLOAD is set to 0, plug-ins are not loaded unless the APPAUTOLOADER command is
used.
A package can be uninstalled by removing the appropriate folder with a .bundle extension from the
ApplicationPlugins folder. This can be accomplished by offering an uninstall option with the original
installer or to manually delete the .bundle folder.
8
Demand-Loading AutoCAD® .NET Plug-ins
The Package folder contains an XML file named “PackageContents.xml” with metadata that defines the
plug-in.
Sample Of a PackageContents.xml
There are three primary elements in this file ApplicationPackage,CompanyDetails, and Components.
The Components element has two elements RuntimeRequirements and ComponentEntry.
The settings contained in the PackageContents.xml file are used to determine what plug-ins are loaded
when and how they are loaded, setup for specific operating systems and display versioning and
localization names and files.
The following Images and text about the Attributes and Elements in the
PackageContents.xml were pulled from the Autodesk Exchange Online help...
9
Demand-Loading AutoCAD® .NET Plug-ins
ApplicationPackage Attributes
SchemaVersion and AppVersion are REQUIRED
OPTIONAL
local
REQUIRED
for
Autodesk
Exchange
REQUIRED
OPTIONAL
local
REQUIRED
for Autodesk
Exchange
10
Demand-Loading AutoCAD® .NET Plug-ins
CompanyDetails Attributes
All COMPANYDETAILS
are OPTIONAL
Components Element
You can specify as many ComponentEntry elements as needed. Component types can be one of the
following file formats:
• AutoLISP (LSP)
• AutoLISP Fastload (FAS)
• Visual LISP (VLX)
• Managed or Mixed Mode .NET Assembly (.dll)
• ObjectARX (ARX)
• ObjectDBX (DBX)
• Partial Customization (CUIx)
A ComponentEntry element may contain a Commands element if the LoadReasons attribute is set to
LoadOnCommandInvocation.
ComponentEntry Attributes
APPNAME is REQUIRED
APPDESCRIPTION and
APPTYPE are OPTIONAL
12
Demand-Loading AutoCAD® .NET Plug-ins
MODULNAME is REQUIRED
OPTIONAL
13
Demand-Loading AutoCAD® .NET Plug-ins
The Commands element is optional unless the LoadOnCommandInvocation parameter is enabled for the
LoadReasons attribute. Used to specify which commands to register for LoadOnCommandInvocation.
Command Element
Specifies the global and local names for each command.
A Command element can have any of the following attributes attached to it:
14
Demand-Loading AutoCAD® .NET Plug-ins
Using an Installer
Using the Autoloader with an installer is as simple as creating a folder with an extension name of .bundle
and copying files to that folder or sub-folders in either of the ApplicationPlugins folders with a
ProjectContents.xml file to control loading actions. To uninstall the installer needs to delete the folder with
the “.bundle” extension and files/sub-folders contained in the folder.
Sunmmary
Demand loading is well documented in the AutoCAD ObjectArx help documents, in the help document
search on “Creating AutoCAD Subkeys” and “demand loading applications”.
Links:
Kean Walmsley :
http://through-the-interface.typepad.com/through_the_interface/2006/09/automatic_loadi.html
AutoCAD Exchange:
http://exchange.autodesk.com/autocad/enu/online-help/
search#WS73099cc142f4875533992bfb12ce8a5f915-7e45.htm
15