arx DynamicBlock 有一个 “Visibility” 属性
void SetDynamicBlkProperty(){
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;
//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;
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;
}
}
Here is the C# version:
static public void SetDynamicBlkProperty()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptEntityOptions prEntOptions = new PromptEntityOptions(
"Select a dynamic block reference...");
PromptEntityResult prEntResult = ed.GetEntity(prEntOptions);
if (prEntResult.Status != PromptStatus.OK)
{
ed.WriteMessage("Error...");
return;
}
using(Transaction Tx = db.TransactionManager.StartTransaction())
{
BlockReference bref = Tx.GetObject(
prEntResult.ObjectId,
OpenMode.ForWrite)
as BlockReference;
if (bref.IsDynamicBlock)
{
DynamicBlockReferencePropertyCollection props =
bref.DynamicBlockReferencePropertyCollection;
foreach (DynamicBlockReferenceProperty prop in props)
{
object[] values = prop.GetAllowedValues();
//Switch Property
if (prop.PropertyName == "Visibility" && !prop.ReadOnly)
{
if (prop.Value.ToString() == values.ToString())
prop.Value = values;
else
prop.Value = values;
}
}
}
Tx.Commit();
}
}
页:
[1]