VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Getting information of items in a dynamic block

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
dhanna
1179 Views, 2 Replies

Getting information of items in a dynamic block

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.

2 REPLIES 2
Message 2 of 3
norman.yuan
in reply to: dhanna

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

Drive CAD With Code

EESignature

Message 3 of 3
dhanna
in reply to: norman.yuan

Thank you so very much.

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost