Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
CP115-1
Learn to make your custom Visual Basic (VB) or C# .NET commands look and feel just like
AutoCAD. Create command prompts and LISP functions. 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.
Anatomy of a Prompt
Prompts in AutoCAD follow a set format:
2.
Getting the<default> to
come at the end of the
prompt
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
Entity Prompting and Responding
GetEntity will return an ObjectID (Try/Catch blocks have been omitted for clarity):
Dim prEntOpts As New PromptEntityOptions("Pick an object: ")
Dim prEntResult As PromptEntityResult
prEntResult = ed.GetEntity(prEntOpts)
If prEntResult.Status <> PromptStatus.Error Then
Dim entid As ObjectId = prEntResult.ObjectId
Dim db As Database =
Application.DocumentManager.MdiActiveDocument.Database
Dim tm As _
Autodesk.AutoCAD.DatabaseServices.TransactionManager =
db.TransactionManager
Dim myT As Transaction = tm.StartTransaction()
Dim entity As _
Entity = CType(tm.GetObject(entid, OpenMode.ForRead, True), Entity)
ed.WriteMessage("You selected: " + entity.GetType().FullName)
myT.Commit()
End If
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.
This dialog is designed to emulate the Pick Point feature on the Block Definition dialog in
AutoCAD.
In addition to transparent commands, you can limit you application to SDI, only ModelSpace
and more.
02
03
04
05
06
[HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R17.1\ACAD-6001:409\Applications\AUNetLoad]
"DESCRIPTION"="AU 2008 Demandload Example"
"LOADER"="C:\\Program Files\\AU2007\\ComSchool.dll"
"LOADCTRLS"=dword:00000002
"MANAGED"=dword:00000001
07
[HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R17.1\
ACAD-6001:409\Applications\AUNetLoad\Commands]
"AUNetLoad"="AUText"
08
09
10
[HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R17.1\
ACAD-6001:409\Applications\AUNetLoad\Groups]
"AUNetMan"="AUNetMan"
Line 02: The last item AUNetLoad is a unique name for your application.
Line 03: Any Description for the assembly.
Line 04: The actual location of the assembly.
Line 05: Double word value of loadreasons. Here is a table of possible loadreasons from
the AutoCAD Managed Class Reference:
LoadReasons
Name
kOnProxyDetection
Value
0x01
kOnAutoCADStartup
0x02
kOnCommandInvocation
0x04
kOnLoadRequest
0x08
kLoadDisabled
0x10
kTransparentlyLoadable 0x20
Description
Load the ObjectARX application when objects of custom classes it
controls are loaded via drawing open, dxfin, insert, and so on
Load the ObjectARX application when AutoCAD starts up
Load the ObjectARX application whenever an unknown command is executed
for which it has a registry entry
Allow loading of the ObjectARX application via the
AcRxDynamicLinker::loadApp() method
Do not demand load the ObjectARX application for any reason
Load the ObjectARX application transparently
We are using 0x02 in this example to load the application when AutoCAD starts. 0x0e is
also very common. It uses 0x01 + 0x02 + 0x04 + 0x08.
Line 06: A double word declaring that this is a managed .NET assembly.
This should always be 1.
Line 07: Specifies a subkey for defining commands.
Line 08: Specifies the command name in the class. String1 is the global command, String
2 is the local command. You can add as many commands as are in your assembly.
Lines 09 & 10: Specify the command group name in the module.
=
=
=
=
=
=
=
=
=
=
=
=
=
=
AutoCAD
Map
Mechanical Desktop for AIS
Architectural Desktop
AutoCAD Mechanical
Building Systems
AutoCAD Electrical
Land Desktop
AutoCAD LT
AutoCAD OEM
Mechanical Desktop for AIP
Autodesk Utility Design
Autodesk Civil 3D
Architectural Desktop w/Raster Design
The localid for English is 409. Other languages are indicated by other localid numbers. All
localids for AutoCAD start with the number 4. English is 409, German is 407, Chinese is
404, and so on. You can find a complete list on Microsofts MSDN website at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/nls_61df.asp
Creating an install
There are many tools available for creating installation of your program. The three most
important things you will have to accomplish in your install are:
1. Installing the files
2. Setting the registry keys for demandloading the application
3. Providing a way to uninstall the application.
A very simple install to meet all three needs is available in Visual Studio. We will use the VS
Setup and Deployment module as an example.
Create the installation project
Create a new deployment project by selecting File>New>Project. Then select Setup Project.
Then modify the Project Properties:
Visual Studio will automatically create the dependency files for the installation.