- 积分
- 334
- 明经币
- 个
- 注册时间
- 2003-7-17
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2004-5-21 20:36:00
|
显示全部楼层
Acad::ErrorStatus createBlockRecord (const char *name) { // First, check if a block of the same name already exists // by verifying in the current database block table. AcDbBlockTable *pBlockTable ; // Open the block table for read Acad::ErrorStatus es ; if ( (es =acdbHostApplicationServices ()->workingDatabase ()->getBlockTable (pBlockTable, AcDb::kForRead)) != Acad::eOk ) return (es) ;
if ( pBlockTable->has (name) == Adesk::kTrue ) { pBlockTable->close () ; return (Acad::eDuplicateKey) ; } // Now we know the block does not exist, so we create it // using the name passed in. AcDbBlockTableRecord *pBlockTableRecord =new AcDbBlockTableRecord ; pBlockTableRecord->setName (name) ; // To keep it simple, we use the origin for the insertion point pBlockTableRecord->setOrigin (AcGePoint3d::kOrigin) ; // Open the block table for write // since we are adding a new block definition if ( (es =pBlockTable->upgradeOpen ()) != Acad::eOk ) { delete pBlockTableRecord ; pBlockTable->close () ; return (es) ; } // Add the new block table record to the block table. // For now, the block table record is empty. if ( (es =pBlockTable->add (pBlockTableRecord)) != Acad::eOk ) { // The block table record has not been added // to the block table, so we have to delete it. pBlockTable->close(); delete pBlockTableRecord; return (es) ; } pBlockTable->close () ; // Now the block table record is in the database, but is empty // (has no sub-entity). // Note that after having been added to the database, an object or an entity // is implicitely opened for write. // // So we create the sub entities to append to the block // which will represent a "happy face": // the block should consist of a round yellow face (circle) // two blue eyes (circles) and a red mouth (arc) AcDbCircle *pFace =new AcDbCircle (AcGePoint3d::kOrigin, AcGeVector3d::kZAxis, 1.0) ; AcDbCircle *pLeftEye =new AcDbCircle (AcGePoint3d (0.33, 0.25, 0.0), AcGeVector3d::kZAxis, 0.1) ; AcDbCircle *pRightEye =new AcDbCircle (AcGePoint3d (-0.33, 0.25, 0.0), AcGeVector3d::kZAxis, 0.1) ; AcDbArc *pMouth =new AcDbArc (AcGePoint3d (0, 0.5, 0), 1.0, 3.141592 + (3.141592 * 0.3), 3.141592 + (3.141592 * 0.7)) ; // Set the color property. pFace->setColorIndex (2) ; pLeftEye->setColorIndex (5) ; pRightEye->setColorIndex (5) ; pMouth->setColorIndex (1) ; // add the entities to the new block table record if ( (es =pBlockTableRecord->appendAcDbEntity (pFace)) != Acad::eOk ) { delete pFace ; delete pLeftEye ; delete pRightEye ; delete pMouth ; pBlockTableRecord->erase () ; pBlockTableRecord->close () ; return (es) ; } pFace->close () ;
if ( (es =pBlockTableRecord->appendAcDbEntity (pLeftEye)) != Acad::eOk ) { delete pLeftEye ; delete pRightEye ; delete pMouth ; pBlockTableRecord->erase () ; pBlockTableRecord->close () ; return (es) ; } pLeftEye->close () ;
if ( (es =pBlockTableRecord->appendAcDbEntity (pRightEye)) != Acad::eOk ) { delete pRightEye ; delete pMouth ; pBlockTableRecord->erase () ; pBlockTableRecord->close () ; return (es) ; } pRightEye->close () ;
if ( (es =pBlockTableRecord->appendAcDbEntity (pMouth)) != Acad::eOk ) { delete pMouth ; pBlockTableRecord->erase () ; pBlockTableRecord->close () ; return (es) ; } pMouth->close () ;
pBlockTableRecord->close () ;
return (Acad::eOk) ; }
插入块 输入块的名称
void insrtBlk() { char blkName[50]; AcDbDatabase *pCurDb; AcDbBlockTable *pBlkTable; AcDbBlockTableRecord *pBlkTableRecord; AcDbBlockReference *pInsrtObj; AcDbObjectId blkId;
AcGePoint3d insPt;
int retCode;
retCode = acedGetString(0, "\nEnter Block Name: ", blkName); if(retCode != RTNORM || blkName[0] == '\0') { acutPrintf("\nInvalid block name."); return; }
pCurDb = acdbHostApplicationServices()->workingDatabase();
// Check to see if the block table // has blkName
pCurDb->getBlockTable(pBlkTable, AcDb::kForRead); if(!pBlkTable->has(blkName)) { acutPrintf("\nBlock definition %s not found. ", blkName); pBlkTable->close(); return; }
// Get the AcDbObjectId of the block // definition. pBlkTable->getAt(blkName, blkId);
pBlkTable->getAt(ACDB_MODEL_SPACE, pBlkTableRecord, AcDb::kForWrite); pBlkTable->close(); acedInitGet(RSG_NONULL, NULL); acedGetPoint(NULL, "\nPick insertion point: ", asDblArray(insPt));
pInsrtObj = new AcDbBlockReference(insPt, blkId);
// Here is where you can set scale, rotation and other // properties to the block entity. If you want to // see the AcDbBlockReference class for more details.
pBlkTableRecord->appendAcDbEntity(blkId, pInsrtObj);
pBlkTableRecord->close(); pInsrtObj->close(); } |
|