Dokumen - Tips Objectarx

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 135

7/29/2019 ObjectARX

ObjectARX 2010
and
AutoCAD .NET
http://slidepdf.com/reader/full/objectarx
Autodesk Developer Technical Services 1/135
7/29/2019 ObjectARX

Getting Acquainted

Instructor: Marat Mirgaleev (Марат Миргалеев)


Developer Consultant ADN
 Mechanics Engineering + Computer Science
 20 years in software development (CAD, 3D,
Databases)
 C++, C#, Delphi, Assembler; Object-Oriented
Analysis and Design

Who Are You?


 Your work, your software
 AutoCAD customization experience
 Your company
 What are you expecting from this training?

© 2008 Autodesk
http://slidepdf.com/reader/full/objectarx 2/135
7/29/2019 ObjectARX

Autodesk Developer Network (ADN)

 Access to almost all Autodesk software and SDK‟s


 Including early access to Beta software
 Members-only website with 1000s of technical articles
 Unlimited technical support
 Product direction through conferences
 Marketing benefits
 Exposure on autodesk.com
 Promotional opportunities

1 to 3 free API training classes
 Based on user level

www.autodesk.com/joinadn

© 2008 Autodesk
http://slidepdf.com/reader/full/objectarx 3/135
7/29/2019 ObjectARX

Developer Technical Services

Worldwide Workgroup
 Over 25 Specialists World Wide
 Virtually 24 hour support, 5 days a week

Americas Team
 CA, WA, São Paulo

European Team
 Switzerland, United Kingdom, France, Czech Republic, Russia

APac Team
 China, Japan, India

© 2008 Autodesk
http://slidepdf.com/reader/full/objectarx 4/135
7/29/2019 ObjectARX

Getting Support

http://www.autodesk.com/adn-devhelp
 Provides access to

 On-line knowledgebase
 Request submission
 Newsgroups
 Requests are logged automatically
 1-3 day turnaround
 Callbacks as needed

 Answers to frequently asked questions are posted in our on-


line knowledge base

© 2008 Autodesk
http://slidepdf.com/reader/full/objectarx 5/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 6/135
7/29/2019 ObjectARX

Class Agenda

Lectures with Labs


 Slides give an abstract overview

 Labs and my comments give the practical experience

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

 AutoCAD .NET

© 2008 Autodesk
http://slidepdf.com/reader/full/objectarx 7/135
7/29/2019 ObjectARX

Class Schedule

Time 10:00 - 5:00


 Lunch 12:00 - 1:00

Day 1
 Overview of APIs

 AutoCAD: Hello.arx

Day 2
 ObjectDBX: Structure

 ObjectDBX: Extend it!

Day 3
 AutoCAD: MDE Environment

 Notification System

Day 3, Day 4
 AutoCAD .NET

© 2008 Autodesk
http://slidepdf.com/reader/full/objectarx 8/135
7/29/2019 ObjectARX

Training Material

C:\AutoCAD API Training


 ObjectARX*.pptx - this presentation
 AutoCAD.NET*.pptx - .NET API presentation
 objectarx_2010_win_64_and_32bit.exe - ObjectARX installation file

 objectarx_2010_training.zip - ObjectARX labs


 AutoCAD 2010.Net Training.zip - .NET labs
 Inspector.zip - ObjectARX snoop tool

© 2008 Autodesk
http://slidepdf.com/reader/full/objectarx 9/135
7/29/2019 ObjectARX

Agenda

Overview of APIs
AutoCAD: Hello.arx
ObjectDBX: Structure

ObjectDBX: Extend it!


AutoCAD: Multi-Document Environment
Notification System

© 2008 Autodesk
http://slidepdf.com/reader/full/objectarx 10/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 11/135
7/29/2019 ObjectARX

What is an API?

A contract, it is about responsibilities


 Both sides are (or may be) required to

 Implement service entry points


 Call services properly

Code implementing API can be packaged as


 Source code modules (.h/.cpp in C++)

 Binary

 Static library
 DLL
 EXE

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 12/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 13/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 14/135
7/29/2019 ObjectARX

The Plug-In Architecture

API is implemented by an exe


Client is implemented as a dll

.DLL
.ARX .ARX
.DLL

API APIs
ObjectARX

.EXE
AutoCAD

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 15/135
7/29/2019 ObjectARX

Forms of Client Code

SLOW Interpreted code


 Source script
 AutoLISP in the past
Packaged code (p-code)
 Pre-processed, semi interpreted code
 Compiled Visual LISP
AutoCAD.NET
 Compiled into IL
Compiled code
 Processor instructions
 ObjectARX
FAST

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 16/135
7/29/2019 ObjectARX

AutoCAD APIs and IDEs

Application Programming Interfaces


 ObjectARX
 .NET Managed API
 COM Automation (VB, Java, Delphi, etc.)

AutoLISP

Integrated Development Environments in AutoCAD


 Visual LISP
 Visual Basic, Applications Edition (VBA)

(Visual Studio outside AutoCAD)

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 17/135
7/29/2019 ObjectARX

API Implementation I
t r
u
p v
e
ir Input acquisition
n
I d

AutoCAD
r I
e r D 2D graphics
tt e
v
ir H
t cache
o
l o
P d l
P (WHIP!)

y r I
a
l e D 3D graphics
p v I ObjectDBX
s ir E
i d cache
D H

 ObjectARX SDK (free, http://www.autodesk.com/objectarx)


 RealDWG (licensed, http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=770257 ) dwg
 Plot DDK (licensed, http://www.autodesk.com/adn-devhelp)
 HEIDI DDK (licensed, http://www.autodesk.com/heidi)
 Wintab API (free)

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 18/135
7/29/2019 ObjectARX

API Implementation II

.NET Lisp
script VBA
script COM Client
(VB, Java, Delphi)
Acdbmgd.dll
Acmgd.dll vl.arx acvba.arx

axdb.dll

ObjectARX APIs COM


AutoCAD

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 19/135
7/29/2019 ObjectARX

Old API Performance Comparison

100.00

90.00

80.00

70.00

s
d
60.00
n
o 50.00
c
e
S 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
)
B )
V
( A Create 1000 Circles
B P
M V
( S
I X
O L R
C M A
O t
c
C e
j
b
O
AutoCAD's APIs

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 20/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 21/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 22/135
7/29/2019 ObjectARX

How to Store Your Data in AutoCAD


Different Programming Techniques

Data Container Performance Chart

5000
s
d 4000
n
o
c
e 3000 ObjectARX
s
n
i .NET
e
2000
m VBA
i
T 1000 LISP
0
Xrecord Custom
Object

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 23/135
7/29/2019 ObjectARX

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

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 24/135
7/29/2019 ObjectARX

Agenda

Overview of APIs
AutoCAD: Hello.arx
ObjectDBX: Structure

ObjectDBX: Extend it!


AutoCAD: Multi-Document Environment
Notification System

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 25/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 26/135
7/29/2019 ObjectARX

What is ObjectARX?

AutoCAD Runtime eXtension


 A DLL plug-in model
 A set of Object Oriented C++ libraries
 A framework

A framework?
 More than just a toolkit
 Specialized objects can be plugged back into the system
 Custom entities
 Reactors
 ...

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 27/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 28/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 29/135
7/29/2019 ObjectARX

Binary compatibility

ObjectARX 2010
 AutoCAD 2010
 Binary incompatible with earlier releases

ObjectARX 2009

AutoCAD 2009
ObjectARX 2008
 AutoCAD 2008 and 2009

ObjectARX 2007

AutoCAD 2007, 2008 and 2009
 Binary incompatible with earlier releases

ObjectARX 2006, 2005, 2004…


 Not supported, as well as AutoCAD versions older than 2007

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 30/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 31/135
7/29/2019 ObjectARX

ObjectARX SDK Contents

What comes with the SDK


 Libraries and Header Files
 Documentation
 Samples
 Utilities

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 32/135
7/29/2019 ObjectARX

Main Libraries - I

AcRx Object and Class Management (rxapi.lib)


AcEd AutoCAD Editor Facilities (acedapi.lib)
AcDb AutoCAD Database (acdb18.lib)
AcGi AutoCAD Graphics Interface (acgiapi.lib)
AcGe AutoCAD Geometry Library (acge18.lib)

32- and 64-bit versions:


\ObjectARX 2010\lib-win32 and
\ObjectARX 2010\lib-x64

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 33/135
7/29/2019 ObjectARX

Main Libraries - II

AcUi/AdUi MFC Extension Library (adui18.lib acui18.lib)


Automation (axdb.lib oleaprot.lib)
ads_ Function Set (acad.lib)

Static Linking Memory Management (rxheap.lib)

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 34/135
7/29/2019 ObjectARX

Utilities

AutoCAD Facet Modeler (aecmodeler60.lib)

AutoCAD Boundary Representation (acbr18.lib, acgex19.lib)

ObjectARX Wizard
(<your path>\ObjectARX 2010\utils\ObjARXWiz\ArxWizards.msi)

ATIL - Raster graphics

Teefy - Converting existing applications to Unicode string handling

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 35/135
7/29/2019 ObjectARX

On-line Documentation

Found in ObjectARX\docs
 ObjectARX Documentation (arxdoc.chm)
 ObjectARX Developers Guide (arxdev.chm)
 Reference Manual (arxref.chm)
 Managed Class Reference Guide (arxmgd.chm)
 ObjectARX 2010 Migration Guide (arxxmg.chm)
 64-bit Migration Guide (arxmgr.chm)
 Interoperability Guide (arxiop.chm)
 ObjectARX Readme (readarx.chm)

ObjectARX Training Material and Labs


(can be found on the Autodesk site)

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 36/135
7/29/2019 ObjectARX

Samples

The ObjectARX SDK comes with a number of code samples


organized into sub-categories:
 ObjectARX\Samples
 COM
 Database


DotNet
Editor
 Entity
 Graphics
 Misc
 Reactors
 PolySamp and ArxDbg

Also see Knowledgebase on the ADN website.

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 37/135
7/29/2019 ObjectARX

.ARX = .DLL + 2 exported functions

 acrxEntryPoint
 acrxGetApiVersion

.DLL
.ARX .ARX
.DLL

API APIs
ObjectARX

.EXE
AutoCAD

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 38/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 39/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 40/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 41/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 42/135
7/29/2019 ObjectARX

Correct ARX Memory Management II


2.

AutoCAD/ObjectDBX 4. MSVCRT.DLL
Piece of
1. 3. Memory

Rxheap.lib ib
l
.t
.ARX m
c
b
i
L

1. .ARX allocates memory via rxheap.lib


2. AutoCAD allocates memory on release heap
3. .ARX passes memory to AutoCAD
4. AutoCAD de-allocates it with release „delete‟…  OK

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 43/135
7/29/2019 ObjectARX

Getting Started

Visual C++ 9.0 (.NET)


AutoCAD 2010
ObjectARX 2010

ArxDbg \ObjectARX 2010\samples\database\ARXDBG

Dependency Walker www.dependencywalker.com or


C:\Program Files\Microsoft Visual Studio 9\Common7\Tools\bin\depends.exe

Process Monitor www.sysinternals.com

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 44/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 45/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 46/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 47/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 48/135
7/29/2019 ObjectARX

ObjectARX Wizards

Application Wizard
 ObjectARX\utils\ObjARXWiz\ArxWizards.msi
 COM Wrapper Wizard

 Custom Object Wizard

 Reactors Class Wizard

etc.

Visual Studio Add-In


 ObjectARX Commands
 Autodesk Class Explorer
etc.

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 49/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 50/135
7/29/2019 ObjectARX

Agenda

Overview of APIs
AutoCAD: Hello.arx
ObjectDBX: Structure

ObjectDBX: Extend it!


AutoCAD: Multi-Document Environment
Notification System

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 51/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 52/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 53/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 54/135
7/29/2019 ObjectARX
DWG Viewers

No viewing available in RealDWG!


AutoCAD OEM
DWF

www.dwfit.com

Autodesk Design Review


DWG TrueView – conversion of dwgs from old formats

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 55/135
7/29/2019 Database Framework ObjectARX

DWG Client Apps

ObjectARX
Application
AutoCAD
User Interface
Partners: Autodesk: ObjectDBX
App 1 Inventor acdb18.dll achapi18.lib
Object Enablers
acismobj18.lib acge18.lib
App 2 Revit ObjEnabler1.dbx
axdb.lib acis.dll(s)
ObjEnabler2.dbx
Acgiapi.lib others...
Corp. Dev. Max
ObjEnabler3.dbx

Other ObjEnablerN.dbx

Design Object Data

DWG DXF

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 56/135
7/29/2019
Enabling Custom Objects w/o ACAD ObjectARX

DWG Client Apps.

Partners: Autodesk:

App 1 Inventor ObjectDBX


Object Enablers
acdb18.lib achapi18.lib
App 2 Revit ObjEnabler1.dbx
acISMobj.lib acge18.lib
ObjEnabler2.dbx
Corp. Dev. Max axdb.lib acis.dll(s)

acgiapi.lib others... ObjEnabler3.dbx


Other
ObjEnablerN.dbx

Design Object Data

DWG DXF

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 57/135
7/29/2019
Plug-In Model & ObjectDBX ObjectARX

AutoCAD process

.ARX .DBX

Acad.exe &
other AutoCAD ObjectDBX DLLs
specific DLLs

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 58/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 59/135
7/29/2019
What can I do with ObjectARX?
ObjectARX

Create/Modify DWG/DXF files (.ARX)

Create object enabler DLLs (.DBX)

Cannot create standalone applications


… this requires RealDWG

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 60/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 61/135
7/29/2019
Object Identity 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

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 62/135
7/29/2019
Handles, Object IDs, Pointers ObjectARX

ObjectDBX session
1.
2.
Object Open New
.dwg Closed AcDbObject AcDbObject
4. 3.
5.

1. Object read from file


Handle  Object ID
2. Object opened
Object ID  Pointer
3. New object added to database

New Object ID & Handle assigned


4. Object closed
Pointer becomes invalid
5. Object saved to file
Handles are written to disk

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 63/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 64/135
7/29/2019
Open Modes ObjectARX

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

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 65/135
7/29/2019
Transactions ObjectARX

Two models
 Open/Close
 acdbOpenObject
 AcDbObject::close, AcDbObject::cancel
 Transaction
 AcDbTransactionManager::startTransaction
 AcTransaction::getObject
 AcDbTransactionManager::end/abortTransaction

Do not mix transaction models


 e.g. getObject, then close

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 66/135
7/29/2019
Nesting AcTransactions ObjectARX

1 2 3 4
Transaction 2 obj2 obj3

Transaction 1 obj1 obj2

obj1 obj3
obj2
AcDbDatabase

1. Client starts Trans1 and gets Obj1 & Obj2


2. Client starts Trans2 and gets Obj2 & Obj3

3. Client
Trans2commits Trans2
changes are committed
4a. Client commits Trans1
 Trans1 changes are committed
4b. Client aborts Trans1 instead
 Trans1 (and Trans2) changes are rolled back

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 67/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 68/135
7/29/2019
AcDbDatabase Ownership Hierarchy
ObjectARX

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 69/135
7/29/2019
Object Model Overview ObjectARX

classmap.dwg
 in ObjectARX distribution

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 70/135
7/29/2019
Important Classes ObjectARX

AcRxObject

AcGiDrawable
AcDbObject

AcDbEntity

AcDbCurve

AcDbDictionary AcDbLine

AcDbSymbolTable

AcDbBlockTable

AcDbSymbolTableRecord

Database resident objects


Drawable objects

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 71/135
7/29/2019 Snoop Tools for the AutoCAD Database ObjectARX

Tool Language Where to find


ArxDbg C++ ObjectARX Samples
MgdDbg C# ADN site
Inspector C++ ADN site

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 72/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 73/135
7/29/2019 Iterating Through Containers ObjectARX

Objects that use iterators


 Symbol Tables
 Block Table Records
 Dictionaries
 Polylines
 PolyFaceMesh & PolygonMesh
 ACIS Solids
 Called traversers
 BlockReferences (Inserts)
 Only useful when attributes are present

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 74/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 75/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 76/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 77/135
7/29/2019 AcRxClass II (Cont.) ObjectARX

AcRxObject-derived objects hold a pointer to an AcRxClass


object (class descriptor object)
 static class variable

AcRxClass objects hold a pointer to the „parent‟ AcRxClass


object
 forms a „run time class hierarchy‟

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 78/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 79/135
7/29/2019 AcRxClass IV (Roles) ObjectARX

Class Factory
 During filing we look up the class identifier in the runtime class
hierarchy
 AcRxClass provides a „constructor‟ function

Run time type identification


 Each AcRxObject provides a virtual member to look up the static
member pointing to its AcRxClass object

Protocol Extension
 AcRxClasses hold a list of „extension objects‟

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 80/135
7/29/2019
Storing Data in the Database ObjectARX

Create custom objects (more on this later)

Without using custom objects


 Extended entity data (Xdata)
 Xrecords
 Extension dictionaries on individual objects
 Dictionaries e.g. under the Named Objects

Data stored with these methods can be also accessed by LISP


and COM

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 81/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 82/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 83/135
7/29/2019
Inter-Object References ObjectARX

Ownership
 Dictates objects written to disk (DWG/DXF)
 A database object has exactly one owner
 Database is the ultimate owner

 Bi-directional
Pointer reference
 Arbitrary references between object
 Multiple objects can point to the same object
 Uni-directional

Use ArxDbg to discover them

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 84/135
7/29/2019
Inter-Object References ObjectARX

AcDbDatab ase

AcDbDictionary
AcDbBlockTable AcDbLayerTable
Named Object Dict.

AcDbDictionary
AcDbBlockTableRecord AcDbLayerTableRe cord Company Dictionary *

AcDbLine AcDbObject'

AcDbHardOwnershipId AcDbHardPointerId
AcDbSoftOwnershipId AcDbSoftPointerId

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 85/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 86/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 87/135
7/29/2019
Soft/Hard References ObjectARX

Save
 Follows both types of ownership links
Wblock
 Follows hard references

DeepClone
 COPY, MIRROR, EXPLODE commands
 Follows only ownership links
Purge
 Soft references do not protect the object from purge

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 88/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 89/135
7/29/2019
Changing an Object s Identity II ObjectARX

AcDbObject::swapIdWith
 Changes the object denoted by the object ID

id id

AcDbObject AcDbObject

ObjectDBX Session

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 90/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 91/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 92/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 93/135
7/29/2019
Create a New Class ObjectARX

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

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 94/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 95/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 96/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 97/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 98/135
Filing Member Functions II
7/29/2019 ObjectARX

AutoCAD callsfunction
dwgOutFields the dwgOut
on: which in turn calls your
 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

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 99/135
Filing Member Functions III
7/29/2019 ObjectARX

AutoCAD calls dxfOut kFileFiler


WBLOCK
which calls your dxfOutFields function on:

 SAVE kFileFiler
 SAVEAS kFileFiler
 acdbEntGet kBagFiler

AutoCAD calls dxfIn which calls your dxfInFields function on:


 OPEN kFileFiler
 INSERT kFileFiler
 acdbEntMod,
acdbEntMake,
acdbEntMakeX kBagFiler

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 100/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 101/135
Check You Have Access Rights
7/29/2019 ObjectARX

Member functions should first call one of these:


 assertReadEnabled
 Every member function that reads data

 assertWriteEnabled
 Every member function that modifies data

 assertNotifyEnabled
 Used internally

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 102/135
7/29/2019 ObjectARX

http://slidepdf.com/reader/full/objectarx 103/135
Lab Step 5
7/29/2019 ObjectARX

Creating a Custom Object

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 104/135
Graphics Display
7/29/2019 ObjectARX

ObjectDBX does not display any graphics

ObjectDBX defines a callback API that host applications may


implement
 AcGi: interface between database objects and a display system

Host applications must implement AcGi to display graphics

AcGi Library defines the interface between database objects


and a display system

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 105/135
7/29/2019 ObjectARX

Graphics Acquisition
http://slidepdf.com/reader/full/objectarx 106/135
7/29/2019 ObjectARX

4.

An AcGiWorldDraw An AcGiDrawable

6.
1.
3.
5.

Host Application 2. An AcGiViewportDraw

1. Host creates object implementing AcGiWorldDraw


2. Host creates object implementing AcGiViewportDraw

3. Host passes world-draw object to your drawable


4. Drawable draws viewport independent graphics
5. Host passes viewport-draw object to your drawable
6. Drawable draws viewport dependent graphics

© 2008 Autodesk

AcGiGeometry
http://slidepdf.com/reader/full/objectarx 107/135
7/29/2019 ObjectARX

Responsible for inserting geometry into the graphics cache for


later display

Primitive geometry used:


 circle, circularArc, polyline,
 mesh, pline, polygon,
 shell, text, xline and ray

Viewport-dependent and viewport-independent graphics

© 2008 Autodesk

AcGiSubEntityTraits
http://slidepdf.com/reader/full/objectarx 108/135
7/29/2019 ObjectARX

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

Default attribute values:


 color, layer, linetype - Current for editor
 filltype - kAcGiFillNever if standard mode
kAcGiFillAlways if hide, shade, render
 gsmarker - invalid, must be set by app

© 2008 Autodesk

Special Uses of AcGi


http://slidepdf.com/reader/full/objectarx 109/135
7/29/2019 ObjectARX

Can derive
versions from AcGiWorldGeometry,
of geometry functions implementing own

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 110/135
7/29/2019 ObjectARX

AcDbEntity Protocol
http://slidepdf.com/reader/full/objectarx 111/135
7/29/2019 ObjectARX

subGetOsnapPoints - define osnap points


subGetGripPoints - define grip points
subMoveGripPointsAt - default is to call
AcDbEntity::subTransformBy
subGetStretchPoints - provide stretch points other than
the grippoints, default is to call
subGetGripPoints
subMoveStretchPointsAt - used by stretch, default is
subTransformBy
subTransformBy - needed for moving entity

© 2008 Autodesk

AcDbEntity Protocol
http://slidepdf.com/reader/full/objectarx 112/135
7/29/2019 ObjectARX

subIntersectWith - no default
subGetGeomExtents - no default

subList - print specified data, DXF name, layer,


space, and handle by default

subExplode - no default, must be implemented for


hatch to work
 If exploding to non-“native” objects, return eExplodeAgain
 Hatch calls explode recursively until down to “native”
entities (until eOk returned)

© 2008 Autodesk

Lab - Step 6
http://slidepdf.com/reader/full/objectarx 113/135
7/29/2019 ObjectARX

Creating a Custom Entity

© 2008 Autodesk

Agenda
http://slidepdf.com/reader/full/objectarx 114/135
7/29/2019 ObjectARX

Overview of APIs
AutoCAD: Hello.arx
ObjectDBX: Structure
ObjectDBX: Extend it!
AutoCAD: Multi-Document Environment
Notification System

© 2008 Autodesk

AutoCAD: Multi-Document Environment (MDE)


http://slidepdf.com/reader/full/objectarx 115/135
7/29/2019 ObjectARX

Documents, per-document data

Execution context

Document locking

© 2008 Autodesk

Documents
http://slidepdf.com/reader/full/objectarx 116/135
7/29/2019 ObjectARX

State of the edit session


AcApDocument class encapsulates
 AcDbDatabase viewed
 XRefed databases
 Selection sets
 Most system variables

AcApDocManager holds the list of documents

© 2008 Autodesk

Per-Document Data
http://slidepdf.com/reader/full/objectarx 117/135
7/29/2019 ObjectARX

Applications may have per-doc data


 this is their concept of a document

Data must be kept in sync with the active document (fiber)


 this is their concept of a document manager

© 2008 Autodesk

Execution Contexts
http://slidepdf.com/reader/full/objectarx 118/135
7/29/2019 ObjectARX

AutoCAD has a fiber-based architecture


 see MSDN for more info on fibers
 fibers are scheduled by AutoCAD
 they have their own call stack

Application fiber (context):


 runs windows message loop
 kicks off a fiber for each document created

Document fibers (context):


 run commands for the given document

© 2008 Autodesk

Fiber scheduling in AutoCAD


http://slidepdf.com/reader/full/objectarx 119/135
7/29/2019 ObjectARX

App Fiber Doc1 Fiber Doc2 Fiber

Msg loop
Cmd started
in Doc1
Time
Doc1 prompts for
user input
Msg loop
User switches to
Doc2, starts cmd

Cmd completes
in Doc2
Msg loop

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 120/135
7/29/2019 ObjectARX

Lock Types
http://slidepdf.com/reader/full/objectarx 121/135
7/29/2019 ObjectARX

New Lock Request


(from another context)

XWrite Write Read AWrite

None
k
c    
o Read
L
t

n
Write
e
r
r

u XWrite
C

AutoWrite   

© 2008 Autodesk

Document vs. Application


http://slidepdf.com/reader/full/objectarx 122/135
7/29/2019 ObjectARX

Document context
 Automatic locking (simpler)
 e.g. for exclusive write
 addCommand ( …, ACRX_CMD_DOCEXCLUSIVELOCK, … );

Application context
 Manual locking (more control)
 acDocManager->lockDocument( pDoc, kXWrite );

 Required for multiple docs

© 2008 Autodesk

Current vs. Active Documents


http://slidepdf.com/reader/full/objectarx 123/135
7/29/2019 ObjectARX

Current…
 for the user = „Active‟
 for the API = „Current‟

Activating a document sets the current doc


 current document = active document

Current doc can change (programmatically)


 current document may not be active

© 2008 Autodesk

Agenda
http://slidepdf.com/reader/full/objectarx 124/135
7/29/2019 ObjectARX

Overview of APIs
AutoCAD: Hello.arx
ObjectDBX: Structure
ObjectDBX: Extend it!
AutoCAD: Multi-Document Environment
Notification System

© 2008 Autodesk

Notification System
http://slidepdf.com/reader/full/objectarx 125/135
7/29/2019 ObjectARX

Observer Pattern Implementation


Subjects & Observers
 ObjectDBX
 AutoCAD

Acting as an Observer
Acting as a Subject

© 2008 Autodesk

Notification
http://slidepdf.com/reader/full/objectarx 126/135
7/29/2019 Observer pattern class diagram
ObjectARX

1. Knows its observers Defines updating interface


2. Provides interface to
attach/detach observers

Observer
Subject observers

Attach(Observer) Update()
Detach(Observer)
For all o in observers { SendNotification()
o->Update()
}

ConcreteSubject ConcreteObserver
Update()
subjectState observerState

© 2008 Autodesk

Notification
http://slidepdf.com/reader/full/objectarx 127/135
7/29/2019 ObjectARX

Observer pattern interaction diagram

3.
A ConcreteSubject 4.
A ConcreteObserver

2. 1.
Client

1. Client creates observer


2. Client attaches observer to subject
3. Subject changes state and fires notification to observer
4. Observer learns details of state change

© 2008 Autodesk

Notification Example
http://slidepdf.com/reader/full/objectarx 128/135
7/29/2019 ObjectARX
Interaction diagram

3.
An AcDbLine 4.
Your custom object

2.
1.
Client

1. Client creates your custom object


2. Client calls addPersistentReactor on the AcDbLine
3. Changing AcDbLine sends objectModified notification
4. Your custom object looks at the line to find out what changed

© 2008 Autodesk

ObjectDBX
http://slidepdf.com/reader/full/objectarx 129/135
Observers (reactors)
7/29/2019 ObjectARX

Another AcDbObject An AcDbDatabaseReactor


An AcDbDatabase

s An AcDbObject An AcDbObjectReactor
t
c
e
j
b An AcDbLayoutManagerReactor
u The AcDbLayoutManager
S
The AcDbTransactionManager An AcTransactionReactor

The AcRxEvent An AcRxEventReactor

The AcRxDynamicLinker An AcRxDLinkerReactor

ObjectDBX

© 2008 Autodesk

AutoCAD
http://slidepdf.com/reader/full/objectarx 130/135
Observers (reactors)
7/29/2019 ObjectARX

The AcDbSummaryInfoManager An AcDbSummaryInfoReactor

The AcGsManager An AcGsReactor

The AcApProfileManager An AcApProfileManagerReactor


s
t
c An AcEdInputPointFilter
e
j
b The AcEdInputPointManager An AcEdInputPointMonitor
u
S An AcEdInputContextReactor

The AcApLongTransactionManager An AcApLongTransactionReactor

The AcApDocumentManager An AcApDocManagerReactor

The AcEditor An AcEditorReactor


AutoCAD

© 2008 Autodesk

Acting as an Observer
http://slidepdf.com/reader/full/objectarx 131/135
7/29/2019 ObjectARX

Derive a concrete observer class


 Override notification functions

Instantiate it
Attach it to subject
Remove it when done
 At least when application is unloaded

© 2008 Autodesk

Acting as a Subject
http://slidepdf.com/reader/full/objectarx 132/135
7/29/2019 ObjectARX

Define your own observer (notification) interface


Provide methods to attach/detach observers
Send notifications when state changes
 If your observer (reactor) is database resident then open it for
kForNotify

© 2008 Autodesk

Lab - Step 7
http://slidepdf.com/reader/full/objectarx 133/135
7/29/2019 ObjectARX

Observing various subjects

© 2008 Autodesk

http://slidepdf.com/reader/full/objectarx 134/135
7/29/2019 ObjectARX

Thank you!

http://slidepdf.com/reader/full/objectarx 135/135

You might also like