- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to get the width and height of a block within my drawing. The block looks like a table, being made up of columns and rows of TEXT objects divided by and bounded by LINE objects. At first I used the bounds of the block and that worked great as long as their was no UCS. I have to account for UCS drawings. Soooo I have written the following code to go through the block and fine the line segments, get the length of those lines. The code runs ok, but the length values of the lines does not correspond to what I get when I explode the block and list the lines. For eg. The code says the line has a length of 85, but when you list it it's 81.6? The other dimension lines the code has it at 158.6 but when I list it it's 152.2???
You will see in the code I tried to grab all the X's and Y's of the line objects and then sort them to get min and max and figure it out that way too, but get the same results and just getting the LENGTH property.
Can anyone help me explain why the difference?
Dim blkheight As Double = GetblksizeUcs(blkobjref, 1)
Dim blkwidth As Double = GetblksizeUcs(blkobjref, 2)
Public Shadows Function GetblksizeUcs(ByVal blkref As BlockReference, ByVal dimtype As Integer) As Double
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim sizevalue As Double = 0
Dim XcoordList As List(Of Double) = New List(Of Double)
Dim YcoordList As List(Of Double) = New List(Of Double)
Using tr As Transaction = doc.TransactionManager.StartTransaction
Try
Dim blk As BlockTableRecord = DirectCast(tr.GetObject(blkref.BlockTableRecord, OpenMode.ForRead), BlockTableRecord)
Dim nrOfEnts As Integer = 0
For Each blkEntId As ObjectId In blk
Dim blkEnt As Entity = DirectCast(tr.GetObject(blkEntId, OpenMode.ForRead), Entity)
Dim enttype As String = blkEntId.ObjectClass.DxfName
If enttype = "LINE" Then
Dim PEnt As Line = blkEnt.ObjectId.GetObject(OpenMode.ForRead)
Dim startpt As Point3d = PEnt.StartPoint
Dim endpt As Point3d = PEnt.EndPoint
XcoordList.Add(startpt.X)
XcoordList.Add(endpt.X)
YcoordList.Add(startpt.Y)
YcoordList.Add(endpt.Y)
Dim linelength As Double = PEnt.Length
End If
Next
XcoordList.Sort()
YcoordList.Sort()
Dim minX As Double = XcoordList(0)
Dim maxX As Double = XcoordList(XcoordList.Count - 1)
Dim minY As Double = YcoordList(0)
Dim maxY As Double = YcoordList(YcoordList.Count - 1)
Dim BlkHieght As Double = maxY - minY
Dim BlkWidth As Double = maxX - minX
If dimtype = 1 Then
sizevalue = BlkHieght
Else
sizevalue = BlkWidth
End If
Catch
MsgBox("block has no lines within it")
End Try
End Using
Return sizevalue
End Function
Solved! Go to Solution.