About Developing and Implementing CAD Standards Plug-ins (ActiveX/CSP)

Plug-ins are COM servers, which can be created using C++ and ATL, VB6, VB.NET, C#, or any other programming languages that can be compiled into an in-process DLL.

A plug-in must implement the IAcStPlugin2 interface and be registered in the AutoCAD section of the Windows Registry. The properties and methods exposed by the IAcStPlugin2 interface are used by the CAD Standards framework to communicate with a registered plug-in.

The methods and properties of the IAcStPlugin2 interface are used to perform these tasks:

Implement Plug-In Properties

Each plug-in created must support a specific set of properties that are exposed by the IAcStPlugin2 interface. These properties are used to identify the standards that will be enforced by the plug-in and the author of the plug-in. A plug-in must implement the following properties:

Implement Initialization Methods

The initialization of a plug-in happens when it is first loaded into the AutoCAD program or the Batch Standards Checker stand-alone application. A plug-in is initialized based on one of these conditions:

The Initialize method is the entry point for a plug-in. This method is passed a reference to the Standards Manager object of which can be saved for future reference while the plug-in is active. Once a plug-in has been initialized, the SetupForAudit method is executed and is used to setup the drawing to be checked along with which DWS files to use during the checking of standards.

Implement Error Iteration Methods

A plug-in checks for and fixes the errors found in a drawing based on a specified set of established CAD standards. Before an error can be fixed, it must be identified. Each plug-in implements a set of rules to determine the errors in a drawing. Errors can be identified during real-time checking or when the user manually starts the checking process of an entire drawing.

That objects to be checked for errors is passed to the SetContext method as an array. A Boolean value is also passed to the SetContext method to determine whether real-time checking is active; a value of False indicates that real-time checking is active and that only the objects in the array should be checked.

Error checking begins when the Start method is executed by the CAD Standards framework; the first error object that represents the first standards violation in the drawing is passed to the Start method. After the Start method completes execution, the Next method is executed to continue stepping through each error object in the array passed to the SetContext method. After an error has been checked, the Done method is executed to determine whether there are additional errors that need to be fixed. If the Done method returns a Boolean value of False, the Next method is executed and error checking continues.

Implement Error and Fix Retrieval Methods

Prior to fixing an error, the error must be identified and compared against all available fix objects. The current error object is obtained with the GetError method. Once the current error object has been obtained, a list of possible fixes can be obtained with the GetAllFixes method. The fixes that are returned by the GetAllFixes method are those setup initially as part of the SetupForAudit method.

Note: If a plug-in is designed to report errors in a drawing and not fix them, the GetAllFixes method is not required.

The GetAllFixes method expects an error object and two variables; the first variable represents an array of fix objects and the second variable the recommended fix. A recommended fix is used to automatically fix an error. The GetRecommendedFix method is used by the CAD Standards framework to support the automatic fixing of an error. The recommended fix for an error is determined by the plug-in, often by comparing the name of an object or geometric properties. When comparing error and fix objects, a list of property differences can be obtained with the GetPropertyDiffs method.

Implement Error Fixing

After identifying an error and obtaining all available fixes, the FixError method can be used to apply a fix to an error. The FixError method is not required for the development of a plug-in, but is required to support the fixing on an error with the CAD Standards feature in the AutoCAD program. If the FixError method is not defined in a plug-in, a message box is displayed that lets the user know an error cannot be fixed.

Note: The FixError method is not used by the Batch Standards Checker.

When an error is fixed with the FixError method, the plug-in should update the ResultStatus property of the error object based on whether a fix was successful applied by the user. Set the ResultStatus property to AcStMgr.AcStResultStatus.acStResFixed if the error could be fixed or AcStMgr.AcStResultStatus.acStResFixFailed if the error couldn't be fixed. When the uses the CAD Standards feature in the AutoCAD program, an error can be marked as fixed or ignored if the ‘Mark this Problem as Ignored’.

Implement Report Methods

The CAD Standards framework generates a report after checking the standards of objects in a drawing. A report can contain the number of errors found, fixed, and ignored. The presentation of the report varies based on if the CAD Standards feature in the AutoCAD program was used or the Batch Standards Checker.

Check Standards Dialog Box

The Check Standards dialog box, part of the CAD Standards feature in the AutoCAD program, is used to check and fix the standards in a drawing file. After a drawing file has been checked, a message box is displayed. The message box lists the total number of errors found, fixed manually or automatically, and ignored. Your plug-in doesn't need to track the number of errors found, fixed or ignored as that is handled by the CAD Standards framework.

Batch Standards Checker

The Batch Standards Checker generates a report containing the errors found in the drawings checked. The report is saved as part of the CHX file that is created by the Batch Standards Checker. Information about a plug-in can be written to the report with the WritePluginInfo method, while information about an error or fix object can be written to a report using the writeData method.