AcDbBlockReference + appendAcDbEntity

AcDbBlockReference + appendAcDbEntity

Anonymous
Not applicable
815 Views
2 Replies
Message 1 of 3

AcDbBlockReference + appendAcDbEntity

Anonymous
Not applicable
Hi,

First I add a new Block. Than I add a Line to this Block. So now, I want that the Block is referenced from the MODEL_SPACE, what it also is a Block(TableRecord).
I try for two days now to solve this little problem. I have read posts about AcDbBlockReference in this forum, but I can't see the error. Because I want that, the Block is visible, to do so, the block must be drawn, but without refernce from the MODEL_SPACE, the BLock will not be drawn. I hope you understand my Problem.

// Get the block table.
//
AcDbBlockTable *pBlockTable = NULL;
acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTable, AcDb::kForWrite);
AcDbBlockTableRecord *pModelSpace = NULL;
pBlockTable->getAt(ACDB_MODEL_SPACE, pModelSpace, AcDb::kForWrite);

// Create and name a new block table record.
//
AcDbBlockTableRecord *pOrgaMainBlock = new AcDbBlockTableRecord();
pOrgaMainBlock->setName(_T("OrgaMainBlock"));

// Create a line
//
AcGePoint3d startPt(4.0, 2.0, 0.0);
AcGePoint3d endPt(10.0, 7.0, 0.0);
AcDbLine *pLine = new AcDbLine(startPt, endPt);

// add the line to the new block
//
pOrgaMainBlock->appendAcDbEntity(pLine);

// Add blockrecord to blocktable
//
AcDbObjectId blockId;
pBlockTable->add(blockId, pOrgaMainBlock);

// Create and name a new blockreference
//
AcGePoint3d insPt(0.0, 0.0, 0.0);
AcDbBlockReference *pBlockTableRef = new AcDbBlockReference(insPt, blockId);
pBlockTableRef->setBlockTableRecord(blockId);
pModelSpace->appendAcDbEntity(pBlockTableRef);

pModelSpace->close();
pBlockTable->close();
pLine->close();
pOrgaMainBlock->close();
}
0 Likes
816 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
You forgot to close the block reference. It's also a good idea to close objects as soon as you're done with them.

Regards,
Andy F.
0 Likes
Message 3 of 3

Anonymous
Not applicable
Great, thx a lot

that solved my problem 🙂 how could I forgot ^^

Regards
B.Bromisch
0 Likes