AutoCAD has provided so called AutoLoader for a while. It is announced to be environment friendly (no need to mess up the Windows Registry anymore), support multiple versions, support both AutoCAD and its flavors (such as AutoCAD Mechanical and AutoCAD Architecture) at the same time in a single place, support various AutoCAD applications such as .NET, ARX, DBX, and AutoLISP, support multiple Operating Systems (such as Microsoft Windows 64, Microsoft Windows 32, and even Apple Mac), and more.
It sounds huge and complex, but in fact, it is nothing but an XML file that is supposed to specify what the application/addin/plugin is, what it does, and what it needs. That is about it in a single sentence.
Though simple, it has many subtle details for us to sort out due to lack of good documentation, not open at all the AutoLoader schema if any, and far from set yet at this time. Thus, mysteries about the AutoLoader are here and there in spite that the XML format itself is not a thing at all to most developers.
Many times, we define commands without command groups or local command ids. How to specify such commands in the AutoLoader/ApplicationPackage then?
For example, if the following command is defined in an AutoCAD .NET assembly, e.g. TestApp.dll, how can we make AutoCAD aware of the command and the assembly in an AutoLoader/ApplicationPackage?
[CommandMethod("RootCommand1")]
public void RootCommand1_Method()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = MgdAcApplication.DocumentManager.MdiActiveDocument.Editor;
try
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
//TODO: add your code below.
Debug.WriteLine("RootCommand1 ran.");
ed.WriteMessage("RootCommand1 ran.\n");
tr.Commit();
}
}
catch (System.Exception ex)
{
Debug.WriteLine(ex.ToString());
ed.WriteMessage(ex.ToString());
}
}
Here we go.
<?xml version="1.0" encoding="utf-8"?>
<ApplicationPackage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" HelpFile="./Contents/UsersGuide.chm" OnlineDocumentation="spiderinnet1.typepad.com" Name="NSS" Description="" Icon="./Resources/app.ico" Author="spiderinnet1">
<CompanyDetails Name="NSS" Url="spiderinnet1.typepad.com" Email="spiderinnet1@nss.com" />
<Components>
<RuntimeRequirements OS="Win64" Platform="AutoCAD" SeriesMin="R18.0" SeriesMax="R18.2" />
<ComponentEntry
ModuleName=".\TestApp.dll"
LoadOnAutoCADStartup="true"
LoadOnCommandInvocation="false"
AppDescription=""
AppName="TestApp"
AppType=".NET">
<Commands GroupName="">
<Command Global="RootCommand1" />
</Commands>
</ComponentEntry>
</Components>
</ApplicationPackage>
As can be seen, it can be done through simply providing an empty string to the Commands GroupName attribute and skipping the Local attribute of the Command node.
By the way, the TestApp project and the sample command were all generated by the leading edge AutoCAD .NET Addin Wizard (AcadNetAddinWizard) automatically in a moment. AcadNetAddinWizard provides various project wizards, item wizards, coders including a Ribbon Creator, and widgets to help program AutoCAD .NET addins.
Posted by: |