Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
static void MyGroupMyCommand () {
ads_name ss = { 0 };
int ret = acedSSGet(NULL, NULL, NULL, NULL, ss);
AcDbObjectIdArray ids;
if (RTNORM == ret)
{
long len = 0;
acedSSLength(ss, &len);
for (long i = 0L; i < len; ++i)
{
ads_name ename = { 0 };
acedSSName(ss, i, ename);
AcDbObjectId id = AcDbObjectId::kNull;
acdbGetObjectId(id, ename);
ids.append(id);
}
acedSSFree(ss);
}
CreateBlock1(_T("TTT"),ids,AcGeScale3d(1,1,1),0); // Create and Insert Blocks
AcDbObjectId AnonblockId ;
CreateAnonBlock(ids,AnonblockId);
}
static AcDbObjectId CreateBlock1(const CString &blkName, const AcDbObjectIdArray &idObjectArray,const AcGeScale3d &m_aScale,const double &m_angle)
{
AcDbBlockTable *pBlkTbl = NULL;
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl, AcDb::kForWrite);
AcDbBlockTableRecord *pBlkRcd = new AcDbBlockTableRecord();
pBlkRcd->setName(blkName);
AcDbObjectId blkDefId;
pBlkTbl->add(blkDefId, pBlkRcd);
pBlkTbl->close();
AcDbObjectId entId;
for (INT32 i = 0; i < idObjectArray.length(); i++)
{
AcDbEntity *pEntity = NULL;
acdbOpenAcDbEntity(pEntity, idObjectArray.at(i), AcDb::kForRead);
pBlkRcd->appendAcDbEntity(entId, pEntity);
}
pBlkRcd->close();
AcDbBlockReference *pBlkRef = new AcDbBlockReference(AcGePoint3d::kOrigin, entId);
pBlkRef->setScaleFactors(m_aScale);
PostToModelSpace(pBlkRef);
pBlkRef->setRotation (m_angle) ;
return entId;
}
static Acad::ErrorStatus CreateAnonBlock(AcArray<AcDbObjectId> &selectedIds, AcDbObjectId &idAnonBlock)
{
Acad::ErrorStatus es;
AcDbBlockTable *pBlockTable = NULL;
AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();
AcDbBlockTableRecord *pAnonBlock = NULL;
if( idAnonBlock == AcDbObjectId::kNull )
{
if ((es = pDb->getBlockTable(pBlockTable, AcDb::kForWrite))
!= Acad::eOk)
{
acutPrintf(L"Could not open block table 无法打开块表.\n");
return es;
}
AcDbBlockTableRecord* pAnonBlock = new AcDbBlockTableRecord;
if(!pAnonBlock)
{
acutPrintf(L"Could not create new block table record.无法创建新的块表记录\n");
return Acad::eNullObjectPointer;
}
if((es = pAnonBlock->setName(_T("*U"))) != Acad::eOk)
{
acutPrintf(L"Could not name anonymous block.无法命名匿名块\n");
return es;
}
if((es = pBlockTable->add(idAnonBlock, pAnonBlock)) != Acad::eOk)
{
acutPrintf(L"Could not add anonymous block to block table.无法将匿名块添加到块表\n");
return es;
}
if((es = pBlockTable->close()) != Acad::eOk)
{
acutPrintf(L"Could not close block table.\n");
return es;
}
if((es = pAnonBlock->close()) != Acad::eOk)
{
acutPrintf(L"Could not close block table record.\n");
return es;
}
}
AcDbObjectPointer<AcDbBlockTableRecord> pAnonBlockObjectPtr(idAnonBlock, AcDb::kForWrite);
if((es = pAnonBlockObjectPtr.openStatus()) != Acad::eOk)
{
acutPrintf(L"Could not open anonymous block.\n");
return es;
}
for(int cnt = 0; cnt < selectedIds.length(); cnt++)
{
AcDbObjectId entId = selectedIds.at(cnt);
AcDbObjectPointer<AcDbEntity> pEntity(entId, AcDb::kForRead);
if(Acad::eOk == pEntity.openStatus())
{
AcDbEntity *pCloneEnt = (AcDbEntity *) pEntity->clone();
if((es = pAnonBlockObjectPtr->appendAcDbEntity(pCloneEnt)) != Acad::eOk)
{
acutPrintf(L"Could not append entity to anonymous block.\n");
return es;
}
if((es = pCloneEnt->close()) != Acad::eOk)
{
acutPrintf(L"Could not close entity.\n");
return es;
}
}
}
return Acad::eOk;
}
Solved! Go to Solution.