void createBlockWithEntities(OdDbDatabase* pDb, const OdString& blockName, const OdString& layerName) { try { OdDbLayerTablePtr pLayerTable = pDb->getLayerTableId().safeOpenObject(OdDb::kForWrite); OdDbLayerTableRecordPtr pLayer;
if (!pLayerTable->has(layerName)) { pLayer = OdDbLayerTableRecord::createObject(); pLayer->setName(layerName); pLayer->setColor(OdCmColor(OdCmEntityColor::kRed)); pLayer->setIsOff(false); pLayer->setIsFrozen(false); pLayer->setIsLocked(false); pLayerTable->add(pLayer); } else { pLayer = pLayerTable->getAt(layerName).safeOpenObject(OdDb::kForWrite); }
OdDbBlockTablePtr pBlockTable = pDb->getBlockTableId().safeOpenObject(OdDb::kForWrite); OdDbBlockTableRecordPtr pBlockRecord;
if (!pBlockTable->has(blockName)) { pBlockRecord = OdDbBlockTableRecord::createObject(); pBlockRecord->setName(blockName); pBlockTable->add(pBlockRecord); } else { pBlockRecord = pBlockTable->getAt(blockName).safeOpenObject(OdDb::kForWrite); }
OdDbLinePtr pLine = OdDbLine::createObject(); pLine->setStartPoint(OdGePoint3d(0, 0, 0)); pLine->setEndPoint(OdGePoint3d(100, 0, 0)); pLine->setLayer(layerName); pBlockRecord->appendOdDbEntity(pLine);
OdDbPolylinePtr pRect = OdDbPolyline::createObject(); pRect->setLayer(layerName); pRect->addVertexAt(0, OdGePoint2d(0, 0)); pRect->addVertexAt(1, OdGePoint2d(100, 0)); pRect->addVertexAt(2, OdGePoint2d(100, 50)); pRect->addVertexAt(3, OdGePoint2d(0, 50)); pRect->setClosed(true); pBlockRecord->appendOdDbEntity(pRect);
OdDb3dSolidPtr pBox = OdDb3dSolid::createObject(); pBox->setLayer(layerName); pBox->createBox(100, 50, 30); pBox->transformBy(OdGeMatrix3d::translation(OdGeVector3d(0, 0, 0))); pBlockRecord->appendOdDbEntity(pBox);
OdDbCirclePtr pCircle = OdDbCircle::createObject(); pCircle->setCenter(OdGePoint3d(50, 25, 0)); pCircle->setRadius(25); pCircle->setLayer(layerName); pBlockRecord->appendOdDbEntity(pCircle);
OdDbBlockTableRecordPtr pModelSpace = pDb->getModelSpaceId().safeOpenObject(OdDb::kForWrite); OdDbBlockReferencePtr pBlockRef = OdDbBlockReference::createObject(); pBlockRef->setBlockTableRecord(pBlockRecord->objectId()); pBlockRef->setPosition(OdGePoint3d(0, 0, 0)); pBlockRef->setLayer(layerName); pBlockRef->setScaleFactors(OdGeScale3d(1.0)); pBlockRef->setRotation(0.0); pModelSpace->appendOdDbEntity(pBlockRef); } catch (const OdError& e) { throw e; } }
void example() { OdDbDatabase* pDb = ; createBlockWithEntities(pDb, L"MyBlock", L"MyLayer"); }
|