Как вариант:
static void AddLinesFromOtherDWG(void)
{
resbuf *result = NULL;
result = acutNewRb(RTSTR);
result->resval.rstring = NULL;
Acad::ErrorStatus es = Acad::eOk;
ACHAR *fname = NULL;
if (acedGetFileD(_T("Select file:"), NULL, _T("dwg"), 0, result) == RTNORM) {
fname = acad__strdup(result->resval.rstring); acutRelRb(result);
} else {
acutRelRb(result);
return;
}
AcDbDatabase *db = new AcDbDatabase();
if ((es = db->readDwgFile(fname,_SH_DENYNO)) != Acad::eOk) {
acutPrintf(_T("\nError open database <%s> with error %s!"),fname, acadErrorStatusText(es));
delete db;
return;
}
AcDbObjectIdArray ids;
{
AcDbBlockTablePointer pBlk(db,AcDb::kForRead);
if (pBlk.openStatus() == Acad::eOk) {
AcDbBlockTableRecordPointer pBlkRec(ACDB_MODEL_SPACE,db,AcDb::kForRead);
if (pBlkRec.openStatus() == Acad::eOk) {
AcDbBlockTableRecordIterator *pIter = NULL;
if (pBlkRec->newIterator(pIter) == Acad::eOk && pIter) {
for (;!pIter->done();pIter->step()) {
AcDbObjectId id;
if (pIter->getEntityId(id) == Acad::eOk) {
AcDbObjectPointer<AcDbLine> pLine(id,AcDb::kForRead);
if (pLine.openStatus() == Acad::eOk) {
if (pLine->colorIndex() != 2) // Цвет не 2 - пропускаем
continue;
AcDbLayerTableRecordPointer pLay(pLine->layerId(),AcDb::kForRead);
if (pLay.openStatus() == Acad::eOk) {
const ACHAR *pLayName = NULL;
if (pLay->getName(pLayName) == Acad::eOk) {
if (AcString(pLayName).compareNoCase(AcString(_T("1")))) // Слой не 1 - пропускаем
continue;
ids.append(id);
}
}
}
}
}
}
}
}
}
if (ids.length() > 0) {
AcDbIdMapping idMap;
idMap.setDestDb(acdbCurDwg());
Acad::ErrorStatus es;
if ((es = db->wblockCloneObjects(ids,acdbCurDwg()->currentSpaceId(),idMap,AcDb::kDrcReplace)) != Acad::eOk) {
acutPrintf(_T("\nes=%s"),acadErrorStatusText(es));
}
}
delete db;
}