Sie sind auf Seite 1von 36

ObjectARX 2009

Quick Overview

Nguyen Xuan Hong

Ha Noi, 1/11/2008

Introduction
ARX = AutoCad Runtime eXtension ObjectARX is an object oriented program library to extend AutoCad ObjectARX is developed by C++ Latest version is ObjectArx 2009 for Autocad 2009 and compatiable with Microsoft Visual Studion 2008 Download: http://autodesk.com/objectarx
ObjectArx 2009

Abilities
AutoCA D databas e Access Interact Other environments Build Create Support the MDI AutoCA D editor Interact Create UI with MFC

Complex applications

Custom classes

ObjectArx 2009

Class Libraries
AcEd

AcRx AcDb

ObjectARX

AcGi

AcGe ObjectArx 2009

Create Project
Using Wizard

ObjectArx 2009

Setting Project
Include Library

ObjectArx 2009

New Command
Test1 Command

ObjectArx 2009

AutoCad Database
Class AcDbDatabase
AutoCad Database
Color Dictionary Named Object Dictionary Group Dictionary Layout Dictionary
Layer Records Model Space Paper Space Textstyle Records View Records

Layer Table

Block Table

TextStyl eTable

View Table

Dictionar y Dictionary
Objects

Block Records

Entities

Entities

Entities

ObjectArx 2009

Assess a symbol
Get a database acdbCurDwg() Get a table Open a record - read/write
 Process(get/set) 

Close record Close table

?
ObjectArx 2009

New Symbol
Open Table for write New a record (Layer, View, Ucs)
 Set name  Set properties 

Add record to table Close record Clode table

?
ObjectArx 2009

New Entity
New an object of a class inherit from AcDbEntity
 Set properties (Layer, Color,)  Set location 

Append to database

 Open Block table for read  Open Block record (Model, Paper,) for write  Append entity to block record  Close
ObjectArx 2009

Access entity
Select object
 Convert ename to objectId

Open entity for read/write


 Get/set properties  Get/set location 

Close

ObjectArx 2009

Delete object
Open object for write Call erase function Close object

ObjectArx 2009

Extension Data
AutoCad Database Block Table Object xData Entity Block Record Extension Dictionary Dictionary Named Object Dictionary

Custom Entity

Custom Object

ObjectArx 2009

Custom Object
Inherit from AcDbObject Define: ACRX_DXF_DEFINE_MEMBERS
 ACRX_DXF_DEFINE_MEMBERS(CLASS_NAME, PARENT_CLASS, DWG_VERSION, MAINTENANCE_VERSION, PROXY_FLAGS , DXF_NAME, APP)

Override: dwgIn, dwgOut, Init: rxInit() Unload: deleteAcRxClass() Use:


 New a custom object and set properties  Add to dictionary - setAt(Name) function  Close custom object
ObjectArx 2009

Custom Entity
Inherit from AcDbEntity Define: ACRX_DXF_DEFINE_MEMBERS Override: dwgIn, dwgOut, worldDraw, Init: rxInit() Unload: deleteAcRxClass() Use:
     New a custom entity Set properties Set location Add to block record Close custom entity
ObjectArx 2009

Add xData
Registry AppName Build a struct resbuf list
 acutBuildList(,RTNONE)  New direct elements of resbuf

Open an object for write Call setXdata function with resbuf Close object Release resbuf
 acutRelRb

ObjectArx 2009

Get xData
Open an object for read Call xData fuction with AppName to receive a resbuf Process resbuf Release resbuf Close object

ObjectArx 2009

Add Data to Extension Dictionary


Open an object for write Open extension dictionary of object for write Open xrecord with AppName Build a struct resbuf list Add resbuf to xrecod setFromRbChain Release resbuf Close xrecord, extension dictionary and object

ObjectArx 2009

Notifycation
Window Message
 acedRegisterFilterWinMsg
 acedRemoveFilterWinMsg

Reactor  Transient and Persistent  AcDbObjectReactor  AcDbDatabaseReactor  AcEdEditorReactor 

ObjectArx 2009

Use reactor
Inherit from a reactor class (AcDbDatabaseReactor...) Override events: (objectModified...) Determine reactor manager object: (AcDbDatabase, AcEditor...) Init: addReactor(this) Unload: removeReactor(this)

ObjectArx 2009

ObjectArx 2009

THE END

ObjectArx 2009

ObjectArx 2009

Class Libraries
Classes for binding an application and for runtime class registration and identification AcRx AcDb AcEd

ObjectARX

AcGi

AcGe ObjectArx 2009

Class Libraries
AcEd

AcRx

Classes for registering native AutoCAD commands and for AutoCAD event notification ObjectARX

AcDb

AcGi

AcGe ObjectArx 2009

Class Libraries
AcEd AutoCAD database classes

AcRx AcDb

ObjectARX

AcGi

AcGe ObjectArx 2009

Class Libraries
AcEd

AcRx AcDb Utility classes for common linear algebra and geometric objects

ObjectARX

AcGi

AcGe ObjectArx 2009

Class Libraries
AcEd

AcRx AcDb

Graphics classes for rendering AutoCAD entities

ObjectARX

AcGi

AcGe ObjectArx 2009

Ex: Assess a textstyle


double getTextSize(const CString& sTextStyle) { double dTextSize = 0.0; AcDbTextStyleTable* pTextStyleTbl = NULL; if(acdbCurDwg()->getTextStyleTable(pTextStyleTbl,AcDb::kForRead) == Acad::eOk) { AcDbTextStyleTableRecord* pTextStyleTblRcd = NULL; if(pTextStyleTbl->getAt(sTextStyle,pTextStyleTblRcd,AcDb::kForRead) == Acad::eOk) { dTextSize = pTextStyleTblRcd->textSize(); pTextStyleTblRcd->close(); } pTextStyleTbl->close(); } return dTextSize; }

ObjectArx 2009

Ex: Create a layer


AcDbObjectId createLayer(const CString& sLayerName) { AcDbObjectId layerId; AcDbLayerTable* pLayerTbl = NULL; if(acdbCurDwg()->getLayerTable(pLayerTbl,AcDb::kForWrite) == Acad::eOk) { if(!pLayerTbl->has(sLayerName)) { AcDbLayerTableRecord* pLayerTblRcd = new AcDbLayerTableRecord(); pLayerTblRcd->setName(sLayerName); pLayerTbl->add(layerId,pLayerTblRcd); pLayerTblRcd->close(); } pLayerTbl->close(); } return layerId; }

ObjectArx 2009

Ex: New a line


AcDbObjectId createLine() { AcDbObjectId lineId; AcDbBlockTable* pBlkTbl = NULL; if(acdbCurDwg()->getBlockTable(pBlkTbl,AcDb::kForRead) == Acad::eOk) { AcDbBlockTableRecord* pBlkTblRcd = NULL; if(pBlkTbl->getAt(ACDB_MODEL_SPACE,pBlkTblRcd,AcDb::kForWrite) == Acad::eOk) { AcDbLine* pLine = new AcDbLine(); pLine->setStartPoint(AcGePoint3d(0,0,0)); pLine->setEndPoint(AcGePoint3d(100,0,0)); pLine->setColorIndex(1); pBlkTblRcd->appendAcDbEntity(lineId,pLine); pBlkTblRcd->close(); } pBlkTbl->close(); } return lineId; }

ObjectArx 2009

Ex: Change color


void changeColor() { ads_name ename; ads_point point; if(acedEntSel(_T("\nSelect an entity:"),ename,point) == RTNORM) { AcDbObjectId objectId; acdbGetObjectId(objectId,ename); AcDbEntity* pEnt = NULL; if(acdbOpenAcDbEntity(pEnt,objectId,AcDb::kForWrite) == Acad::eOk) { pEnt->setColorIndex(2); pEnt->close(); } } }

ObjectArx 2009

Ex: Add xdata


void addXdata(const AcDbObjectId& objId, const CString sAppName) { acdbRegApp(sAppName); AcDbObject* pObj = NULL; if(acdbOpenAcDbObject(pObj,objId,AcDb::kForWrite) == Acad::eOk) { struct resbuf* pRb = acutBuildList(RTSTR, sAppName, RTSHORT, 1, RTNONE); pObj->setXData(pRb); pObj->close(); acutRelRb(pRb); } }

ObjectArx 2009

Ex: Add extension dictionary


void addExtensionDic(const AcDbObjectId& objId, const CString sAppName){ AcDbObject* pObj = NULL; if(acdbOpenAcDbObject(pObj,objId,AcDb::kForWrite) == Acad::eOk){ AcDbObjectId extId = pObj->extensionDictionary(); if(extId == AcDbObjectId::kNull){ pObj->createExtensionDictionary(); extId = pObj->extensionDictionary(); } AcDbDictionary* pDic = NULL; if(acdbOpenObject(pDic,extId,AcDb::kForWrite) == Acad::eOk){ AcDbXrecord* pXrecord = NULL; if(pDic->getAt(sAppName,(AcDbObject*&)pXrecord,AcDb::kForWrite) != Acad::eOk){ pXrecord = new AcDbXrecord(); AcDbObjectId xrdId; pDic->setAt(sAppName,pXrecord,xrdId); } struct resbuf* pRb = acutBuildList(RTSTR, sAppName, RTSHORT, 1, RTNONE); pXrecord->setFromRbChain(*pRb); acutRelRb(pRb); pXrecord->close(); pDic->close(); } } } ObjectArx 2009

Ex: Use reactor


// EditorReactor.h file class public: CEditorReactor(); virtual ~CEditorReactor () ; virtual void commandEnded }; // EditorReactor.cpp file CEditorReactor::CEditorReactor () { if(acedEditor) acedEditor->addReactor(this); } CEditorReactor::~CEditorReactor (){ if(acedEditor) acedEditor->removeReactor(this); } void CEditorReactor::commandEnded (const ACHAR* cmdStr){ acutPrintf(_T("\nCommand %s"),cmdStr); } (const ACHAR* cmdStr); CEditorReactor : public AcEditorReactor{

ObjectArx 2009

Ex: Use reactor


// Main.cpp #include "EditorReactor.h" class CArxProject1App : public AcRxArxApp { CEditorReactor* m_pEditorReactor; public: CArxProject1App () : AcRxArxApp () m_pEditorReactor = NULL; } virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) { AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ; m_pEditorReactor = new VsEditorReactor(); return (retCode) ; } virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) { AcRx::AppRetCode retCode =AcRxArxApp::On_kUnloadAppMsg (pkt) ; delete m_pEditorReactor; return (retCode) ; } {

ObjectArx 2009

Das könnte Ihnen auch gefallen