Continuing from my prior post (thank you those who replied), the equavilent of ThisDrawing from VBA in VB.NET, spawned a new question:
I poked around in the help but it didnt really answer my question.
Anyway, now I am using MdiActiveDocument
Application.DocumentManager.MdiActiveDocument
However there is no .Blocks
In VBA I was able to do this:
For Each entry In ThisDrawing.Blocks If entry.Name = BADBLOCK01 Or entry.Name = BADBLOCK02 Or entry.Name = BADBLOCK03 Then found = True End If Next
How can I access/do this in VB.NET?
Anyone?
By the way, if you do manage to find the answer posted in some help somewhere please post a link.
Tony
Solved! Go to Solution.
Solved by _gile. Go to Solution.
Hi,
IMHO, if you want to learn the AutoCAD .NET API, you'd better forget your VBA knowledge and start from scratch rather than searching for equivalencies (perhaps learning C# rather than VB should be helpfull in this way).
You'll find some tutorials here.
The .NET API have some more layers than the COM one. For example, the equivalent of the COM Document object (ThisDrawing in VBA) is sometimes the .NET Document object, but may also be the Database one.
The common way to access to a database resident object in .NET is openning it from its ObjectId within a transaction. The equivalent for the COM Blocks (the drawing blocks collection) is a BlockTable object.
C#
Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; bool found = false; using (Transaction tr = db.TransactionManager.StartTransaction()) { BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); found = bt.Has("BADBLOCK01") || bt.Has("BADBLOCK02") || bt.Has("BADBLOCK03"); tr.Commit(); }
VB
Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Dim found As Boolean = False Using tr As Transaction = db.TransactionManager.StartTransaction() Dim bt As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable) found = bt.Has("BADBLOCK01") OrElse bt.Has("BADBLOCK02") OrElse bt.Has("BADBLOCK03") tr.Commit() End Using