.NET

Reply
Mentor
Rob.O
Posts: 259
Registered: ‎06-25-2007
Message 1 of 3 (335 Views)
Accepted Solution

Get Mleader Block Attributes

335 Views, 2 Replies
09-27-2011 03:16 PM

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!

 

Mentor
Rob.O
Posts: 259
Registered: ‎06-25-2007
Message 2 of 3 (331 Views)

Re: Get Mleader Block Attributes

09-27-2011 03:36 PM in reply to: Rob.O

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!

*Expert Elite*
chiefbraincloud
Posts: 752
Registered: ‎02-13-2008
Message 3 of 3 (311 Views)

Re: Get Mleader Block Attributes

09-29-2011 02:12 PM in reply to: Rob.O

Open acMReinf.BlockContentId as a BlockReference, and access the AttributeReference's ObjectId's through the that BlockReferences AttributeCollection.

Dave O.                                                                  Sig-Logos32.png
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.