向块添加属性
大家好,我可以使用下面的代码向块(m_CurSpace)添加一行。
现在我还需要添加一个属性定义。
由于C++和ARX并不完全是我的一杯茶,我想知道是否有人可以向我展示一个如何向块添加属性定义的示例。
TIA,
Arno van Eeuwen
Acad::ErrorStatus CadDrawing::AddLine(const AcGePoint3d &p1, const AcGePoint3d &p2)
{
Acad::ErrorStatus es = Acad::eNullHandle;
if(NULL != m_pCurDb)
{
AcDbObjectPointer
line;
if ((es = line.create()) != Acad::eOk) 返回 es;
if ((es = line->setStartPoint(p1)) != Acad::eOk) return es;
if ((es = line->setEndPoint(p2)) != Acad::eOk) 返回 es;
返回 m_CurSpace->appendAcDbEntity(line));
}
返回 es;
}
**** Hidden Message ***** 我要出城了,如果其他人没有发布示例,我回来时会尝试。 一个简单的例子就可以了,或者提示一下在哪里可以找到这方面的文档。
期待您的回复。阿诺
以下是一个快速示例
typedef AcDbObjectPointer AcDbBlockReferencePointer;
static void ArxBlockSamp_doit(void)
{
TCHAR blockName; // alloc space for our blockname
AcDbObjectId btrId = AcDbObjectId::kNull ; // create a null ID
AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();
if(acedGetString(0,_T("\nEnter a Block Name: "),blockName) != RTNORM)
{
acdbFail( _T("@acedGetString"));
return;
}
//call helper to get the ID of block
if(getBlockTableRecordId(blockName,btrId,pDb) != eOk)
{
acdbFail( _T("@getBlockRecordId"));
return;
}
// smart pointer to block
AcDbBlockTableRecordPointer pBlockTableRecordPointer(btrId,AcDb::kForWrite);
if(pBlockTableRecordPointer.openStatus() != eOk)
{
acdbFail( _T("@pBlockTableRecordPointer.openStatus"));
return;
}
// a pointer to a new AcDbAttributeDefinition, I use a normal pointer
// here because I want to use the ctor & I want to use it later
AcDbAttributeDefinition *pAttributeDefinition =
new AcDbAttributeDefinition(pBlockTableRecordPointer->origin(),
_T("Text"), _T("Tag"), _T("Prompt"));
// add the new AcDbAttributeDefinition to block
if(pBlockTableRecordPointer->appendAcDbEntity(pAttributeDefinition) != eOk)
{
delete pAttributeDefinition;
acdbFail( _T("@pBlockTableRecordPointer->appendAcDbEntity"));
return;
}
pAttributeDefinition->downgradeOpen(); // make sure its readonly
AcDbObjectIdArray blockReferenceIds; // array to hold BlockReferenceIds
pBlockTableRecordPointer->getBlockReferenceIds(blockReferenceIds);
// helper to update BlockReferences
updateBlockReferences(blockReferenceIds, pAttributeDefinition );
pAttributeDefinition->close(); // clean up;
acutPrintf(_T("Ok!"));
}
static void updateBlockReferences(const AcDbObjectIdArray &blockReferenceIds,
AcDbAttributeDefinition *pAttributeDefinition)
{
for(int i = 0 ; i blockTransform();
AcDbAttribute *pAttribute =
new AcDbAttribute(pAttributeDefinition->position().transformBy(mat),
pAttributeDefinition->textStringConst(),
pAttributeDefinition->tagConst());
if(pBlockReferencePointer->appendAttribute(pAttribute)!= eOk)
{
delete pAttribute;
continue;
}
pAttribute->close();
}
}
static Acad::ErrorStatus getBlockTableRecordId(LPCTSTR name, AcDbObjectId &btrId,
AcDbDatabase *pDb)
{
Acad::ErrorStatus stat = eOk;
AcDbBlockTablePointer pBlocktable(pDb->blockTableId(), AcDb::kForRead);
stat = pBlocktable.openStatus();
if(stat != eOk)
return stat;
if(pBlocktable->has(name))
return pBlocktable->getAt(name,btrId);
else
return Acad::eNotInDatabase;
}
谢谢你丹尼尔。
这应该让我继续前进。
显然比添加线条要复杂一点......
阿诺
页:
[1]