Message 1 of 3
trouble copying entities using ARX

Not applicable
08-08-2002
02:26 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I'm trying to write some code that will open 2 drawings (database objects),
iterate through one and retrieve all entities, and copy the entities into
the other database. Finally, the "merged" database would be saved into a
third file.
My code compiles and runs. It displays the entity type, and creates the
final drawing, but the final drawing is empty. Here is my code:
Thanks in advance for any help.
Garrett.
void asdkblock1()
{
// TODO: Implement the command
AcDbDatabase *pDbSeed = new AcDbDatabase(Adesk::kFalse);
AcDbDatabase *pDbBlock = new AcDbDatabase(Adesk::kFalse);
pDbSeed->readDwgFile("c:\\arxC\\dbtest1\\test1.dwg");
pDbBlock->readDwgFile("c:\\arxC\\dbtest1\\dbtext.dwg");
AcDbBlockTable *pBlkTblSeed;
AcDbBlockTable *pBlkTblBlock;
pDbSeed->getSymbolTable(pBlkTblSeed, AcDb::kForRead);
pDbBlock->getSymbolTable(pBlkTblBlock, AcDb::kForRead);
AcDbBlockTableRecord *pBlkTblRcdSeed;
AcDbBlockTableRecord *pBlkTblRcdBlock;
pBlkTblSeed->getAt(ACDB_MODEL_SPACE, pBlkTblRcdSeed, AcDb::kForWrite);
pBlkTblBlock->getAt(ACDB_MODEL_SPACE, pBlkTblRcdBlock, AcDb::kForRead);
pBlkTblSeed->close();
pBlkTblBlock->close();
AcDbBlockTableRecordIterator *pBlkTblRcdItrBlock;
pBlkTblRcdBlock->newIterator(pBlkTblRcdItrBlock);
AcDbEntity *pEntBlock;
for (pBlkTblRcdItrBlock->start(); !pBlkTblRcdItrBlock->done();
pBlkTblRcdItrBlock->step())
{
pBlkTblRcdItrBlock->getEntity(pEntBlock, AcDb::kForWrite);
acutPrintf("classname: %s\n", (pEntBlock->isA())->name());
// we have an entity. If text, changet text to NewText
if (pEntBlock->isA() == AcDbText::desc())
{
acutPrintf("text: %s\n", ((AcDbText*)(pEntBlock))->textString());
((AcDbText*)(pEntBlock))->setTextString("NewText");
}
//add entity to seed database (will be new dwg later)
pBlkTblRcdSeed->appendAcDbEntity(pEntBlock);
pEntBlock->close();
}
pBlkTblRcdSeed->close();
pBlkTblRcdBlock->close();
delete pBlkTblRcdItrBlock;
//save seed (with new entities) as new dwg
pDbSeed->saveAs("c:\\arxC\\dbtest1\\test2.dwg");
delete pDbSeed;
delete pDbBlock;
}
I'm trying to write some code that will open 2 drawings (database objects),
iterate through one and retrieve all entities, and copy the entities into
the other database. Finally, the "merged" database would be saved into a
third file.
My code compiles and runs. It displays the entity type, and creates the
final drawing, but the final drawing is empty. Here is my code:
Thanks in advance for any help.
Garrett.
void asdkblock1()
{
// TODO: Implement the command
AcDbDatabase *pDbSeed = new AcDbDatabase(Adesk::kFalse);
AcDbDatabase *pDbBlock = new AcDbDatabase(Adesk::kFalse);
pDbSeed->readDwgFile("c:\\arxC\\dbtest1\\test1.dwg");
pDbBlock->readDwgFile("c:\\arxC\\dbtest1\\dbtext.dwg");
AcDbBlockTable *pBlkTblSeed;
AcDbBlockTable *pBlkTblBlock;
pDbSeed->getSymbolTable(pBlkTblSeed, AcDb::kForRead);
pDbBlock->getSymbolTable(pBlkTblBlock, AcDb::kForRead);
AcDbBlockTableRecord *pBlkTblRcdSeed;
AcDbBlockTableRecord *pBlkTblRcdBlock;
pBlkTblSeed->getAt(ACDB_MODEL_SPACE, pBlkTblRcdSeed, AcDb::kForWrite);
pBlkTblBlock->getAt(ACDB_MODEL_SPACE, pBlkTblRcdBlock, AcDb::kForRead);
pBlkTblSeed->close();
pBlkTblBlock->close();
AcDbBlockTableRecordIterator *pBlkTblRcdItrBlock;
pBlkTblRcdBlock->newIterator(pBlkTblRcdItrBlock);
AcDbEntity *pEntBlock;
for (pBlkTblRcdItrBlock->start(); !pBlkTblRcdItrBlock->done();
pBlkTblRcdItrBlock->step())
{
pBlkTblRcdItrBlock->getEntity(pEntBlock, AcDb::kForWrite);
acutPrintf("classname: %s\n", (pEntBlock->isA())->name());
// we have an entity. If text, changet text to NewText
if (pEntBlock->isA() == AcDbText::desc())
{
acutPrintf("text: %s\n", ((AcDbText*)(pEntBlock))->textString());
((AcDbText*)(pEntBlock))->setTextString("NewText");
}
//add entity to seed database (will be new dwg later)
pBlkTblRcdSeed->appendAcDbEntity(pEntBlock);
pEntBlock->close();
}
pBlkTblRcdSeed->close();
pBlkTblRcdBlock->close();
delete pBlkTblRcdItrBlock;
//save seed (with new entities) as new dwg
pDbSeed->saveAs("c:\\arxC\\dbtest1\\test2.dwg");
delete pDbSeed;
delete pDbBlock;
}