Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm implementing a macro with the purpose to export the names of all blocks in a drawing, wether they're present in the model space or not.
The issue I'm encountring is when I try to include the visibilities of the dynamic blocks in the export.
So I would appreciate if anyone could help show me how to collect the information about the visibilities of a dynamic block. Thank you in advance.
[CommandMethod("ExportBlocksListToCsv")]
public void ExportBlocksListToCsv()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
// Get the path of the open drawing file
string drawingPath = db.Filename;
string csvFilePath = drawingPath.Replace(".dwg", " Blocks.csv");
List<string> blockNames = new List<string>();
using (Transaction tr = db.TransactionManager.StartTransaction())
{
// Open the block table
BlockTable blockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
if (blockTable != null)
{
// Iterate through each block table record (block definition)
foreach (ObjectId btrId in blockTable)
{
BlockTableRecord btr = tr.GetObject(btrId, OpenMode.ForRead) as BlockTableRecord;
if (btr == null || btr.IsLayout || btr.IsAnonymous)
{
continue;
}
blockNames.Add(btr.Name);
if (btr.IsDynamicBlock)
{
//INSERT CODE HERE WHERE YOU ADD THE VISIBILITIES OF THE DYNAMIC BLOCK TO THE LIST blockNames.
}
}
}
tr.Commit();
}
_exportListToCsv(blockNames, csvFilePath);
}
Solved! Go to Solution.