36
ObjectARX 2009 Nguyen Xuan Hong Quick Overview Ha Noi, 1/11/2008

ObjectARX 2009

Embed Size (px)

Citation preview

Page 1: ObjectARX 2009

ObjectARX 2009

Nguyen Xuan Hong

Quick Overview

Ha Noi, 1/11/2008

Page 2: ObjectARX 2009

ObjectArx 2009

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

Page 3: ObjectARX 2009

ObjectArx 2009

Abilities

AutoCAD

database

Access

AutoCAD editor

Interact

UI with MFC

Create

Custom classes

Create

Complex applications

BuildOther

environments

Interact Support the MDI

Page 4: ObjectARX 2009

ObjectArx 2009

Class Libraries

AcRx

AcEd

AcDb

AcGi AcGe

ObjectARX

Page 5: ObjectARX 2009

ObjectArx 2009

Create Project Using Wizard

Page 6: ObjectARX 2009

ObjectArx 2009

Setting Project Include Library

Page 7: ObjectARX 2009

ObjectArx 2009

New Command Test1 Command

Page 8: ObjectARX 2009

ObjectArx 2009

AutoCad Database Class AcDbDatabase

Objects

Textstyle Records

View Records

Named Object Dictionary

Group Dictionary

Color Dictionary

EntitiesEntitiesEntities

Model Space

Paper Space

Block Records

Layer Records

Block Table

Layer Table

TextStyleTable

View Table

Layout Dictionary

Dictionary

Dictionary

AutoCad Database

Page 9: ObjectARX 2009

ObjectArx 2009

Assess a symbol Get a database – acdbCurDwg() Get a table Open a record - read/write

Process…(get/set) …

Close record Close table ?

Page 10: ObjectARX 2009

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

?

Page 11: ObjectARX 2009

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

?

Page 12: ObjectARX 2009

ObjectArx 2009

Access entity Select object

Convert ename to objectId Open entity for read/write

Get/set properties Get/set location …

Close

?

Page 13: ObjectARX 2009

ObjectArx 2009

Delete object Open object for write Call erase function Close object

Page 14: ObjectARX 2009

ObjectArx 2009

Extension Data

Block Record

Entity

Custom Entity

xData

ExtensionDictionary

Object

CustomObject

Block Table

Named Object

Dictionary

Dictionary

AutoCad Database

Page 15: ObjectARX 2009

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

Page 16: ObjectARX 2009

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

Page 17: ObjectARX 2009

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?

Page 18: ObjectARX 2009

ObjectArx 2009

Get xData Open an object for read Call xData fuction with AppName to

receive a resbuf Process resbuf… Release resbuf Close object

Page 19: ObjectARX 2009

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

?

Page 20: ObjectARX 2009

ObjectArx 2009

Notifycation Window Message

acedRegisterFilterWinMsg acedRemoveFilterWinMsg

Reactor Transient and Persistent AcDbObjectReactor AcDbDatabaseReactor AcEdEditorReactor …

Page 21: ObjectARX 2009

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) ?

Page 22: ObjectARX 2009

ObjectArx 2009

ObjectArx 2009

THE END

Page 23: ObjectARX 2009

ObjectArx 2009

Page 24: ObjectARX 2009

ObjectArx 2009

Class Libraries

ObjectARX

Classes for binding an application and for runtime class registration and

identification

AcRx

AcEd

AcDb

AcGi AcGe

Page 25: ObjectARX 2009

ObjectArx 2009

Class Libraries

ObjectARX

Classes for registering native AutoCAD

commands and for AutoCAD event

notification

AcRx

AcEd

AcDb

AcGi AcGe

Page 26: ObjectARX 2009

ObjectArx 2009

Class Libraries

ObjectARX

AutoCAD database classes

AcRx

AcEd

AcDb

AcGi AcGe

Page 27: ObjectARX 2009

ObjectArx 2009

Class Libraries

ObjectARX Utility classes for common linear

algebra and geometric objects

AcRx

AcEd

AcDb

AcGi AcGe

Page 28: ObjectARX 2009

ObjectArx 2009

Class Libraries

ObjectARXGraphics classes for rendering

AutoCAD entities

AcRx

AcEd

AcDb

AcGi AcGe

Page 29: ObjectARX 2009

ObjectArx 2009

Ex: Assess a textstyledouble 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;

}

Page 30: ObjectARX 2009

ObjectArx 2009

Ex: Create a layerAcDbObjectId 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;

}

Page 31: ObjectARX 2009

ObjectArx 2009

Ex: New a lineAcDbObjectId 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;

}

Page 32: ObjectARX 2009

ObjectArx 2009

Ex: Change colorvoid 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();

}}

}

Page 33: ObjectARX 2009

ObjectArx 2009

Ex: Add xdatavoid 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);

}}

Page 34: ObjectARX 2009

ObjectArx 2009

Ex: Add extension dictionaryvoid 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();

}}

}

Page 35: ObjectARX 2009

ObjectArx 2009

Ex: Use reactor// EditorReactor.h file

class CEditorReactor : public AcEditorReactor{

public:

CEditorReactor();

virtual ~CEditorReactor () ;

virtual void commandEnded (const ACHAR* cmdStr);

};

// 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);

}

Page 36: ObjectARX 2009

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) ;

}