AcDbBlockTableRecord* getModelSpace(AcDb::OpenMode mode)
{
AcDbBlockTableRecord* Blok = NULL;
AcDbBlockTable *pBlockTable;
Acad::ErrorStatus es;
AcApDocument* pDoc = acDocManager->curDocument();
es = acDocManager->lockDocument(pDoc);
if (es != Acad::eOk)
ads_alert(_T("Failed to lock the document!"));
AcDbDatabase* pDb = pDoc->database();
es = pDb->getBlockTable(pBlockTable, AcDb::kForRead);
if (es != Acad::eOk)
{
ads_alert(_T("Failed to get block table!"));
return NULL;
}
if (!pDb) return NULL;
AcDbBlockTable* pTbl = NULL;
es = pDb->getBlockTable(pTbl, AcDb::kForRead);
if (es != Acad::eOk) return NULL;
es = pTbl->getAt(ACDB_MODEL_SPACE, Blok, mode);
pTbl->close();
if (es != Acad::eOk) return NULL;
return Blok;
}
Acad::ErrorStatus MoveCreatedCircle()
{
AcDbBlockTableRecord* Blok = NULL;
AcDbObjectId id;
Acad::ErrorStatus es;
AcGePoint3d cntr(0, 0, 0);
ads_real r = 3;
AcGeVector3d ptMove(20, 20, 0);
AcDbCircle* pCirEnt = new AcDbCircle();
pCirEnt->setCenter(cntr);
pCirEnt->setRadius(r);
if (!pCirEnt) return Acad::eNullEntityPointer;
Acad::ErrorStatus es;
if (!Blok)
{
Blok = getModelSpace(AcDb::kForWrite);
if (!Blok) return Acad::eInvalidOwnerObject;
}
if (Blok->isWriteEnabled() == Adesk::kFalse)
{
AcDbObject* pObj = NULL;
es = acdbOpenObject(pObj, Blok->objectId(), AcDb::kForWrite);
Blok = AcDbBlockTableRecord::cast(pObj);
}
//if ((es = Blok->appendAcDbEntity(pCirEnt)) != Acad::eOk)
Blok->close();
id = pCirEnt->objectId();
es = pCirEnt->close();
// Хочется передвинуть круг уже после закрытия
// повторно "открыв" этот объект / сущность
//open the selected entity
AcDbEntity *pEntity2 = NULL;
if (acdbOpenAcDbEntity(pEntity2, id, AcDb::kForRead) != Acad::eOk)
return es;
//AcDbPolyline *pPline = AcDbPolyline::cast(pEntity2);
AcDbCircle *pSameCirc = AcDbCircle::cast(pEntity2);
if (pSameCirc == NULL)
return es;
AcGeMatrix3d mat;
mat.setToTranslation(AcGeVector3d(ptMove[X], ptMove[Y], ptMove[Z]));
pSameCirc->transformBy(mat);
es = pSameCirc->close();
}