//--------------------------------------------------------------------------------------- // // 功能: 路线绘制回调函数 // // 输入参数: // AeccDisplayOrientation &viewMode // IAeccAlignment *pAlign // IAcadBlock *pAnonymousBlock // // 返回值:bool // // 作 者: // // 日期: 2007/08 // // 修改记录:无 // //--------------------------------------------------------------------------------------- bool customAlignmentDraw(const AeccDisplayOrientation &viewMode, IAeccAlignment *pAlign, IAcadBlock *pAnonymousBlock ) { AcDbBlockTableRecord* blkRec; CString strName; CComBSTR bstrName; pAnonymousBlock->get_Name( &bstrName); strName = bstrName; AcDbBlockTable* blkTbl; AcDbDatabase* pDb = acdbCurDwg(); Acad::ErrorStatus es = pDb->getSymbolTable(blkTbl, AcDb::kForRead); if (es != Acad::eOk){ return false; } //// open named block es = blkTbl->getAt(strName, blkRec, AcDb::kForWrite); acutPrintf(_T("\nget block")); if (es != Acad::eOk) { blkTbl->close(); // doesn't need to be open anymore return false; } blkTbl->close(); // doesn't need to be open anymore CComQIPtr <IAeccAlignmentEntities> pAlignEntities; CComQIPtr <IAeccAlignmentEntity> pAlignEnt; CComQIPtr<IAeccAlignmentArc> pAlignArc; long iCount; pAlign->get_Entities(&pAlignEntities); if (pAlignEntities != NULL) { pAlignEntities->get_Count(&iCount); for (long i = 0; i < iCount; i++) { pAlignEnt.Release(); pAlignEntities->Item(_variant_t(i), &pAlignEnt); pAlignArc.Release(); pAlignArc = pAlignEnt; if (pAlignArc != NULL) { double radius; pAlignArc->get_Radius(&radius); //acutPrintf(_T("\nRadius: %f", radius)); if (radius < 200) { double x; double y; double dStart; double dEnd; pAlignArc->get_StartingStation(&dStart); pAlignArc->get_EndingStation(&dEnd); for (double delta = dStart; delta < dEnd; delta += 3.0) { pAlign->PointLocation(delta, 0.0, &x, &y); AcGePoint3d pt(x,y,0); AcDbCircle* cir = new AcDbCircle(pt, AcGeVector3d::kZAxis, 5.0); cir->setColorIndex (1, Adesk::kTrue); blkRec->appendAcDbEntity(cir); cir->close(); } } } } } blkRec->close(); return (true) ; }
Acad::ErrorStatus createBlockRecord(/*[in]*/const char* name) { AcDbCircle* pFace = NULL; AcDbCircle* pLeftEye = NULL; AcDbCircle* pRightEye = NULL; AcDbArc* pMouth = NULL; AcDbBlockTable* pBlockTable = NULL; AcDbBlockTableRecord* pBlockTableRecord = NULL; try { // First, check if a block of the same name already exists // by verifying in the current database block table. // // Open the block table for read // ARXOK(acdbCurDwg()->getBlockTable(pBlockTable, AcDb::kForRead)); 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. // pBlockTableRecord = new AcDbBlockTableRecord(); if (!pBlockTableRecord) throw Acad::eOutOfMemory; 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 // ARXOK(pBlockTable->upgradeOpen()); // Add the new block table record to the block table. // For now, the block table record is empty. // ARXOK(pBlockTable->add(pBlockTableRecord)); pBlockTable->close(); pBlockTable = NULL; // 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) // pFace = new AcDbCircle(AcGePoint3d::kOrigin, AcGeVector3d::kZAxis, 1.0); pLeftEye = new AcDbCircle(AcGePoint3d(0.33, 0.25, 0.0), AcGeVector3d::kZAxis, 0.1); pRightEye = new AcDbCircle(AcGePoint3d(-0.33, 0.25, 0.0), AcGeVector3d::kZAxis, 0.1); pMouth = new AcDbArc(AcGePoint3d(0, 0.5, 0), 1.0, PI + (PI * 0.3), PI + (PI * 0.7)); if (!pFace || !pLeftEye || !pRightEye || !pMouth) { delete pFace; delete pLeftEye; delete pRightEye; delete pMouth; throw Acad::eOutOfMemory; } // Set the color property. // pFace->setColorIndex(2); pLeftEye->setColorIndex(5); pRightEye->setColorIndex(5); pMouth->setColorIndex(1); ARXOK(pBlockTableRecord->appendAcDbEntity(pFace)); ARXOK(pBlockTableRecord->appendAcDbEntity(pLeftEye)); ARXOK(pBlockTableRecord->appendAcDbEntity(pRightEye)); ARXOK(pBlockTableRecord->appendAcDbEntity(pMouth)); pFace->close(); pLeftEye->close(); pRightEye->close(); pMouth->close(); pBlockTableRecord->close(); return Acad::eOk; } catch(const Acad::ErrorStatus es) { if(pBlockTable) pBlockTable->close(); if(pBlockTableRecord) // if the id is NULL, it means that the object // is not in the database and that we can sefely delete it if(pBlockTableRecord->objectId() == AcDbObjectId::kNull) delete pBlockTableRecord; else { pBlockTableRecord->erase(); pBlockTableRecord->close(); } if(pFace) if(pFace->objectId() == AcDbObjectId::kNull) delete pFace; else pFace->close(); if(pLeftEye) if(pLeftEye->objectId() == AcDbObjectId::kNull) delete pLeftEye; else pLeftEye->close(); if(pRightEye) if(pRightEye->objectId() == AcDbObjectId::kNull) delete pRightEye; else pRightEye->close(); if(pMouth) if(pMouth->objectId() == AcDbObjectId::kNull) delete pMouth; else pMouth->close(); return es; } }
void defineBlockWithAttributes( AcDbObjectId& blockId, // This is a returned value. const AcGePoint3d& basePoint, double textHeight, double textAngle) { int retCode = 0; AcDbBlockTable *pBlockTable = NULL; AcDbBlockTableRecord* pBlockRecord = new AcDbBlockTableRecord; AcDbObjectId entityId; // Step 1: Set the block name and base point of the block definition // pBlockRecord->setName("ASDK-BLOCK-WITH-ATTR"); pBlockRecord->setOrigin(basePoint); // Open the block table for write. // acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pBlockTable, AcDb::kForWrite); // Step 2: Add the block table record to block table. // pBlockTable->add(blockId, pBlockRecord); // Step 3: Create a circle entity. // AcDbCircle *pCircle = new AcDbCircle; pCircle->setCenter(basePoint); pCircle->setRadius(textHeight * 4.0); pCircle->setColorIndex(3); // Append the circle entity to the block record. // pBlockRecord->appendAcDbEntity(entityId, pCircle); pCircle->close(); // Step 4: Create an attribute definition entity. // AcDbAttributeDefinition *pAttdef = new AcDbAttributeDefinition; // Set the attribute definition values. // pAttdef->setPosition(basePoint); pAttdef->setHeight(textHeight); pAttdef->setRotation(textAngle); pAttdef->setHorizontalMode(AcDb::kTextLeft); pAttdef->setVerticalMode(AcDb::kTextBase); pAttdef->setPrompt("Prompt"); pAttdef->setTextString("DEFAULT"); pAttdef->setTag("Tag"); pAttdef->setInvisible(Adesk::kFalse); pAttdef->setVerifiable(Adesk::kFalse); pAttdef->setPreset(Adesk::kFalse); pAttdef->setConstant(Adesk::kFalse); pAttdef->setFieldLength(25); // Append the attribute definition to the block. // pBlockRecord->appendAcDbEntity(entityId, pAttdef); // The second attribute definition is a little easier // because we are cloning the first one. // AcDbAttributeDefinition *pAttdef2 = AcDbAttributeDefinition::cast(pAttdef->clone()); // Set the values which are specific to the // second attribute definition. // AcGePoint3d tempPt(basePoint); tempPt.y -= pAttdef2->height(); pAttdef2->setPosition(tempPt); pAttdef2->setColorIndex(1); // Red pAttdef2->setConstant(Adesk::kTrue); // Append the second attribute definition to the block. // pBlockRecord->appendAcDbEntity(entityId, pAttdef2); pAttdef->close(); pAttdef2->close(); pBlockRecord->close(); pBlockTable->close(); return; }