- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
ed.Regen() in the code below only regenerates the physical/visual aspect of the block references, but it doesn't synchronize with the attributes in the new block definition. So is there an equivalent of the command ATTSYNC in C#? Thank you.
[CommandMethod("ReplaceBlock")]
public void UpdateBlock()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
var blkFile = "C:\\8x11Materiel.dwg";
string blkName = System.IO.Path.GetFileNameWithoutExtension(blkFile);
// read the block file into a database
using (var sourceDb = new Database(false, true))
{
sourceDb.ReadDwgFile(blkFile, FileOpenMode.OpenForReadAndAllShare, false, null);
db.Insert(blkName, sourceDb, false);
}
RemoveAttributeFromBlock(db, blkName);
ed.Regen();
}
public static void RemoveAttributeFromBlock(Database db, string blockName)
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
// Get the block definition
var blockTable = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
if (!blockTable.Has(blockName))
return;
var blockDefinition = (BlockTableRecord)tr.GetObject(blockTable[blockName], OpenMode.ForWrite);
// Iterate through the attribute definitions and remove them
foreach (ObjectId objectId in blockDefinition)
{
DBObject obj = tr.GetObject(objectId, OpenMode.ForWrite);
if (obj is AttributeDefinition attributeDefinition)
{
attributeDefinition.Erase();
}
}
// Commit the transaction
tr.Commit();
}
}
Solved! Go to Solution.
Link copied