Good morning;
I would like to put together a routine that will identify rectangles within a dynamic block in autocad which are 2 1/2" wide, figure out if they are vertical or horizontal, figure out which are to run through vs stop short with the end goal of creating a skeleton that can be used in inventor that a user can apply frame members to.
currently, I am right at the beginning, trying to figure out getting the information of the items in the block, but I am not getting points returned from getboundingbox.
Option Explicit
Sub main()
Dim acadApp As AcadApplication
Dim acadDoc As AcadDocument
Dim disCatch As String
Dim disBlk As AcadBlock
Dim datBlkRef As AcadBlockReference
Dim Indx As Long
Dim PntInSpace(0 To 2) As Double
Dim BlkExpld As Variant
Dim varAttributes As Variant
Dim MinPt() As Variant
Dim MaxPt() As Variant
Dim subEnt As AcadEntity
PntInSpace(0) = 200
PntInSpace(1) = 200
PntInSpace(2) = 0
Set acadApp = AutoCAD.Application
Set acadDoc = ThisDrawing
Set disBlk = acadDoc.Blocks.Item("E14")
For Indx = 0 To disBlk.Count - 1
If disBlk(Indx).ObjectName = "AcDbPolyline" Then
Set subEnt = disBlk(Indx)
subEnt.GetBoundingBox MinPt, MaxPt
''' disBlk(Indx).GetBoundingBox MinPt, MaxPt
Debug.Print disBlk(Indx).Handle
Debug.Print subEnt.Handle
Debug.Print LBound(MinPt())
Debug.Print UBound(MinPt())
Debug.Print Indx & " min: " & MinPt(1) & " max: " & MaxPt(1)
End If
Next
End Sub
the handles print out in the debug window and are the same, however the lbound errors out subscript out of range.
any help would be greatly appreciated.
Thank you in advance;
DH.
Solved! Go to Solution.
Solved by norman.yuan. Go to Solution.
See the code changes (RED is your original, BLUE is changed):
Sub main()
Dim acadApp As AcadApplication
Dim acadDoc As AcadDocument
Dim disCatch As String
Dim disBlk As AcadBlock
Dim datBlkRef As AcadBlockReference
Dim Indx As Long
Dim PntInSpace(0 To 2) As Double
Dim BlkExpld As Variant
Dim varAttributes As Variant
''Dim MinPt() As Variant
''Dim MaxPt() As Variant
Dim MinPt As Variant
Dim MaxPt As Variant
Dim subEnt As AcadEntity
PntInSpace(0) = 200
PntInSpace(1) = 200
PntInSpace(2) = 0
Set acadApp = AutoCAD.Application
Set acadDoc = ThisDrawing
Set disBlk = acadDoc.Blocks.Item("E14")
For Indx = 0 To disBlk.Count - 1
If disBlk(Indx).ObjectName = "AcDbPolyline" Then
Set subEnt = disBlk(Indx)
subEnt.GetBoundingBox MinPt, MaxPt
''' disBlk(Indx).GetBoundingBox MinPt, MaxPt
Debug.Print disBlk(Indx).Handle
Debug.Print subEnt.Handle
''Debug.Print LBound(MinPt())
''Debug.Print UBound(MinPt())
Debug.Print LBound(MinPt)
Debug.Print UBound(MinPt)
Debug.Print Indx & " min: " & MinPt(1) & " max: " & MaxPt(1)
End If
Next
End Sub
Norman Yuan