Monday, August 25, 2014

Create an Application Plugin to automatically load custom content

There are several methods for loading custom content into AutoCAD. In other posts we have looked at partially loading CUI files and deploying a network based AutoCAD profile. Another method that is very streamlined and does not even require a custom profile is to use the ApplicationPlugins folder. Autodesk products automatically look in this location for content and will auto-load it if the content is properly organized. This feature was introduced in AutoCAD 2012 and can be a great way to deploy custom content.
The approach is quite different than other methods of managing custom content but it is very powerful as it is not attached to an AutoCAD user profile.
This post will walk through deploying a custom ribbon tab and command using the ApplicationPlugins folder. We will have all the usual pieces:
  • Some code to define the command
  • A CUI with icon images
Then the new component is an XML file that "bundles" the custom content together and tells AutoCAD how it should be loaded.

The location of the ApplicationPlugins folder is: C:\Program Files\Autodesk\ApplicationPlugins
Notice this is not specific to AutoCAD, Civil 3D, Map 3D, etc or even to a version. This is because all of these Autodesk products look in this location for content to load.

We will organize our content in this folder by first creating a top level folder to store our custom content and allow us to keep it separate from other plug-ins in this location.


The content can be organized in multiple sub-folders within this location. It can be setup to accommodate the custom app, or tools that are being added. For this example I made a few subfolders to store the application file (.dll), the CUI, and the images for the button.

 
 
Notice the PackageContents.xml file. This is what instructs AutoCAD on where the custom content is and ensures everything is loaded properly. Here is the contents of the XML file:

<?xml version="1.0" encoding="utf-8"?>

<ApplicationPackage SchemaVersion="1.0" AutodeskProduct="AutoCAD" ProductType="Application" Name="SLDexample" AppVersion="1.1.0" Description="Example Custom Content" Author="Streamlined Design"
                    AppNameSpace="" OnlineDocumentation=""
                    HelpFile="" Icon=""
                    ProductCode="SLD0001" UpgradeCode="">

  <RuntimeRequirements OS="Win32|Win64" Platform="AutoCAD*|AutoCAD" SeriesMin="R18.2" SeriesMax="R19.1"/>

  <CompanyDetails Name="Streamlined Design" Url="http://streamlined-design.blogspot.com" Email=" " />

  <Components>
    <RuntimeRequirements SupportPath="./Contents/Support" OS="Win32|Win64" Platform="AutoCAD*|AutoCAD" SeriesMin="R18.2" SeriesMax="R19.1"/>

    <ComponentEntry AppName="SLDexample" Version="1.1.0" ModuleName="./Contents/SLDexample.dll" AppDescription="SLD Custom Command" PerDocument="True">

      <Commands>
        <Command Local="SLDappPlugin" Global="SLDappPlugin" Description="Custom Command Using Plugin" />
      </Commands>
    </ComponentEntry>
 
    <ComponentEntry AppName="SLDexample" Version="1.1.0" ModuleName="./Contents/Support/SLDexample.cuix" AppDescription="SLD Tools CUI" />

  </Components>
</ApplicationPackage>

The first part of this file defines the application. There are a few fields that can be left blank and the ProductCode can be a unique identifier.
<ApplicationPackage SchemaVersion="1.0" AutodeskProduct="AutoCAD" ProductType="Application" Name="SLDexample" AppVersion="1.1.0" Description="Example Custom Content" Author="Streamlined Design"
AppNameSpace="" OnlineDocumentation=""
HelpFile="" Icon=""
ProductCode="SLD0001" UpgradeCode="">
 
The <Components> section is where a SupportPath can be defined, this creates a functioning support path while AutoCAD is running. The OS and AutoCAD versions can be specified as well.
<Components>
<RuntimeRequirements SupportPath="./Contents/Support" OS="Win32|Win64" Platform="AutoCAD*|AutoCAD" SeriesMin="R18.2" SeriesMax="R19.1"/>
 
There is a <ComponentEntry> for the application (.dll in this example) as well as for the CUI. Notice each component is pathed to using a relative path location from the folder the XML file is located in. This is represented by the "." in the path.
<ComponentEntry AppName="SLDexample" Version="1.1.0" ModuleName="./Contents/SLDexample.dll" AppDescription="SLD Custom Command" PerDocument="True">
 
Each command defined within the application file (.dll) should be specified. In this example there is only one command: SLDappPlugin. If there were more each one would have its own line:
<Command Local="SLDappPlugin" Global="SLDappPlugin" Description="Custom Command Using Plugin" />
 
After defining the application file and the commands the CUI is defined also as a <ComponentEntry>
Again, a relative path location is used from the XML file to the location of the cui file.
<ComponentEntry AppName="SLDexample" Version="1.1.0" ModuleName="./Contents/Support/SLDexample.cuix" AppDescription="SLD Tools CUI" />
 
With the XML file pointing to the application and cui file it is now ready for AutoCAD to load. There is nothing additional required on the AutoCAD side, simply ensure the bundle folder is directly in the ApplicationPlugins folder mentioned above and then launch AutoCAD.
 
You will notice an information bubble pop-up that confirms the custom application was loaded properly

The CUI elements defined in the CUI should now be available

And the command definition in the .dll will be active

Also, without any additional configuration this plugin is available in Civil 3D since it also auto-loads from the same ApplicationPlugins folder.

 
This opens up a whole new method of managing custom content. Consider an automated method of deploying this content to workstations with a batch file and/or SharePoint.


 

Friday, August 15, 2014

Create and Add Extended Help to a custom AutoCAD Command

The extended help information provided for commands through the CUI can be a very handy way to help users understand the functionality of a command. Several of the AutoCAD provided commands have nice extended help files. For example the Scale command:
 
Just to clarify what extended help is, if you hover over a command in an AutoCAD ribbon you will first see the Tooltip.
  
Hover for a bit longer and the Extended Help will display.
 
The extended help file is managed in an XAML (Extensible Application Markup Language) file. This is very similar to XML in format and can be worked with in a text editor.
Here are some points to make:
  • You can manage just one XAML file for your environment as it is structured to define extended help information for multiple commands.
  • Each command will have its own unique ID (defined in the XAML file) and then linked to the appropriate command using the AutoCAD CUI Editor
  • The XAML file is fairly easy to work with, especially if you are just wanting to add text and images
To create an XAML file you can paste the below structure into a blank file in Notepad (or other text editor) and save as a .XAML file type.
 

<ResourceDictionary
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 xmlns:src="clr-namespace:Autodesk.Windows;assembly=AdWindows">
 
  <src:RibbonToolTip x:Key="SLD_TOOLS_CMD_0001">
    <src:RibbonToolTip.ExpandedContent>
      <StackPanel>
        <TextBlock Background="AntiqueWhite" TextAlignment="Left">
        Shades an area in light blue by single clicking within a closed boundary. 
        </TextBlock>
        <Image Source="images/SLDtool0001.png" Width="Auto" Height="Auto">
        </Image>
      </StackPanel>
    </src:RibbonToolTip.ExpandedContent>
  </src:RibbonToolTip>

</ResourceDictionary>

The ID is important (RibbonToolTip x:Key). This will be used to connect each RibbonToolTip to a Ribbon button in AutoCAD.
Multiple RibbonToolTips can be defined in this single file. Just copy the entire RibbonToolTip section:

<src:RibbonToolTip x:Key="SLD_TOOLS_CMD_0001">
...
</src:RibbonToolTip>


and make sure to use a unique ID. (Note, whether you have 1 or multiple RibbonToolTip definitions they will all be wrapped inside the
<ResourceDictionary...>
...
</ResourceDictionary>

To add this extended help RibbonToolTip to a command in AutoCAD:

Open AutoCAD and the CUI Editor and locate the command that you want to add extended help information to. (Refer to this post on how to create a CUI ribbon element). Click the browse button to locate the XAML file created above.

Once you select the XAML file a dialog box will display showing all of the extended help IDs that are defined in the XAML file. Select the appropriate ID for the command you are working with and click OK.

 
Notice after doing this you will see the XAML file defined in the Extended Help field and the Help ID separated by a ':'

 
Now add the command to a Ribbon Panel (if it is not already) and save the CUI changes. When you hover over the ribbon button you should first see the Description

 
And then the extended help defined by the XAML file.

Using extended help is a streamlined method to provide user documentation to project teams as it does not require browsing to a different location. The functionality of the command can be explained in quite a bit of detail with this additional text and image.