Message 1 of 9
Custom entity?
Not applicable
05-29-2007
07:01 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have developed several entities before but all of them in a dbx project. This time I just want to create an AcDbEntity derived class for a title block in the arx application, not a stand-alone dbx.
Is there a minimum of work that needs to be done? Below is what I have so far, but when I try to append an object of this class to the database, I get an exception error. The debug window shows the following line:
[code]
First-chance exception at 0x7c812a5b in acad.exe: Microsoft C++ exception: CInvalidArgException at memory location 0x0012f64c..
[/code]
Any suggestions?
[code]
#pragma once
class TitleBlock : public AcDbEntity
{
private:
AcDbExtents _page;
AcDbExtents _dwgArea;
public:
TitleBlock(void);
~TitleBlock(void);
virtual Adesk::Boolean worldDraw(AcGiWorldDraw* mode);
virtual Acad::ErrorStatus dwgInFields(AcDbDwgFiler* pFiler);
virtual Acad::ErrorStatus dwgOutFields(AcDbDwgFiler* pFiler) const;
};
#include "StdAfx.h"
#include "TitleBlock.h"
TitleBlock::TitleBlock(void)
: AcDbEntity()
, _page(AcDbExtents(AcGePoint3d(0,0,0), AcGePoint3d(8.5,11,0)))
, _dwgArea(AcDbExtents(AcGePoint3d(2.0,3.75,0), AcGePoint3d(9.0,6.25,0)))
{
}
TitleBlock::~TitleBlock(void)
{
}
Adesk::Boolean TitleBlock::worldDraw(AcGiWorldDraw* mode)
{
assertReadEnabled();
AcGeVector3d x(_page.maxPoint().x - _page.minPoint().x, 0, 0);
AcGeVector3d y(0, _page.maxPoint().y - _page.minPoint().y, 0);
AcGePoint3d pts[5];
pts[0] = _page.minPoint();
pts[1] = pts[0] + x;
pts[2] = pts[0] + x + y;
pts[3] = pts[0] + y;
pts[4] = pts[0];
mode->geometry().polyline(5, pts);
x.set(_dwgArea.maxPoint().x - _dwgArea.minPoint().x, 0, 0);
y.set(0, _dwgArea.maxPoint().y - _dwgArea.minPoint().y, 0);
pts[0] = _dwgArea.minPoint();
pts[1] = pts[0] + x;
pts[2] = pts[0] + x + y;
pts[3] = pts[0] + y;
pts[4] = pts[0];
mode->geometry().polyline(5, pts);
return Adesk::kTrue;
}
Acad::ErrorStatus TitleBlock::dwgInFields(AcDbDwgFiler* pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es = AcDbEntity::dwgInFields(pFiler);
if(es != Acad::eOk)
return es;
AcGePoint3d min, max;
pFiler->readPoint3d(&min);
pFiler->readPoint3d(&max);
_page.set(min, max);
pFiler->readPoint3d(&min);
pFiler->readPoint3d(&max);
_dwgArea.set(min, max);
return pFiler->filerStatus();
}
Acad::ErrorStatus TitleBlock::dwgOutFields(AcDbDwgFiler* pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es = AcDbEntity::dwgOutFields(pFiler);
if(es != Acad::eOk)
return es;
pFiler->writePoint3d(_page.minPoint());
pFiler->writePoint3d(_page.maxPoint());
pFiler->writePoint3d(_dwgArea.minPoint());
pFiler->writePoint3d(_dwgArea.maxPoint());
return pFiler->filerStatus();
}
Acad::ErrorStatus AddEntity(AcDbObjectId& objId, AcDbEntity* pEnt)
{
AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase();
if(!pDb)
return Acad::eInvalidBlockName;
AcDbBlockTable* pBt = NULL;
Acad::ErrorStatus es = pDb->getBlockTable(pBt, AcDb::kForRead);
if(es == Acad::eOk)
{
AcDbBlockTableRecord* pBtr = NULL;
es = pBt->getAt(ACDB_MODEL_SPACE, pBtr, AcDb::kForWrite);
if(es == Acad::eOk)
{
es = pBtr->appendAcDbEntity(objId, pEnt);
pBtr->close();
}
pBt->close();
}
return es;
}
[/code]
Mike B
Is there a minimum of work that needs to be done? Below is what I have so far, but when I try to append an object of this class to the database, I get an exception error. The debug window shows the following line:
[code]
First-chance exception at 0x7c812a5b in acad.exe: Microsoft C++ exception: CInvalidArgException at memory location 0x0012f64c..
[/code]
Any suggestions?
[code]
#pragma once
class TitleBlock : public AcDbEntity
{
private:
AcDbExtents _page;
AcDbExtents _dwgArea;
public:
TitleBlock(void);
~TitleBlock(void);
virtual Adesk::Boolean worldDraw(AcGiWorldDraw* mode);
virtual Acad::ErrorStatus dwgInFields(AcDbDwgFiler* pFiler);
virtual Acad::ErrorStatus dwgOutFields(AcDbDwgFiler* pFiler) const;
};
#include "StdAfx.h"
#include "TitleBlock.h"
TitleBlock::TitleBlock(void)
: AcDbEntity()
, _page(AcDbExtents(AcGePoint3d(0,0,0), AcGePoint3d(8.5,11,0)))
, _dwgArea(AcDbExtents(AcGePoint3d(2.0,3.75,0), AcGePoint3d(9.0,6.25,0)))
{
}
TitleBlock::~TitleBlock(void)
{
}
Adesk::Boolean TitleBlock::worldDraw(AcGiWorldDraw* mode)
{
assertReadEnabled();
AcGeVector3d x(_page.maxPoint().x - _page.minPoint().x, 0, 0);
AcGeVector3d y(0, _page.maxPoint().y - _page.minPoint().y, 0);
AcGePoint3d pts[5];
pts[0] = _page.minPoint();
pts[1] = pts[0] + x;
pts[2] = pts[0] + x + y;
pts[3] = pts[0] + y;
pts[4] = pts[0];
mode->geometry().polyline(5, pts);
x.set(_dwgArea.maxPoint().x - _dwgArea.minPoint().x, 0, 0);
y.set(0, _dwgArea.maxPoint().y - _dwgArea.minPoint().y, 0);
pts[0] = _dwgArea.minPoint();
pts[1] = pts[0] + x;
pts[2] = pts[0] + x + y;
pts[3] = pts[0] + y;
pts[4] = pts[0];
mode->geometry().polyline(5, pts);
return Adesk::kTrue;
}
Acad::ErrorStatus TitleBlock::dwgInFields(AcDbDwgFiler* pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es = AcDbEntity::dwgInFields(pFiler);
if(es != Acad::eOk)
return es;
AcGePoint3d min, max;
pFiler->readPoint3d(&min);
pFiler->readPoint3d(&max);
_page.set(min, max);
pFiler->readPoint3d(&min);
pFiler->readPoint3d(&max);
_dwgArea.set(min, max);
return pFiler->filerStatus();
}
Acad::ErrorStatus TitleBlock::dwgOutFields(AcDbDwgFiler* pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es = AcDbEntity::dwgOutFields(pFiler);
if(es != Acad::eOk)
return es;
pFiler->writePoint3d(_page.minPoint());
pFiler->writePoint3d(_page.maxPoint());
pFiler->writePoint3d(_dwgArea.minPoint());
pFiler->writePoint3d(_dwgArea.maxPoint());
return pFiler->filerStatus();
}
Acad::ErrorStatus AddEntity(AcDbObjectId& objId, AcDbEntity* pEnt)
{
AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase();
if(!pDb)
return Acad::eInvalidBlockName;
AcDbBlockTable* pBt = NULL;
Acad::ErrorStatus es = pDb->getBlockTable(pBt, AcDb::kForRead);
if(es == Acad::eOk)
{
AcDbBlockTableRecord* pBtr = NULL;
es = pBt->getAt(ACDB_MODEL_SPACE, pBtr, AcDb::kForWrite);
if(es == Acad::eOk)
{
es = pBtr->appendAcDbEntity(objId, pEnt);
pBtr->close();
}
pBt->close();
}
return es;
}
[/code]
Mike B