Hi all!
I need help reading the values from an Mleader object that contains a block. I can get attributes from normal blocks with no problem, but I am struggling with this.
I can get all the way up to casting the attributes, but when I try getting the AttributeReference, the code crashes. How do I get the AttributeReference from the AttributeDefinition? As it is now, if I declare the AttributeDefinition, the values return as nothing.
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim acCurDb As Database = acDoc.Database Dim acEd As Editor = DocumentManager.MdiActiveDocument.Editor '' Start a transaction Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() Try Dim acBt As BlockTable = acDoc.Database.BlockTableId.GetObject(OpenMode.ForRead) Dim acBtrMs As BlockTableRecord = DirectCast(acBt(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForRead), BlockTableRecord) Dim myReinfVals As New List(Of String) Dim myReinfQtys As New List(Of String) For Each objId As ObjectId In acBtrMs Dim acMReinf As MLeader = TryCast(acTrans.GetObject(objId, OpenMode.ForRead), MLeader) If acMReinf IsNot Nothing Then Dim MleadStyle As MLeaderStyle = acTrans.GetObject(acMReinf.MLeaderStyle, OpenMode.ForRead) Dim strMlStyle As String = MleadStyle.Name If strMlStyle = "ECDT_ANO-Rebar" Then If MleadStyle.ContentType = ContentType.BlockContent Then Dim blkid As ObjectId = acBt("X$X_ANO-RebarID") Dim blk As BlockTableRecord = CType(acTrans.GetObject(blkid, OpenMode.ForRead), BlockTableRecord) For Each attobjId As ObjectId In blk Dim acEnt As Entity = CType(acTrans.GetObject(attobjId, OpenMode.ForRead), Entity) If TypeOf acEnt Is AttributeDefinition Then Dim attDef As AttributeDefinition = DirectCast(acEnt, AttributeDefinition) Dim attRef As AttributeReference = DirectCast(acEnt, AttributeReference) '' << Cannot cast as Attributereference or code crashes End If Next End If End If End If Next Catch ex As Autodesk.AutoCAD.Runtime.Exception MsgBox("An error has occured. Please contact you system administrator." & vbCr & vbCr & ex.Message & vbCr & ex.StackTrace) Finally End Try acTrans.Commit() End Using
Thanks for any advice!
Solved! Go to Solution.
Solved by chiefbraincloud. Go to Solution.
Just an aside...
I am also not able to cast the objectid to a BlockReference (as I normally would for a regular block) without AutoCAD crashing.
Dim acBref As BlockReference = blkid.GetObject(OpenMode.ForRead)
What am I missing?
Thanks!
Open acMReinf.BlockContentId as a BlockReference, and access the AttributeReference's ObjectId's through the that BlockReferences AttributeCollection.
chiefbraincloud,
Pardon my inexperience, but I am having a similar to the one described by Rob O. Using VB.net, I want to capture the value of the attribute contained within an Mleader having a content of "Block", specifically the "BOX" block. Can you further explain your solution (below) to Rob O's question?
Thanks for your assistance with this matter.