|
- AcDbObjectId cloneBlockRecord(AcDbObjectId from, char *to)
- {
- AcDbBlockTable *pBlockTable;
- AcDbBlockTableRecord *pBlockTableRecord;
- AcGePoint3d tempOrigin;
- AcDbObjectIdArray arrayId;
- AcDbBlockTableRecordIterator *pIter;
- AcDbObjectId objId, tableId, blockTargetId;
- AcDbDatabase *pDB;
- AcDbIdMapping idMap;
- char buffer[21];
- pDB = acdbHostApplicationServices()->workingDatabase();
- acdbOpenAcDbObject ((AcDbObject *&)pBlockTableRecord, from,
- AcDb::kForRead);
- tempOrigin = pBlockTableRecord->origin();
- pBlockTableRecord->newIterator(pIter);
- while (!pIter->done())
- {
- pIter->getEntityId(objId);
- arrayId.append(objId);
- pIter->step();
- }
- delete pIter ;
- tableId = pBlockTableRecord->ownerId();
- pBlockTableRecord->close();
- pDB->getBlockTable(pBlockTable, AcDb::kForRead);
- strcpy(buffer, to);
- if(pBlockTable->has(buffer))
- {
- for (int i = 0; i < 255; i++)
- {
- sprintf(buffer, "%s%d", to, i);
- if(!pBlockTable->has(buffer))
- {
- break;
- }
- }
- }
- pBlockTable->upgradeOpen ();
- pBlockTableRecord = new AcDbBlockTableRecord;
- pBlockTableRecord->setName(buffer);
- pBlockTableRecord->setOrigin(tempOrigin);
- pBlockTable->add(blockTargetId, pBlockTableRecord);
- pBlockTableRecord->close();
- pBlockTable->close();
- pDB->deepCloneObjects(arrayId, blockTargetId, idMap);
- return blockTargetId;
- }
复制代码 |
|