Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I want to add count to an attribute in an block that is in an array. Is it possible?
I tried to use the AssocArray as BlockReference and then get the BlockTableRecord to iterate over the blocks, but does not work. the BTR has no objectIds to iterate over.
I know the position can be changed, so I'm wondering if this is possible as well.
This is the way I have tried.
Thanks in advance for any help.
string blockName = "T";
string tag = "TESTATT";
using (Transaction tr = Active.Document.TransactionManager.StartUndoGroupTransaction())
{
try
{
BlockTable bt = (BlockTable)tr.GetObject(Active.Database.BlockTableId, OpenMode.ForRead);
BlockTableRecord modelSpace = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
BlockReference br = BlockOperations.InsertBlock(tr, bt, modelSpace, blockName, Point3d.Origin);
br.SetAttributeValue(tr, tag, "Original");
BlockTableRecord btRec = (BlockTableRecord)tr.GetObject(br.BlockTableRecord, OpenMode.ForRead);
foreach (ObjectId id in btRec)
{
Active.Editor.WriteMessage(id.ToString());
}
AssocArrayRectangularParameters param = new AssocArrayRectangularParameters(100, 100, 0, 10, 10, 0, 0, 0);
VertexRef verref = new VertexRef(br.Position);
AssocArray array = AssocArray.CreateArray(new ObjectIdCollection { br.ObjectId }, verref, param);
BlockReference arrayBlock = (BlockReference)tr.GetObject(array.EntityId, OpenMode.ForWrite);
BlockTableRecord arrayBT = (BlockTableRecord)tr.GetObject(arrayBlock.BlockTableRecord, OpenMode.ForWrite);
foreach (ObjectId id in arrayBT)
{
BlockReference item = (BlockReference)tr.GetObject(id, OpenMode.ForWrite);
item.SetAttributeValue(tr, tag, "Array");
}
tr.Commit();
}
catch (System.Exception ex)
{
Active.WriteError(ex.Message);
tr.Abort();
}
}
Solved! Go to Solution.