cp433-4 - managing cad standards with vb.net lee ambrosius – autodesk, inc. sr. technical writer...

24
CP433-4 - Managing CAD Standards with VB.NET Lee Ambrosius – Autodesk, Inc. Sr. Technical Writer – AutoCAD/AutoCAD LT/ AutoCAD for Mac Image courtesy of Hobart, Yaez, Ramos, Maguey, and Martnez

Upload: reynard-lyons

Post on 18-Dec-2015

232 views

Category:

Documents


0 download

TRANSCRIPT

CP433-4 - Managing CAD Standards with VB.NET

Lee Ambrosius – Autodesk, Inc.Sr. Technical Writer – AutoCAD/AutoCAD LT/ AutoCAD for Mac

Image courtesy of Hobart, Yanez, Ramos, Maguey, and Martinez

Where Am I and Who Should Be Here

You are in session:CP433-4 - Managing CAD Standards with VB.NET

You should know or have the following to get the most out of this session: AutoCAD 2011 (or AutoCAD 2007 and later) CAD Standards and/or the Batch Standards Checker Visual Studio and VB.NET

Overview

AutoCAD ships with a COM library that allows you to implement a custom CAD Standards plug-in.

In this session, you will: Learn to define a plug-in Load and use a plug-in Explore the differences between a non-graphical and graphical plug-in

Who Am I?

My name is Lee Ambrosius

AutoCAD user for over 15 years ago; started on R12 DOS Sr. Technical Writer at Autodesk for AutoCAD/AutoCAD

LT/AutoCAD for Mac Author of AutoCAD related books and articles

AutoCAD 2009 and AutoCAD LT 2009 All-in-one Desk Reference for Dummies

AutoCAD 2008 3D Modeling Workbook for Dummies AUGI World and AUGI Hotnews White Papers for Autodesk

Session Rules

A few rules for this session:

Silent your cell phone If you have to leave at anytime, please do so quietly I will allow time to ask questions during the session unless we

start getting behind

Thanks for Your Cooperation

What is Going to be Covered

Learn What is Needed Before Getting Started Create a Basic VB.NET Project for a Plug-in Anatomy or Basics of a Plug-in Load and Use a Plug-in Look at a Graphical Plug-in Debug a Plug-in

What You Need Before Getting Started

ObjectARX Software Development Kit (SDK)

Development Environment Visual Studio .NET 2008 Visual Basic 2008 Express Edition

AutoCAD Managed .NET Developer’s Guide

AutoCAD ActiveX Reference Guide

Windows SDK Only needed if using Visual Basic 2008 Express Edition

What You Need Before Getting Started

After everything is installed, you need to create an Interop Assembly of the CAD Standards Type Library.

1. Display the Visual Studio 2008 Command Prompt2. Type cd "c:\ObjectARX 2011\inc-win32" and press Enter3. Type tlbimp acstmgr.tlb and press Enter

The file AcStMgr.dll will be added to the inc-win32 folder.

This only needs to be done once.

Defining a Plug-in

A CAD Standard plug-in is based on the Class Library template.

1. Create a new project using the Class Library template2. Reference the following libraries from the ObjectARX SDK:

AcStMgr.dll – CAD Standards Manager library Axdb18enu.tlb – AutoCAD ActiveX/COM library

3. Reference the COM library Microsoft XML Type library (Microsoft XML, v6.0) – Used for reporting in the Batch Standards Checker

4. Check Make Assembly COM-Visible under Assembly Information

.

Basics of a CAD Standards API

The IAcStPlugin2 interface is used to implement a CAD Standard plug-in. Implemented methods and properties being in the following categories:

CAD Standard properties Initialization Error iterations; an error being a standards violation Retrieve errors and fixes Fix errors Report errors

CAD Standard properties

Each plug-in must support a standard set of properties that help to identify it from other loaded plug-ins. The properties you must support are:

Author Description HRef Icon Name Version

Initialization

The initialization of the plug-in is the very first thing that happens. A plug-in is initialized during one of the following conditions:

Opening of a drawing with an associated DWS file and the plug-in and real-time checking are enabled

Enabling a plug-in in the CAD Standards dialog box or the Batch Standards Checker

The following methods must be implemented for initialization: Initialize SetupForAudit

Error iterations

Before errors can be fixed, they must be identified and then handled one at a time.

The following methods are used to identify and step through each error in a drawing against a DWS file:

SetContext Start Next Done Clear

Retrieve errors and fixes

After an error has been identified, you then get the opportunity to display all possible fixes and the recommended fix.

The following methods are used to get the current error being looked at, all available fixes, the recommended fix based on the current error, and display the property differences for the error and selected fix:

GetError GetAllFixes GetRecommendedFix GetPropertyDiffs

Fix errors

Once the user has determined the appropriate fix or an automatic fix can be applied, the FixError method is called.

The revised properties need to be assigned to the bad (error) object and the error object needs to be updated corrrectly if the fix was applied.

Report errors

Most reporting is handled by the CAD Standards framework or the Batch Standards Checker.

However, you need to call the WritePluginInfo method to populate the information about your plug-in for the Batch Standards Checker report.

There is also something else what seems to be a limitation of the API. You need to handle writing out the information about the standards you are using to check against the drawing for you plug-in.

Other Methods to Implement

You need to implement the following even though they are not used:

CheckSysvar StampDatabase

Load and Use a Plug-in

After the plug-in has been created and built, you still have some work to do to get AutoCAD to load it.

The Plug-in needs to be registered with: Windows – Using RegAsm.exe AutoCAD – Using a Registry key

Load and Use a Plug-in

Once loaded, you should test your plug-in under the following situations:

CAD Standards checking in AutoCAD Automatic fixes when checking standards in AutoCAD Real-time checking in AutoCAD, notifications Batch Standards Checker

Create a Graphical Plug-in

Fundamentally there is no difference between a non-graphical and graphical CAD Standard plug-in other than how you validate an error and available fixes. The following needs to be changed for each plug-in if starting from the samples:

Change the helper classes StandardsHelp.vb Class name, ProgId, a few of the global variables Description() and Name() properties GetObjectFilter() and SetupForAudit() methods PlugIn_Next() and PlugIn_Clear() methods GetAllFixes()and GetRecommendedFix() methods FixError() method and WriteStandardsItemsInfo() methods

Debugging a Plug-in

A plug-in can be debugged if you are using Visual Studio (VS) 2008, not Visual Basic 2008 Express. Do the following to debug a plug-in in AutoCAD:

1. Add a reference path to the inc-win32 folder in the ObjectARX SDK.

2. Specify the location of AutoCAD so it is started when debugging begins. Add your breakpoints to the code in VS2008.

3. Register the debug version of the DLL built and the plug-in with AutoCAD through the Registry.

4. Add a DWS file to the drawing to be checked and enable the plug-in for checking. Start checking the drawing file.

Final Questions

Questions

Going Once…

Going Twice…

Closing Remarks

Thanks for choosing this session, and do not forget to fill out the evaluation.

If you have any further questions, I will be around for the week and can be reached at:

email: [email protected]: http://twitter.com/leeambrosius

Enjoy the rest of the conference.

Autodesk [and other] are registered trademarks or trademarks of Autodesk, Inc., and/or its subsidiaries and/or affiliates in the USA and/or other countries. All other brand names, product names, or trademarks belong to their respective holders. Autodesk reserves the right to alter product and services offerings, and specifications and pricing at any time without notice, and is not responsible for typographical or graphical errors that may appear in this document. © 2010 Autodesk, Inc. All rights reserved.