> tati
Ну тогда попробуй такой код:
static void CPBLOCK(void)
{
resbuf *result = NULL;
result = acutNewRb(RTSTR);
result->resval.rstring = NULL;
Acad::ErrorStatus es = Acad::eOk;
ACHAR filepath[_MAX_PATH];
if (acedGetFileD("Select file:", NULL, "dwg", 0, result) == RTNORM) {
strcpy(filepath,result->resval.rstring); acutRelRb(result);
} else {
acutRelRb(result);
return;
}
AcDbDatabase *db = new AcDbDatabase();
if ((es = db->readDwgFile(filepath,_SH_DENYNO)) != Acad::eOk) {
acutPrintf("\nError open database <%s> with error %s!",filepath, acadErrorStatusText(es));
delete db;
return;
}
ACHAR path_buffer[_MAX_PATH],drive[_MAX_DRIVE],dir[_MAX_DIR],fname[_MAX_FNAME],ext[_MAX_EXT];
_splitpath(filepath,drive,dir,fname,ext);
AcDbIdMapping idMap; idMap.setDestDb(acdbCurDwg());
AcDbObjectId idBTR_new;
AcDbObjectIdArray ids;
if (acdbSNValid(fname,FALSE) == RTNORM) {
AcDbBlockTableRecordPointer pBTR(ACDB_MODEL_SPACE,db,AcDb::kForRead);
if (pBTR.openStatus() == Acad::eOk) {
AcDbBlockTableRecordIterator *pIter = NULL; pBTR->newIterator(pIter);
if (pIter) {
for (pIter->start();!pIter->done(); pIter->step()) {
AcDbObjectId id;
if (pIter->getEntityId(id) == Acad::eOk) {
ids.append(id);
}
}
delete pIter;
}
}
AcDbBlockTableRecord *pBTR_new = new AcDbBlockTableRecord();
pBTR_new->setName(fname);
pBTR_new->setOrigin(db->insbase());
AcDbBlockTablePointer pBT(acdbCurDwg(),AcDb::kForWrite);
if (pBT.openStatus() == Acad::eOk) {
if (!pBT->has(fname)) {
pBT->add(idBTR_new,pBTR_new);
pBTR_new->close();
}
} else {
delete pBTR_new;
}
} else {
acedAlert("Invalid file name - can not be set as block name!!!");
}
if (idBTR_new.isValid() && ids.length() > 0) {
if ((es = db->wblockCloneObjects(ids,idBTR_new,idMap,AcDb::kDrcReplace)) != Acad::eOk) {
acutPrintf("\nError copy block definition <%s> with error %s!",fname,acadErrorStatusText(es));
}
} else {
acedAlert("Can not copy block definition!!!");
}
delete db;
}