I am trying to filter for a dynamic block using xdata. I found this post by Kean Walmsley going over the process, but I haven't been able to make it work for me. The code he has is in C#, which I'm not familiar with (I code very rarely).
This is what I have so far:
Code:
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Using tr As Transaction = doc.TransactionManager.StartTransaction()
Dim bt As BlockTable = tr.GetObject(db.BlockTableId, OpenMode.ForWrite)
For Each bid In bt
Dim btr2 As BlockTableRecord = tr.GetObject(bid, OpenMode.ForWrite)
If Not btr2.Name = "PointMarker" AndAlso IsDBNull(btr2.XData) = False Then
Dim TypeValArr() As TypedValue = btr2.XData.AsArray
For i = 0 To TypeValArr.Length
Dim TypeVal As String = TypeValArr(i)
If TypeVal.GetTypeCode = DxfCode.ExtendedDataRegAppName Then
If TypeVal.ToString = "AcDbBlockRepBTag" Then
For j = i + 1 To TypeValArr.Length
TypeVal = TypeValArr(j)
If TypeVal.GetTypeCode = DxfCode.ExtendedDataRegAppName Then
i = j - 1
Exit For
End If
If TypeVal.GetTypeCode = DxfCode.ExtendedDataHandle Then
If TypeVal.ToString = "PointMarker" Then
Dim blockref As BlockReference = btr2.Id.GetObject(OpenMode.ForWrite)
Dim xpos As Double = blockref.Position.X
Dim ypos As Double = blockref.Position.Y
Dim zpos As Double = blockref.Position.Z
Dim scalefactor As Double = blockref.ScaleFactors.X
blockref.ScaleFactors() = New Scale3d(sf)
Dim ac As AttributeCollection = blockref.AttributeCollection
For Each att As ObjectId In ac
Dim attr As DBObject = att.GetObject(OpenMode.ForWrite)
If TypeOf attr Is AttributeReference Then
Dim ar As AttributeReference = att.GetObject(OpenMode.ForWrite)
ar.TransformBy(Matrix3d.Scaling(1 / scalefactor, New Point3d(xpos, ypos, zpos)))
ar.TransformBy(Matrix3d.Scaling(sf, New Point3d(xpos, ypos, zpos)))
End If
Next
i = TypeValArr.Length - 1
Exit For
End If
End If
j = j + 1
Next
End If
End If
i = i + 1
Next
End If
Next
tr.Commit()
End Using
I am stuck on the "Dim TypeValArr As Array = btr2.XData.AsArray" part. It continually causes a fatal error when the code runs. Should I be declaring this differently?