- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I created a custom object that inherits from AcDbBlockTableRecord. I use it to create a block definition '111' and save it as a dwg file. When I open this dwg without loading arx, I will be prompted to repair the file.How can solve this problem?
class DLLIMPEXP YJBlkDef : public AcDbBlockTableRecord {
public:
ACRX_DECLARE_MEMBERS(YJBlkDef) ;
protected:
static Adesk::UInt32 kCurrentVersionNumber ;
public:
YJBlkDef () ;
virtual ~YJBlkDef () ;
//----- AcDbObject protocols
//- Dwg Filing protocol
virtual Acad::ErrorStatus dwgOutFields (AcDbDwgFiler *pFiler) const ;
virtual Acad::ErrorStatus dwgInFields (AcDbDwgFiler *pFiler) ;
} ;
#ifdef YJENTITY_MODULE
ACDB_REGISTER_OBJECT_ENTRY_AUTO(YJBlkDef)
#endif
#include "StdAfx.h"
#include "YJBlkDef.h"
//-----------------------------------------------------------------------------
Adesk::UInt32 YJBlkDef::kCurrentVersionNumber =1 ;
//-----------------------------------------------------------------------------
ACRX_DXF_DEFINE_MEMBERS (
YJBlkDef, AcDbBlockTableRecord,
AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
AcDbProxyEntity::kNoOperation, YJBLKDEF,
YTMYJENTITYAPP
|Product Desc: A description for your object
|Company: Your company name
|WEB Address: Your company WEB site address
)
//-----------------------------------------------------------------------------
YJBlkDef::YJBlkDef () : AcDbBlockTableRecord () {
}
YJBlkDef::~YJBlkDef () {
}
//-----------------------------------------------------------------------------
//----- AcDbObject protocols
//- Dwg Filing protocol
Acad::ErrorStatus YJBlkDef::dwgOutFields (AcDbDwgFiler *pFiler) const {
assertReadEnabled () ;
//----- Save parent class information first.
Acad::ErrorStatus es =AcDbObject::dwgOutFields (pFiler) ;
if ( es != Acad::eOk )
return (es) ;
//----- Object version number needs to be saved first
if ( (es =pFiler->writeUInt32 (YJBlkDef::kCurrentVersionNumber)) != Acad::eOk )
return (es) ;
//----- Output params
//.....
es = __super::dwgOutFields(pFiler);
return (pFiler->filerStatus ()) ;
}
Acad::ErrorStatus YJBlkDef::dwgInFields (AcDbDwgFiler *pFiler) {
assertWriteEnabled () ;
//----- Read parent class information first.
Acad::ErrorStatus es =AcDbObject::dwgInFields (pFiler) ;
if ( es != Acad::eOk )
return (es) ;
//----- Object version number needs to be read first
Adesk::UInt32 version =0 ;
if ( (es =pFiler->readUInt32 (&version)) != Acad::eOk )
return (es) ;
if ( version > YJBlkDef::kCurrentVersionNumber )
return (Acad::eMakeMeProxy) ;
//- Uncomment the 2 following lines if your current object implementation cannot
//- support previous version of that object.
//if ( version < YJBlkDef::kCurrentVersionNumber )
// return (Acad::eMakeMeProxy) ;
//----- Read params
//.....
es = __super::dwgInFields(pFiler);
return (pFiler->filerStatus ()) ;
}
static void YTMYJEntityMyCommand1(void)
{
// Add your code for command YTMYJEntity.MyCommand1 here
Acad::ErrorStatus es;
AcDbBlockTable *pBlkTbl = NULL;
acdbCurDwg()->getBlockTable(pBlkTbl, AcDb::kForWrite);
YJBlkDef *pBlkTblRcd = new YJBlkDef();
pBlkTblRcd->setName(_T("111"));AcDbObjectId blkDefId;
es = pBlkTbl->add(blkDefId, pBlkTblRcd);
pBlkTbl->close();
if(Acad::eOk !=es)
{
acutPrintf(_T("\nAdd error!"));
delete pBlkTblRcd;return;
}
std::vector<AcDbEntity*> pEnts;
{
AcDbLine* pLine = new AcDbLine(AcGePoint3d(0,0,0),AcGePoint3d(10,10,0));
pEnts.push_back(pLine);
AcDbCircle* pCilrcle = new AcDbCircle(AcGePoint3d(5,5,0),AcGeVector3d::kZAxis,3);
pCilrcle->setColorIndex(3);
pEnts.push_back(pCilrcle);
}
for(int i=0;i<pEnts.size();i++)
{
AcDbObjectId entId;
es =pBlkTblRcd->appendAcDbEntity(entId, pEnts.at(i));
if (es != Acad::eOk)
{
acutPrintf(_T("\nError!"));
delete pEnts.at(i);
continue;
}
pEnts.at(i)->close();
}
pBlkTblRcd->close();
AcDbBlockReference *pBlkRef = new AcDbBlockReference(AcGePoint3d(20,20,0), blkDefId);
PostToModelSpace(pBlkRef);
}
Solved! Go to Solution.