// blockId - ObjectId блока для вставки (получить можно, например, в результате работы функции importBlockToCurDWGDatabase)
// basePointUCS - точка вставки блока в пользовательской системе координат
// scale - масштаб для текущей вставки
// на возврат ID вставки блока из БД чертежа
AcDbObjectId addBlockToCurDWG (AcDbObjectId blockId, AcGePoint3d basePointUCS, double scale)
{
bool haveToDel = false;
Acad::ErrorStatus es;
AcDbObjectId newEntId; newEntId.setNull();
AcDbBlockReference *pBlkRef =new AcDbBlockReference(basePointUCS,blockId) ;
pBlkRef->setRotation(0.0);
pBlkRef->setNormal(AcGeVector3d (0.0, 0.0, 1.0));
pBlkRef->setScaleFactors(AcGeScale3d(scale));
newEntId = postToDb(pBlkRef);
AcDbObjectPointer<AcDbBlockReference> pAddedEnt(newEntId,AcDb::kForWrite);
if (pAddedEnt.openStatus () != Acad::eOk) return NULL;
AcDbBlockTableRecord * pBlockDef;
acdbOpenObject(pBlockDef, blockId, AcDb::kForRead);
AcDbBlockTableRecordIterator * pIterator;
pBlockDef->newIterator(pIterator);
AcDbEntity * pEnt;
AcDbAttributeDefinition * pAttdef;
for ( pIterator->start(); !pIterator->done(); pIterator->step() )
{
pIterator->getEntity(pEnt, AcDb::kForRead);
pAttdef =AcDbAttributeDefinition::cast(pEnt);
if ( pAttdef != NULL && !pAttdef->isConstant () )
{
AcDbAttribute * pAtt = new AcDbAttribute;
es = pAtt->setAttributeFromBlock(pAttdef,pBlkRef->blockTransform());
ACHAR *pStr = pAttdef->tag();
pAtt->setTag(pStr);
pAtt->setFieldLength(pAttdef->fieldLength());
ACHAR *pPrompt = pAttdef->prompt();
CString pDefValue = pAttdef->textStringConst();
ACHAR promptStr[255]; _tcsncpy(promptStr,_T("\0"),255);
_tcscpy(promptStr,_T("\n"));
_tcscat(promptStr,pPrompt);
if (!pDefValue.IsEmpty())
{
_tcscat(promptStr,_T(" <"));
_tcscat(promptStr,pDefValue.GetString());
_tcscat(promptStr,_T(">"));
}
_tcscat(promptStr,_T(": "));
ACHAR txtStr[255];
int ret = acedGetString(TRUE,promptStr, txtStr);
if (RTNORM == ret)
{
if (_tcslen(txtStr) > 0)
pAtt->setTextString(txtStr);
else
pAtt->setTextString(pDefValue.GetString());
}
else if (RTNONE == ret)
pAtt->setTextString(pDefValue.GetString());
else haveToDel = true;
delete pStr;
delete pPrompt;
AcDbObjectId attId;
pAddedEnt->appendAttribute(attId, pAtt);
pAtt->close();
}
pEnt->close();
}
delete pIterator;
pBlockDef->close();
AcGeMatrix3d matUcs;
acedGetCurrentUCS(matUcs);
pAddedEnt->transformBy(matUcs);
pAddedEnt->downgradeOpen();
pAddedEnt->close();
if (haveToDel)
{
deleteEntities(newEntId);
newEntId.setNull();
}
return newEntId;
}