Objectarx API
Objectarx API
Americas Team
US (CA, AZ, WA), Canada, Brazil
European Team
Switzerland, United Kingdom, France, Russia
APac Team
China, Japan, India
Getting Support
http://www.autodesk.com/adn-devhelp
Provides access to
On-line knowledge base
Call submission
Newsgroups
It is to understand:
The fundamentals of ObjectARX
How to teach yourself AutoCAD APIs
Where to get help with afterwards
What it is not:
Teach you C++, C#, VB, .NET
Give you complete of coverage of all API functions
Class Agenda
Day 1
Overview of APIs
AutoCAD: Hello.arx
Lab : Step 1 + Step 2
Day 2
ObjectDBX: Structure
ObjectDBX: Extend it!
Lab : Step 3 + Step 4 + Step 5 + Step 6
Day 3
AutoCAD: MDE
Notification System
Lab : Step 7
Training Material
Overview of APIs
AutoCAD: Hello.arx
ObjectDBX: Structure
ObjectDBX: Extend it!
AutoCAD: Multi-Document Environment
Notification System
API Overview
In process
Client/server is in the same process
Local
Client/server is on the same machine
Remote
Client/server is on the same network
The Plug-In Architecture
.DLL
.ARX .DLL
.ARX
API APIs
ObjectARX
.EXE
AutoCAD
Forms of Client Code
Interpreted code
SLOW Source script
AutoLISP in the past
AutoCAD.NET
Compiled into IL
Compiled code
FAST Processor instructions
ObjectARX
AutoCAD APIs and IDEs
axdb.dll
AutoCAD
Old API Performance Comparison S.0.58 API Performance
100.00
90.00
80.00
70.00
60.00
Seconds
50.00
40.00
Total
30.00
Create 1000 2dPolylines
20.00
Add XData to 1000 Entities
10.00 Update 1000 Circles
0.00 Create 1000 lines
COM (VB)
COM (VBA)
ObjectARX
Cre
Cre
Upd
140000
120000
Time in seconds
100000 ObjectARX
80000 .NET
60000 LISP
40000 VBA
VB
20000
0
Xrecord Xdata
How to Store Your Data in AutoCAD
Different Programming Techniques
4000
3000 ObjectARX
2000 .NET
VBA
1000 LISP
0
Xrecord Custom
Object
API Comparison Summary
Speed
ObjectARX, .NET is close second, VBA also
though obsolete
Coverage
ObjectARX, .NET everything except custom
objects
Ease of use
.NET, VBA
Learning curve
.NET, VBA
Agenda
Overview of APIs
AutoCAD: Hello.arx
ObjectDBX: Structure
ObjectDBX: Extend it!
AutoCAD: Multi-Document Environment
Notification System
AutoCAD: Hello.arx
ObjectARX
What it is
Where to get it
ObjectARX applications
Structure
Loading
Memory management
Creating commands
Command mechanism
Prompting for user input
ObjectARX Wizards
What is ObjectARX?
A framework?
More than just a toolkit
Specialized objects can be plugged back into the system
Custom entities
Reactors
...
What can I do with ObjectARX?
Download - Free
On Autodesk public web site
Developer Center - ObjectARX
(http://usa.autodesk.com/adsk/servlet/index?id=773204
&siteID=123112)
ObjectARX 2017
AutoCAD 2017
Binary incompatible with earlier releases
ObjectARX 2016
AutoCAD 2016
ObjectARX 2015
AutoCAD 2015 and 2016
Binary incompatible with earlier releases
ObjectARX 2014
AutoCAD 2014
Development Environment
ObjectARX Wizard
ObjectArxWizards.msi downloadable from Developer Center
http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=1911627
acrxEntryPoint
acrxGetApiVersion
.DLL
.ARX .ARX
.DLL
API APIs
ObjectARX
.EXE
AutoCAD
Loading ObjectARX Applications I
Rxapi.lib
AutoCAD 5. 4.
.ARX
1. 6.
2.
Operating System
1. LoadLibrary
2. _DllMainCRTStartup (see MSDN for info)
3. CRT_INIT (constructs global class vars)
4. DllMain (see MSDN for info)
5. acrxGetApiVersion
6. acrxEntryPoint
Wrong ARX Memory Management
AutoCAD/ObjectDBX 3.
MSVCRT.DLL
2. Piece of
CRASH! Memory
.ARX 1. MSVCRTD.DLL
1.
.ARX
.ARX
1.
AcEdCommandStack
3.
4. Callback
2 5. function
AcEdCommand
AutoCAD
1. Add command
AcEd functions
String, number acquisition : acedGetString(), acedGetInt()
Point, angle acquisition : acedGetPoint(), acedGetAngle()
Entity selection : acedEntSel()
Overview of APIs
AutoCAD: Hello.arx
ObjectDBX: Structure
ObjectDBX: Extend it!
AutoCAD: Multi-Document Environment
Notification System
Terminology
AutoCAD Session
Document
Current Document
ObjectARX works with this in background
Active Document
User sees this in UI
Drawing
Database
Working Database
acdbHostApplicationServices()->workingDatabase()
ObjectDBX: Introduction
Set of DLLs
Custom object data services
Extensible application development framework
DWG Viewers
AutoCAD process
.ARX .DBX
Acad.exe &
other AutoCAD ObjectDBX DLLs
specific DLLs
ObjectARX & ObjectDBX
acdb22.lib acad.lib
Acge22.lib acedapi.lib
rcexelib.obj acgiapi.lib acui22.lib
axdb.lib adui22.lib
achapi22.lib oleaprot.lib
rxapi.lib AcTc.lib
acismobj22.lib AcTcUI.lib
rxheap.lib …
…
RealDWG
Shared
What can I do with ObjectARX?
Handle (AcDbHandle)
Unique identifier of an object for the life of the drawing
Object ID (AcDbObjectId)
Unique identifier of an object for a session of ObjectDBX
Multiple drawings allowed per session
IDs unique across ALL files would require too much storage space
(GUIDs)
Pointer
Unique identifier of an object for the duration of a transaction
Handles, Object IDs, Pointers
ObjectDBX session
1.
2.
Object Open New
.dwg Closed AcDbObject AcDbObject
4. 3.
5.
Read
255 simultaneous readers
Write
Open/Close model
1 writer at a time
read/write are mutually exclusive
Transaction model
multiple writers are allowed
read/write are NOT exclusive
Notify
Used internally
Transactions
Two models
Open/Close
acdbOpenObject
AcDbObject::close, AcDbObject::cancel
Transaction
AcDbTransactionManager::startTransaction
AcTransaction::getObject
AcDbTransactionManager::end/abortTransaction
1 2 3 4
Transaction 2 obj2 obj3
obj1 obj3
obj2
AcDbDatabase
Construct one
In memory
classmap.dwg
in ObjectARX distribution
Important Classes
AcRxObject
AcGiDrawable
AcDbObject
AcDbEntity
AcDbCurve
AcDbDictionary AcDbLine
AcDbSymbolTable
AcDbBlockTable
AcDbSymbolTableRecord
Client1 Client2
iterator1 iterator1
Aggregate
AcDbEntity * ent;
if( ent->isKindOf( AcDbLine::desc() ) )
{
AcDbLine * line = AcDbLine::cast( ent );
// do something with line->startPoint() ...
}
AcRxClass I (Overview)
Three roles:
Runtime type identification
Class factory
Protocol extension
Look for Protocol extension in developer’s guide.
Runtime class
An AcDbLine hierarchy An AcRxClass
for
AcDbCurve
Another AcDbLine
An AcRxClass
for
AcDbLine
An AsdkCircle An AcRxClass
for
AcDbCircle
A protocol
extension An AcRxClass
object for
Pseudo AsdkCircle
.DBX/.ARX App constructor
AcRxClass IV (Roles)
Class Factory
During filing we look up the class identifier in the runtime
class hierarchy
AcRxClass provides a ‘constructor’ function
Protocol Extension
AcRxClasses hold a list of ‘extension objects’
Storing Data in the Database
Pointer reference
Arbitrary references between object
Multiple objects can point to the same object
Uni-directional
AcDbDatabase
AcDbDictionary
AcDbBlockTable AcDbLayerTable
Named Object Dict.
AcDbDictionary
AcDbBlockTableRecord AcDbLayerTableRecord
Company Dictionary *
AcDbLine AcDbObject'
AcDbHardOwnershipId AcDbHardPointerId
AcDbSoftOwnershipId AcDbSoftPointerId
Inter-Object References
Save
Follows both types of ownership links
Wblock
Follows hard owner and hard pointer references.
DeepClone
COPY, MIRROR, EXPLODE commands
Follows only ownership links
Purge
Soft references do not protect the object from
purge
Changing an Object’s Identity I
AcDbObject::handOverTo
Replaces an objects in the db with a new one
Objects cannot be removed from the db
You can only flag them as erased
removed
Open New
AcDbObject AcDbObject
AcDbObject::swapIdWith
Changes the object denoted by the object ID
id id
AcDbObject AcDbObject
ObjectDBX Session
Lab - Step 4
Overview of APIs
AutoCAD: Hello.arx
ObjectDBX: Structure
ObjectDBX: Extend it!
AutoCAD: Multi-Document Environment
Notification System
ObjectDBX: Extend It!
Derive from
AcRxObject RTTI protocol
AcGiDrawable + Graphics protocol
AcDbObject + Filing protocol
AcDbEntity + Persistent graphics
AcDbCurve + Curve entities
…
An AcDbDwgFiler 3.
An AcDbObject
1.
2. 3.
Another
AcDbObject
ObjectDBX
2.
An AcDbDwgFiler 4.
An AcDbObject
2.
1.
4.
2.
Another
3.
AcDbObject
ObjectDBX
3.
assertWriteEnabled
Every member function that modifies data
assertNotifyEnabled
Used internally
Proxy
Class ID
Class ID
AcGiGeometry
AcGiGeometry
AcGiWorldDraw AcGiWorldGeometry
AcGiWorldGeometry
AcGiViewportDraw
AcGiViewportDraw AcGiViewportGeometry
AcGiViewportGeometry
AcGiViewport
Legend:
Inheritance
Containment
Graphics Acquisition
4.
An AcGiWorldDraw An AcGiDrawable
6.
1.
3.
5.
Host Application An AcGiViewportDraw
2.
subIntersectWith - no default
subGetGeomExtents - no default
Overview of APIs
AutoCAD: Hello.arx
ObjectDBX: Structure
ObjectDBX: Extend it!
AutoCAD: Multi-Document Environment
Notification System
AutoCAD: Multi-Document Environment
(MDE)
Documents
Per-document data
Current…
for the user = ‘Active’
for the API = ‘Current’
Overview of APIs
AutoCAD: Hello.arx
ObjectDBX: Structure
ObjectDBX: Extend it!
AutoCAD: Multi-Document Environment
Notification System
Notification System
Observer
Subject observers
Attach(Observer) Update()
Detach(Observer)
For all o in observers { SendNotification()
o->Update()
}
ConcreteSubject ConcreteObserver
Update()
subjectState observerState
Notification
Observer pattern interaction diagram
3.
A ConcreteSubject 4. A ConcreteObserver
2. 1.
Client
3.
An AcDbLine 4.
Your custom object
2. 1.
Client
An AcDbDatabase
An AcDbObject An AcDbObjectReactor
Subjects
An AcEdInputPointFilter
The AcEdInputPointManager An AcEdInputPointMonitor
An AcEdInputContextReactor
Blogs
Through the Interface (AutoCAD.NET)
http://through-the-interface.typepad.com/through_the_interface/
AutoCAD DevBlog
http://adndevblog.typepad.com/autocad/