현재 열려진 Database를 사용하지 않고.
임의의 Database를 생성하여 블럭을 만들 Entity들을 추가한 후 블럭을 만든다.
이런 방법을 사용하면 현재의 Drawing,에 Entity들을 그리지 않고서도 블럭을 만들기가 가능합니다.
| void Command_Block() |
| { |
| AcDbDatabase* pDatabase = new AcDbDatabase; |
| |
| AcGePoint3d ptStart; |
| ptStart.x = ptStart.y = ptStart.z = 0; |
| AcGePoint3d ptEnd; |
| ptEnd.x = ptEnd.y = ptEnd.z = 100; |
| |
| AcDbLine* pLine = new AcDbLine(ptStart , ptEnd); |
| AcDbBlockTable *pBlockTable; |
| Acad::ErrorStatus es; |
| es = pDatabase->getBlockTable(pBlockTable, AcDb::kForRead); |
| if (es != Acad::eOk) |
| { |
| ads_alert("Failed to get the block table!"); |
| pBlockTable->close(); |
| return; |
| } |
| |
| AcDbBlockTableRecord *pBlockRec; |
| es = pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockRec, AcDb::kForWrite); |
| if (es != Acad::eOk) |
| { |
| ads_alert("Failed to get the block table record!"); |
| pBlockRec->close(); |
| return; |
| } |
| |
| AcDbObjectId retId; |
| if(pBlockRec->appendAcDbEntity(retId, pLine) != Acad::eOk) |
| { |
| ads_alert("Can't add entity to the blockTableRecord!"); |
| pBlockRec->close(); |
| return; |
| } |
| |
| AcDbObjectIdArray ids; |
| ids.append(pLine->objectId()); |
| pLine->close(); |
| |
| es = pBlockTable->close(); |
| assert(es == Acad::eOk); |
| es = pBlockRec->close(); |
| assert(es == Acad::eOk); |
| |
| AcGePoint3d basePoint; |
| basePoint.x = basePoint.y = basePoint.z = 100; |
| AcDbDatabase* pOutput = NULL; |
| pDatabase->wblock(pOutput , ids , basePoint); |
| |
| pOutput->saveAs("D:\\block.dwg"); |
| |
| delete pDatabase; |
| delete pOutput; |
| } |
댓글
댓글 쓰기