Professional Documents
Culture Documents
CP21-2 Learn to make your custom VB or C# .NET commands look and feel just like "regular" AutoCAD. This
class is all about prompts, dialogs, and interaction with the users using the 2007 .NET API. We will
take a detailed look at creating looping command prompts for AutoCAD. You will learn how to present
the user with a choice of geometry and keyword responses, perform various actions depending on the
input, and then repeat the prompt for the next input.
Can the Average User Tell the Difference between Your Commands and AutoCAD’s?
AutoCAD follows standard conventions when interacting with the user. Autodesk has many years
of observation and feedback that has helped in determining how to prompt for user input. Novice
and experienced users alike will expect to be presented with prompts and dialogs in the
conventions that they are accustomed to. You can gain a great advantage in usability for your
application by anticipating what the user will expect when prompted for input while using AutoCAD.
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports DbTransMan = Autodesk.AutoCAD.DatabaseServices.TransactionManager
Imports Autodesk.AutoCAD.Geometry
2
.NET Command School
Anatomy of a Prompt
Prompts in AutoCAD follow a set format:
3
.NET Command School
1. _____________________________________________
2. _____________________________________________
3. _____________________________________________
4. _____________________________________________
Select Case prPtResult.Status
Case PromptStatus.OK 'got expected response
Case PromptStatus.Keyword 'keyword was entered
Case PromptStatus.None 'user pressed ENTER
Case PromptStatus.Cancel 'user cancelled command
Case Else
End Select
4
.NET Command School
The Transaction Manager provides a clean way to access the AutoCAD database and manage the
manipulation of AutoCAD objects in a drawing. The Transaction Manager makes AutoCAD “aware”
of your transaction, makes possible the “Undoing” of your commands, and facilitates safe memory
management.
Use the Transaction Manager in the following sequence:
1. Initialize the Transaction Manager
2. Use the TM to operate on the entity (query, create, modify)
3. Commit the Transaction
Using the Transaction Manager to get the selected object as an Entity type insures that a proper
object will be operated on without crashing the AutoCAD session.
Set form properties as shown below to eliminate confusion and erroneous navigation when
displayed. Modal dialogs should not be minimizable since this would prevent the user from
interacting with AutoCAD.
5
.NET Command School
This dialog is designed to emulate the Pick Point feature on the Block Definition dialog in AutoCAD.
6
.NET Command School
7
.NET Command School
-and-
‘Start command with command line prompts
<CommandMethod("-MYCOMMAND")> Public Function myComand()
<CommandMethod("AUSCHOOL", CommandFlags.Transparent)> _
Public Sub myAuschoolCommand()
In addition to transparent commands, you can limit you application to SDI, only ModelSpace and
more.
8
.NET Command School
9
.NET Command School
10