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
Lectures:
Overview of APIs
AutoCAD: Hello.arx Step 1 + 2
ObjectDBX: Structure Step 3 + 4
ObjectDBX: Extend it! Step 5 + 6
AutoCAD: Multi-Document Environment
Notification System Step 7
Class Schedule
Time : 9:30 AM - 5:30 PM
Lunch 12:00 PM - 1:00 PM
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
. ..DLL
ARX ARX
API
ObjectARX
APIs
.EXE
AutoCAD
Forms of Client Code
Interpreted code
SLO Source script
W AutoLISP in the past
AutoCAD.NET
Compiled into IL
axdb.dll
AutoCAD
Old API Performance Comparison
S.0.58 production
100.00
90.00
80.00
70.00
S econds
60.00
Machine prof ile:
50.00 CPU: Pentium 150 MHz
RAM: 64 MB
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
C O M (V B )
C O M (V B A )
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 2015
AutoCAD 2015 and 2016
Binary incompatible with earlier releases
ObjectARX 2014
AutoCAD 2014
ObjectARX 2013
AutoCAD 2013 and 2014
Binary incompatible with earlier releases
ObjectARX 2012
AutoCAD 2012
ObjectARX 2011
AutoCAD 2011 and 2012
Development Environment
ObjectARX Wizard
ArxWizards.msi downloadable from Developer Center
http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=
1911627
acrxEntryPoint
acrxGetApiVersion
.DLL
. ..DLL
ARX ARX
API
ObjectARX
APIs
.EXE
AutoCAD
Loading ObjectARX Applications I
Demand loaded
Startup
Registry
(arxload) in acad2015doc.lsp
On command invocation
Registry
On request
From another application
On proxy detection
Registry
Loading ObjectARX Applications
II
3.
Rxapi.lib
AutoCAD 5. 4.
CRT
.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
ObjectDBX ObjectARX
SDK
acdb20.lib acad.lib
Acge20.lib acedapi.li
rcexelib.obj acgiapi.lib b
axdb.lib acui20.lib
achapi20.lib adui20.lib
rxapi.lib oleaprot.li
b
acismobj20.li AcTc.lib
b
rxheap.lib AcTcUI.lib
RealDWG
Share
d
What can I do with ObjectARX?
Objects canmodel
Relational encapsulate data
Object model
Tables Objects
Records Objects
Fields Data members (encapsulated)
Object Identity
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
AcDbDatabas
e
1. Client starts Trans1 and gets Obj1 & Obj2
2. Client starts Trans2 and gets Obj2 & Obj3
3. Client commits Trans2
Trans2 changes are committed
4a. Client commits Trans1
Trans1 changes are committed
4b. Client aborts Trans1 instead
Trans1 (and Trans2) changes are rolled back
Getting an AcDbDatabase Object
Construct one
In memory
classmap.dwg
in ObjectARX distribution
Important Classes
AcRxObject
AcGiDrawable
AcDbObject
AcDbEntity
AcDbCurve
AcDbDictionary AcDbLine
AcDbSymbolTable
AcDbBlockTable
AcDbSymbolTableRecord
Stores where
Client1 Client2 we a re
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 developers 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
.DBX/.ARX construct AsdkCircle
App or
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 Objects 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.
3.
2.
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
Acting as an Observer
Acting as a Subject
Notification
Observer pattern class diagram
Observer
Subject observers
Attach(Observer)
Detach(Observer Update()
)
For all o in observers { SendNotification(
o->Update() )
}
ConcreteSubje ConcreteObserver
ct 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
Instantiate it
Attach it to subject
Remove it when done
At least when application is unloaded
Acting as a Subject
AutoCAD DevBlog
http://adndevblog.typepad.com/autocad/