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.adn.autodesk.io
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
.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 production
100.00
90.00
80.00
70.00
Seconds
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
COM (VB)
140000
120000
Time in seconds
100000 ObjectARX
80000 .NET
60000 LISP
40000 VBA
20000 VB
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
https://www.autodesk.com
/developer-network/platform-technologies/autocad
Or Search for ObjectARX on
http://www.autodesk.com/
Binary compatibility
ObjectARX 2022
AutoCAD 2022
Binary incompatible with earlier releases
ObjectARX 2021
AutoCAD 2021
Binary incompatible with earlier releases
ObjectARX 2020
AutoCAD 2020
Binary compatible with earlier releases
ObjectARX 2019
AutoCAD 2019
Binary incompatible with earlier releases
ObjectARX 2018
AutoCAD 2018
Binary incompatible with earlier releases
ObjectARX 2017
AutoCAD 2017
Binary incompatible with earlier releases
ObjectARX 2016
AutoCAD 2016
Development Environment
64-bit versions:
C:\ObjectARX 2023\lib-x64
Main Libraries - II
ObjectARX Wizard
ObjectArxWizards.msi downloadable from Developer Center
https://www.autodesk.com/developer-network/platform-technologies/
Also see Knowledgebase on the ADN website and visit ADN Devblog.
.ARX = .DLL + 2 exported functions
acrxEntryPoint
acrxGetApiVersion
.DLL
.ARX .ARX
.DLL
API APIs
ObjectARX
.EXE
AutoCAD
Loading ObjectARX Applications I
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()
ObjectARX 2021 Wizards
Installer downloadable from Developer Center
Visual Studio ObjectARX wizards
COM Wrapper Wizard
Custom Object Wizard
Reactors Class Wizard
Jig wizard
Dynamic Property Wizard
etc.
Lab - Step 2
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
acdb24.lib acad.lib
acge24.lib acedapi.lib
rcexelib.obj acgiapi.lib acui24.lib
axdb.lib adui24.lib
achapi24.lib oleaprot.lib
rxapi.lib AcTc.lib
acismobj24.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
Stores ‘where
Client1 Client2 we are’
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
…
ObjectDBX and host applications interact with your object through these
interfaces
Filing
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.
+ kIdXlateFiler
Wblock kWblockCloneFiler
+
kIdXlateFiler
Object paging kPageFiler
Filing Member Functions - II
AutoCAD calls the dwgOut which in turn calls your dwgOutFields
function on:
Save/SaveAs kFileFiler
Wblock kWblockCloneFiler +
kIdXlateFiler
Insert, Xref kDeepCloneFiler +
kIdXlateFiler
Copy same as Insert
(files out object’s state and files it into another object)
Purge kPurgeFiler
Object paging kPageFiler
Any Object modification kUndoFiler
for undo recording
Filing Member Functions - III
AutoCAD calls dxfOut which calls your dxfOutFields function
on:
WBLOCK kFileFiler
SAVE kFileFiler
SAVEAS kFileFiler
acdbEntGet kBagFiler
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.
co g
rre on
ct w r
AcGiSubEntityTraits
Traits control current attributes for primitives:
color, layer, linetype, filltype
graphics system (GS) marker
Allows identification of sub-entities
Once set, a trait stays active until changed or out of scope
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) 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
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/