Developer Technical Services
Developer Technical Services
NET API
Developer Technical Services
Developer Technical Services
Worldwide Workgroup
Over 25 Specialists World Wide
Virtually 24 hour support, 5 days a week
Americas Team
US (CA, AZ, WA), Canada, Brazil
European Team
Switzerland, United Kingdom, France, Russia
APac Team
China, Japan, India
Getting Support
http://www.adn.autodesk.io
Provides access to
On-line knowledge base
Call submission
Newsgroups
What it is not:
Teach you .NET framework or C# , VB programming language
Give you complete coverage of all API functions
Class Agenda
Lectures with Labs
Slides give an abstract overview
Labs and discussion give a practical perspective
Lectures
Overview of .NET.
AutoCAD .NET Visual Studio project settings – Hello World!
User Interaction - User Input and Entity Selection
Database Fundamentals – Symbol tables, Transactions
User Interface design – Win Form Dialogs and Palettes
Event handling – Reacting to AutoCAD Events in .NET. Database
Dictionaries, XRecords, Table Traversal
Point Monitor
Jigs
Additional User Interface Elements (Non CUI related)
Class Schedule
Day 1
Overview of .NET
Visual Studio Project Settings – Lab 1
User Input – Lab 2
Creating Entity, Block definition and Block References – Lab 3
UI Design – Win form Dialogs, Palettes and Event Handling – Lab 4
Day 2
Dictionaries – Lab 5
Point Monitor – Lab 6
Jigs - Lab 7
Non-CUI related UI elements – Lab 8
.NET Overview
What is .NET?
Important Concepts
.NET Overview
What is .NET?
Components of .NET
The .NET Framework used for building and running all kinds of
software, including Web-based applications, smart client applications,
and XML Web Services
Developer tools such as Microsoft Visual Studio 2010 / 2012 ,2015,
2017 and 2019 (latest)
A set of servers that integrate, run, operate, and manage Web
services and Web-based applications
Client software that helps developers deliver a deep and compelling
user experience across a family of devices and existing products.
.NET Framework
VB C++ C# JScript …
NET Framework
Common Language Runtime (CLR)
Object-Oriented programming environment
Common execution environment for .NET applications
-Similar to Java VM – but with much stronger interoperability
(Source: MSDN)
.NET Overview
CLR Execution Model
Source code
VB C# C++
JIT Compiler
Native Code
Programming style
Multiple supported languages – Choose your weapons
.NET Overview
What is .NET?
Important Concepts
.NET Overview
Benefits of programming in .NET
(Source: MSDN)
.NET Overview
Consistent Object Oriented Development platform
Everything you see can be treated as an Object!
Dim myLine As New Line()
myLine.StartPoint = New Point3d(0, 0, 0)
myLine.EndPoint = New Point3d(10, 10, 0)
myLine.GetClosestPointTo(New Point3d(5, 5.1, 0), False)
Dim x as Interger = 7
Dim s as String = x.ToString()
(Source: MSDN)
.NET Overview
char *pName=(char*)malloc(128);
strcpy(pName,"Hello");
//...
free(pName);
New Way - .NET
New – VB .NET
Try
Dim x As Double=10/0 ‘…error which throws exception
Catch
‘…what happened? Division by Zero!
Finally
‘…cleanup - do this either way
End Try
.NET Overview
What is .NET?
Important Concepts
.NET Overview
Important Concepts
Assembly
Assemblies
•Contains a manifest that describes the What files make up the assembly?
assembly Dependent assemblies?
(Source: MSDN)
Class Agenda
Lectures and Labs
Overview of .NET.
AutoCAD .NET Visual Studio project settings – Hello World!
User Interaction - Simple User Input and Entity Selection
Database Fundamentals – Symbol tables, Transactions
Database Fundamentals – Dictionaries, XRecords, Table
Traversal
More User Interaction – Advanced Prompts
User Interface design - WinForm Dialogs and Palettes
Event handling – Reacting to AutoCAD Events in .NET.
AutoCAD .NET API Documentation
How do I get started?
ADN website
DevNotes
DevHelp Online
AutoCAD 2023
Microsoft Windows 8
Microsoft Windows 7
Microsoft Windows 10
.NET Debugging Tools
Reflector
Browse .NET assemblies,
disassemble, decompile
http://sharptoolbox.madgeek.com
Ildasm
Disassemble .NET assemblies
Visual Studio Tools
Fuslogv
Diagnose load time problems
Visual Studio Tools
FxCop
Check conformance with Design
Snoop Tools (for AutoCAD’s database)
MgdDbg(C#) ADN
Visual Studio project settings– Hello World!
Reference to AutoCAD
DLLs. Use it from
Code witten in ObjectARX INC folder
Visual Basic .NET
Project VB.NET
Compile
<CommandMethod("HelloWorld")>
_
Public Function HelloWorld()
End Function
End Class
The attribute is added to the metadata for that function
Visual Studio project settings– Hello World!
Dim ed As Editor =
Application.DocumentManager.MdiActiveDocument.Editor
<CommandMethod("HelloWorld")>
_
Public Function HelloWorld()
ed.WriteMessage("Hello
Loading .NET assembly
NETLOAD command
AUTOLOADER
Startup
On command invocation
Demand Load (Registry)
Startup
On command invocation
On request
From another application
On proxy detection
[HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R23.1\ACAD-2001\Applications\AcLayer]
"DESCRIPTION"="AutoCAD Layer Manager"
"LOADER"="C:\\Program Files\\AutoCAD 2020\\aclayer.dll"
"LOADCTRLS"=dword:0000000e
"MANAGED"=dword:00000001
[HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R2310\ACAD-2001\Applications\AcLayer\
Commands]
"LAYER"="LAYER“
[HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R23.1\ACAD-2001\Applications\AcLayer\Groups]
"ACLAYER_CMDS"="ACLAYER_CMDS“
SOFTWARE
R19.0: 2013
.1: 2014
Autodesk R20.0: 2015
R20.1:2016
AutoCAD R21.0:2017
R22.0:2018
R23.0:2019
R23.0 409: English
R23.1:2020
X000: Civil3D 416: Portuguese
ACAD-2001 X001: AutoCAD 040A: Spanish
"DESCRIPTION"="Custom App Name"
Applications
"LOADER"="C:\\folder\\appName.dll"
"LOADCTRLS"=dword:0000000e
YourAppName "MANAGED"=dword:00000001
Lab 1 – Hello World!
Class Agenda
Lectures and Labs
Overview of .NET.
AutoCAD .NET Visual Studio project settings – Hello World!
User Interaction - User Input and Entity Selection
Database Fundamentals – Symbol tables, Transactions
User Interface design – Win Form Dialogs and Palettes
Event handling – Reacting to AutoCAD Events in .NET. Database
Dictionaries, XRecords, Table Traversal
Point Monitor
Jigs
Additional User Interface Elements
Prompting for User Input
Ask the user to select the point and store the selection
result
ed.WriteMessage(selectedPoint.ToString())
More User Interaction
PromptsXXXOptions is used to control prompting such as
Set Keywords
Enter Number of Sides [Triangle/Square/Pentagon] :
Set Defaults
Enter Number of Sides [Triangle/Square/Pentagon] <3>:
Overview of .NET.
AutoCAD .NET Visual Studio project settings – Hello World!
User Interaction - User Input and Entity Selection
Database Fundamentals – Symbol tables, Transactions
User Interface design – Win Form Dialogs and Palettes
Event handling – Reacting to AutoCAD Events in .NET. Database
Dictionaries, XRecords, Table Traversal
Point Monitor
Jigs
Additional User Interface Elements
AutoCAD Drawing Database
In-Memory representation of the Dwg File
Objects are stored hierarchically in the database - Db Structure
All objects have identities – ObjectId, like Primary Key in a relational
database
Objects are always accessed in a transaction
The transaction defines the boundary of database operations
Objects have to be opened first in a transaction before they can be used
DWG
Database Structure: Overview
Database
Construct One
In Memory
Transactions
Sets the boundary for database operations
Can be
committed – All database
operations are saved
rolled back – All database
operations are aborted
Can be nested
Nesting Transactions
1 2 3 4
Transaction 2 obj2 obj3
obj1 obj3
obj2
Database
Use Add method for adding Symbol Table Records to add to Symbol
Table
Use AppendXXX to add add other kinds of objects to its owners For
example
AppendEntity to add to BlockTableRecord
'open the current space (can be any BTR, usually model space)
Dim mSpace As BlockTableRecord = trans.GetObject(db.CurrentSpaceId, _
OpenMode.ForWrite)
'Create and configure a new line Open the current space for write.
Dim newLine As New Line Can be any other BTR.
newLine.StartPoint = New Point3d(0, 0, 0)
newLine.EndPoint = New Point3d(10, 10, 0) Create and configure a new
line (in-memory)
'Append to model space Append to the current space, now the
mSpace.AppendEntity(newLine) line it is database resident
'Inform the transaction
trans.AddNewlyCreatedDBObject(newLine, True)
trans.commit()
End Using 'Dispose the transaction
Object memory management
Namespace System.Windows.Forms
Main features
Forms
Controls for forms (button, textbox, combobox)
Ready to use forms (dialogs to open, save, folder)
Others (menus, ribbon, tooltip)
Creating my first Form
Properties
Do something when the user click!
Select “Events”
TIP
User Interface Design
AutoCAD Defined
Menus – Application level menu, Context menu
Dialogs
AutoCAD’s Enhanced Secondary Windows ( Palettes )
Color, Linetype, Lineweight, OpenFile dialogs
Tabbed Dialog Extensions (to Options Dialog)
Status Bar
Tray
Drag-Drop
And more. Explore Autodesk.AutoCAD.Windows namespace
Windows Defined
Windows Forms (Winform)
Host of other controls defined in CLR
Using a form inside AutoCAD
Modal forms
Application.ShowModalDialog
Create a PaletteSet
Delegates
Like a class (can be instantiated) but with a signature
Holds references to functions having same signature
Like ‘Type-Safe’ function pointer
Can encapsulate any method which matches the specific signature
Using Delegates
Delegates in AutoCAD’s .NET API usually have ‘EventHandler’ suffix
Lookup the signature of the delegate in the object browser
myFunction(delegate signature)
{
}
‘Don’t forget to remove the listener!
Event Handling - Example
Create the event handler (callback)
Sub objAppended(ByVal o As Object, ByVal e As ObjectEventArgs)
MessageBox.Show("ObjectAppended!")
‘Do something here
‘Do something else, etc.
End Sub
Data containers
Dim db = HostApplicationServices.WorkingDatabase
myEntity.CreateExtensionDictionary()
Dictionary Hierarchy
Extension Dictionary
DBDictionary
One DBDictionary can contain others.
Good to organize the structure.
SetAt GetAt DBDictionary
Also avoid conflict with other apps.
Symbol Tables
Block Table Records
Dictionaries
Polylines
PolyFaceMesh & PolygonMesh
ACIS Solids
Called traversers
BlockReferences (Inserts)
Only useful when attributes are present
Symbol Table Traversal
Start with a database pointer
HostApplicationServices.WorkingDatabase – Get used to this one!
Dim id As ObjectId
For Each id In bt
Dim btr As BlockTableRecord = trans.GetObject(id, OpenMode.ForRead)
Next
Lab 5
Provides relevant data to the input received – Osnap, Draw context, various
computed points, Entities underneath aperture etc.
AppendToolTipText
Context
GetPickedEntities
FullSubentityPath
DrawContext
Geometry.Draw
Lab 6
PointMonitor
Class Agenda
Sampler
Used to get input from the user
Update
Used to update the entity that is being jigged.
Jig Function - Sampler
Returns SamplerStatus
NoChange
OK
Jig Function - Update
Jigs
Class Agenda
Application Level
Application.AddDefaultContextMenuExtension
Object Level
Application. AddObjectContextMenuExtension –per
RXClass
Tabbed Dialog Extensions
Create a new tab inside Options dialog
Handle MouseMove
Call Application.DoDragDrop
AutoCAD DevBlog
http://adndevblog.typepad.com/autocad/
Developer Center : http://www.autodesk.com/developautocad
API Training Classes : www.autodesk.com/apitraining