- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Here is a quick background for what I am trying to do:
Essentially, I need to loop through and update a set of attributes which match the following set of requisites:
1. The AttributeCollection must contain a provided Tag name
2. The AttributeCollection must be a property on a BlockReference which matches a specific Block name
3. The AttributeCollection must be a property on a BlockReference which is a DynamicBlock
I believe I have issues 1 and 3 solved, but 2 is throwing me off. While looping through the BlockReferences, the BlockReference which contains the AttributeCollection does not have a Name which matches what is displayed in the Enhanced Attribute Editor. For example, the .NET code will report that the BlockReference.Name is something similar to *U16, and BlockReference.BlockName is *Model_Space, when the Enhanced Attribute Editor states that "Block: My_Expected_Block_Name". What I really need to do is tie the BlockReference back to "My_Expected_Block_Name".
Am I looking in the wrong spot for matching an AttributeCollection to a specific Block Name, or using the wrong properties? Any direction I can get would be helpful. I don't know my way around AutoCAD very well, as I am just stepping in to assist another user with some .NET programming.
If more information is necessary, let me know - I will post the code I am using to loop below.
Code:
// Assume that "db" is a Transaction which has been opened by a StartTransaction() call
// Assume that "AutoCADHelper.CurrentAcadDb" is DocumentManager.MdiActiveDocument.Database
var blockTable = (BlockTable)db.GetObject(AutoCADHelper.CurrentAcadDb.BlockTableId, OpenMode.ForRead);
foreach (ObjectId blockTableId in blockTable) {
var blockTableRecord = db.GetObject(blockTableId, OpenMode.ForRead) as BlockTableRecord;
if (blockTableRecord != null) {
foreach (ObjectId blockTableRecordId in blockTableRecord) {
var blockReference = db.GetObject(blockTableRecordId, OpenMode.ForWrite) as BlockReference;
if (blockReference != null && blockReference.IsDynamicBlock) {
Debug.WriteLine(" blockReference.Name: " + blockReference.Name); // I would assume one of these would be the expected name
Debug.WriteLine(" blockReference.BlockName: " + blockReference.BlockName); // but I am clearly wrong. 🙂
}
}
}
}
Solved! Go to Solution.