Hi Moky,
what i meant was somthg like this (after it you can explode the new insert):
BOOL InsertBlock(char* szname)
{
//the error checking is maybe a bit paranoid but it can't hurt
Acad::ErrorStatus es;
AcDbObjectId id;
AcDbBlockTable* pBlockTable;
//check if the block is in the database
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable,
AcDb::kForRead);
if(pBlockTable->has(szname) != Adesk::kTrue)
{
acutPrintf("ERROR: block %s doesn't exist.", szname);
pBlockTable->close();
return FALSE;
}
//get record ID of block szname
es = pBlockTable->getAt(szname, id);
pBlockTable->close();
if (es != Acad::eOk)
{
acutPrintf("Error opening block");
return FALSE;
}
//you should check here for attributes and act accordingly
//for simplicity's sake we assume the block has no attributes
//set data (either ask user or if preset pass it to the func)
//for instance:
AcGePoint3d pt(0.0, 0.0, 0.0); //insert pt
double sclX=1.0, sclY=1.0, sclZ=1.0;//block scale
double rot=0.0; //rotation angle
AcGeScale3d scale(sclX, sclY, sclZ);
//---allocate a block reference object
AcDbBlockReference *pBlkRef = new AcDbBlockReference;
if (pBlkRef == NULL)
{
acutPrintf("alloc error ");
return FALSE;
}
//---set up the block reference to the block definition ID and set
properties
es = pBlkRef->setBlockTableRecord(id);
if (es != Acad::eOk)
{
delete pBlkRef;
return FALSE;
}
es = pBlkRef->setPosition(pt);
if (es != Acad::eOk)
{
delete pBlkRef;
return FALSE;
}
es = pBlkRef->setRotation(rot);
if (es != Acad::eOk)
{
delete pBlkRef;
return FALSE;
}
es = pBlkRef->setScaleFactors(scale);
if (es != Acad::eOk)
{
delete pBlkRef;
return FALSE;
}
//---open current database's Model Space blockTableRecord
es =
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable,
AcDb::kForRead);
if (es != Acad::eOk)
{
delete pBlkRef;
return FALSE;
}
AcDbBlockTableRecord *pBlockTableRecord;
es = pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,
AcDb::kForWrite);
if (es != Acad::eOk)
{
delete pBlkRef;
pBlockTable->close();
return FALSE;
}
pBlockTable->close();
//---append the block reference to the model space block table record
AcDbObjectId newEntId;
es = pBlockTableRecord->appendAcDbEntity(newEntId, pBlkRef);
//subsequently you can use the new newEntId to explode it
pBlockTableRecord->close();
if (es != Acad::eOk)
{
delete pBlkRef;
acutPrintf"The insert operation failed.");
return FALSE;
}
pBlkRef->close();
return TRUE;
}