|
[code]//////////////////////////////////////////////////////////////////////////
// 08/14/2012
// By Philippe Leefsma
// How to access and modify a DynamicBlockReference property in ARX and .Net?
static void xlMyGroupTest98()
{
ads_name ename;
ads_point pt;
if (acedEntSel(L"\nSelect a dynamic block reference: ", ename, pt) != RTNORM)
{
acutPrintf(L"\nError selecting entity.");
return;
}
AcDbObjectId eId;
acdbGetObjectId(eId, ename);
AcDbEntity* pEnt = NULL;
if (acdbOpenObject(pEnt, eId, AcDb::kForRead) != Acad::eOk)
{
acutPrintf(L"\nError opening entity.");
if (pEnt)
pEnt->close();
return;
}
if (pEnt->isA() != AcDbBlockReference::desc())
{
acutPrintf(L"\nMust select a block insert.");
pEnt->close();
return;
}
AcDbBlockReference *pBlkRef = AcDbBlockReference::cast(pEnt);
// initialise a AcDbDynBlockReference from the object id of the blockreference
AcDbDynBlockReference* pDynBlkRef = new AcDbDynBlockReference(pBlkRef->objectId());
//Don't forget to close the blockreference here, otherwise you wont be able to modify properties
pEnt->close();
if (pDynBlkRef)
{
AcDbDynBlockReferencePropertyArray blkPropAry;
pDynBlkRef->getBlockProperties(blkPropAry);
Acad::ErrorStatus err;
AcDbDynBlockReferenceProperty blkProp;
for (long lIndex1 = 0L; lIndex1 < blkPropAry.length(); ++lIndex1)
{
blkProp = blkPropAry[lIndex1];
//look for the relevant property
if (wcscmp(blkProp.propertyName().kACharPtr(), L"Visibility") != 0) continue;
//Get allowed values for property
AcDbEvalVariantArray evalAry;
if ((err = blkProp.getAllowedValues(evalAry)) == Acad::eOk)
{
if (evalAry.length() >= 1)
{
AcDbEvalVariant eval = evalAry[1];
if (!blkProp.readOnly())
{
if ((err = blkProp.setValue(eval)) != Acad::eOk)
{
acutPrintf(L"\nError setting property value...");
}
}
}
}
}
//Don't forget to delete this reference, otherwise you will have problems.
delete pDynBlkRef;
}
}[/code] |
|