
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm having a hard time with the .NET API. To begin with, I find the object hierarchy documentation cumbersome, even more, I haven't managed to find a proper "map" showing object relationships and dependencies. Is it just me or it's way more complicated than VBA? I've read the Autodesk documentation to no avail.
I've been lately challenging myself through coding in order to make sure I have a good grasp of object relationships. Next, I'm pasting the code corresponding to a custom command meant to list all block references names in my drawing - just for practising purposes - . It turns out AutoCad crashes and I suspect is because I haven't understood how the Blockreference object relates to the BlockTableRecord, I guess. Aren't block references contained in the Model Space block table? Can anybody point me in the right direction?
[CommandMethod("ListarBloques")]
public void ListarBloques()
{
Document miDibujo = Application.DocumentManager.MdiActiveDocument;
Database misElementos = miDibujo.Database;
using(Transaction miTransaccion = misElementos.TransactionManager.StartTransaction())
{
BlockTable blckTbl;
blckTbl = miTransaccion.GetObject(misElementos.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord blckTblRcrd;
blckTblRcrd = miTransaccion.GetObject(blckTbl[BlockTableRecord.ModelSpace], OpenMode.ForRead) as BlockTableRecord;
foreach (ObjectId id in blckTblRcrd)
{
BlockReference blckRef;
blckRef = miTransaccion.GetObject(id, OpenMode.ForRead) as BlockReference;
miDibujo.Editor.WriteMessage("" + blckRef.Name);
}
miTransaccion.Commit();
}
}
}
Solved! Go to Solution.