trouble copying entities using ARX

trouble copying entities using ARX

Anonymous
Not applicable
317 Views
2 Replies
Message 1 of 3

trouble copying entities using ARX

Anonymous
Not applicable
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;


}
0 Likes
318 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
"garrett beaubien" wrote:

> Hello,
Hi Garrett,

[...]
Before adding the entity to the new database, clone it:

AcDbEntity *pEntSeed = AcDbEntity::cast(pEntBlock->clone());
if (pEntSeed)
{
pBlkTblRcdSeed->appendAcDbEntity(pEntSeed);
pEntSeed->close();
}
>
> //add entity to seed database (will be new dwg later)
> pBlkTblRcdSeed->appendAcDbEntity(pEntBlock);
> pEntBlock->close();
> }
>
[...]

HTH
Arnold
0 Likes
Message 3 of 3

Anonymous
Not applicable
You may want to consider using a deepclone operation, rather than a
clone( ). For complex objects, the clone( ) operation will not be
sufficient.

-Rich


"Arnold Eibel" wrote in message
news:Xns92655EF9CCA1Aeibel@ID-45990.user.dfncis.de...
> "garrett beaubien" wrote:
>
> > Hello,
> Hi Garrett,
>
> [...]
> Before adding the entity to the new database, clone it:
>
> AcDbEntity *pEntSeed = AcDbEntity::cast(pEntBlock->clone());
> if (pEntSeed)
> {
> pBlkTblRcdSeed->appendAcDbEntity(pEntSeed);
> pEntSeed->close();
> }
> >
> > //add entity to seed database (will be new dwg later)
> > pBlkTblRcdSeed->appendAcDbEntity(pEntBlock);
> > pEntBlock->close();
> > }
> >
> [...]
>
> HTH
> Arnold
0 Likes