Erase attribute inside block

Erase attribute inside block

kebby70
Contributor Contributor
373 Views
3 Replies
Message 1 of 4

Erase attribute inside block

kebby70
Contributor
Contributor

I've erased attribute and correctlty erased.

but remained attribute inside block.(block edit)

Please See below code.

 

BlockReference blkRef = (BlockReference)acTrans.GetObject(blkId, OpenMode.ForWrite);

 

foreach (ObjectId attId in blkRef.AttributeCollection)
{
AttributeReference attRef = (AttributeReference)acTrans.GetObject(attId, OpenMode.ForWrite);

string tag = attRef.Tag.ToUpper();
string tagValue = attRef.TextString;

 if (attRef.Tag.StartsWith("test"))
{
attRef.Erase();
}
}

0 Likes
374 Views
3 Replies
Replies (3)
Message 2 of 4

hosneyalaa
Advisor
Advisor

Hi 

May add 

 

Comment ATTSYNC

0 Likes
Message 3 of 4

kebby70
Contributor
Contributor

Thanks hosneyalaa, 

 

1. Erase attribue inside the block

2. Correctlry erased on attribute window or current drawing.

2. But Explode or Enter the block, remained attribute.

3. Block is rollbacked because the block has erased attribute if use ATTSYNC, 

 

I'd like to erase attribute defination entity inside block.

0 Likes
Message 4 of 4

kebby70
Contributor
Contributor

I've solved to erase/rename attribute and it works for me.

 

foreach (ObjectId blkId in objectIds)
{
BlockReference blkRef = (BlockReference)acTrans.GetObject(blkId, OpenMode.ForRead);
BlockTable acBlkTbl = acTrans.GetObject(acDocDb.BlockTableId, OpenMode.ForRead, false, true) as BlockTable;
BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[blkRef.Name], OpenMode.ForRead, false, true) as BlockTableRecord;

foreach (ObjectId attId in blkRef.AttributeCollection)
{
AttributeReference attRef = (AttributeReference)acTrans.GetObject(attId, OpenMode.ForRead);

string tag = attRef.Tag.ToUpper();
if (tag.StartsWith("AAA_"))
{
attRef.UpgradeOpen();
attRef.Erase();
attRef.DowngradeOpen();
}
}

foreach (ObjectId id in acBlkTblRec)
{
DBObject obj = id.GetObject(OpenMode.ForRead);
AttributeDefinition attDef = obj as AttributeDefinition;

if (attDef != null && !attDef.Constant)
{
if (attDef.Tag.StartsWith("AAA_"))
{
attDef.UpgradeOpen();
attDef.Erase();
attDef.DowngradeOpen();
}
}
}

}

0 Likes