Message 1 of 3
AcDbBlockReference + appendAcDbEntity
Not applicable
09-21-2007
01:19 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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();
}
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();
}