Loop through Walls

Discussion in 'AutoCAD' started by Andrew Elmore, Jun 24, 2003.

  1. Can someone give an example of looping through each wall on a drawing and
    display it information (i.e. Length,Width, style name, end cap ect...)

    Andy
     
    Andrew Elmore, Jun 24, 2003
    #1
  2. Try this:



     



    '**************************************************************************************
    '   Project: WallsInformation.dvb  |
    '----------------------------------------------------------------------------------------------------------------
    '
    '   References: '     VBA   GUID: {000204EF-0000-0000-C000-000000000046}
    '                        Type Library - C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6.DLL
    '                     AutoCAD   GUID: {C094C1E2-57C6-11D2-85E3-080009A0C626}
    '                        Type Library - C:\Program Files\ABS3\ACAD.TLB
    '                     stdole    GUID: {00020430-0000-0000-C000-000000000046}
    '                        Type Library - C:\WINNT\System32\Stdole2.tlb
    '                     AecXUIArchBase    GUID: {842B17BD-8A01-11D2-9C40-0080C7D6CCA4}
    '                        Type Library - C:\Program Files\Common Files\Autodesk Shared\AecXUIArchBase30.tlb
    '                     AecXArchBase  GUID: {0CF50021-59F3-11D2-9B3E-000000000000}
    '                        Type Library - C:\Program Files\Common Files\Autodesk Shared\AecXArchBase30.tlb
    '                     AecXUIBase    GUID: {842B17A3-8A01-11D2-9C40-0080C7D6CCA4}
    '                        Type Library - C:\Program Files\Common Files\Autodesk Shared\AecXUIBase30.tlb
    '                     AecXBase  GUID: {08B589BB-4F00-11D2-A7F1-0060B0572AC8}
    '                        Type Library - C:\Program Files\Common Files\Autodesk Shared\AecXBase30.tlb
    '
    '----------------------------------------------------------------------------------------------------------------



     




    Public Sub IterateAllWalls()
        Dim myWall As AecWall
        Dim myEnt As AecEntity
        Dim myLength
        For Each myEnt In ThisDrawing.ModelSpace
            If TypeOf myEnt Is AecWall Then
                Set myWall = myEnt
                'Assumption...all walls are planar therefore
                'distance = Sqr( (x1 - x2)^2 + (y1 - y2)^2 )
                With myWall
                    myLength = Distance(.StartPoint(0), .StartPoint(1), .EndPoint(0), ..EndPoint(1))
                End With
                MsgBox "Entity Handle: " & myWall.Handle & vbCrLf & _
                       "StyleName: " & myWall.StyleName & vbCrLf & _
                       "Height: " & myWall.BaseHeight & "   Width: " & myWall.Width & vbCrLf & _
                       "Length: " & ThisDrawing.Utility.RealToString(myLength, acArchitectural, 2)
            End If
        Next
    End Sub



     



    Public Function Distance(x1 As Variant, y1 As Variant, x2 As Variant, y2 As Variant) As Variant
        Distance = VBA.Sqr((x1 - x2) ^ 2 + (y1 - y2) ^ 2)
    End Function




    Hope that helps,



     



    RLB



    "Andrew Elmore" <> wrote in message news:...

    Can someone give an example of looping through each wall on a drawing and
    display it information (i.e. Length,Width, style name, end cap ect...)

    Andy
     
    Richard Binning, Jun 24, 2003
    #2
  3. thanks I'll try that



     



    Andy



    "Richard Binning" <rlbinnin@thehaskellco_dot_com> wrote in message news:...



    Try this:



     



    '**************************************************************************************
    '   Project: WallsInformation.dvb  |
    '----------------------------------------------------------------------------------------------------------------
    '
    '   References: '     VBA   GUID: {000204EF-0000-0000-C000-000000000046}
    '                        Type Library - C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6.DLL
    '                     AutoCAD   GUID: {C094C1E2-57C6-11D2-85E3-080009A0C626}
    '                        Type Library - C:\Program Files\ABS3\ACAD.TLB
    '                     stdole    GUID: {00020430-0000-0000-C000-000000000046}
    '                        Type Library - C:\WINNT\System32\Stdole2.tlb
    '                     AecXUIArchBase    GUID: {842B17BD-8A01-11D2-9C40-0080C7D6CCA4}
    '                        Type Library - C:\Program Files\Common Files\Autodesk Shared\AecXUIArchBase30.tlb
    '                     AecXArchBase  GUID: {0CF50021-59F3-11D2-9B3E-000000000000}
    '                        Type Library - C:\Program Files\Common Files\Autodesk Shared\AecXArchBase30.tlb
    '                     AecXUIBase    GUID: {842B17A3-8A01-11D2-9C40-0080C7D6CCA4}
    '                        Type Library - C:\Program Files\Common Files\Autodesk Shared\AecXUIBase30.tlb
    '                     AecXBase  GUID: {08B589BB-4F00-11D2-A7F1-0060B0572AC8}
    '                        Type Library - C:\Program Files\Common Files\Autodesk Shared\AecXBase30.tlb
    '
    '----------------------------------------------------------------------------------------------------------------



     




    Public Sub IterateAllWalls()
        Dim myWall As AecWall
        Dim myEnt As AecEntity
        Dim myLength
        For Each myEnt In ThisDrawing.ModelSpace
            If TypeOf myEnt Is AecWall Then
                Set myWall = myEnt
                'Assumption...all walls are planar therefore
                'distance = Sqr( (x1 - x2)^2 + (y1 - y2)^2 )
                With myWall
                    myLength = Distance(.StartPoint(0), .StartPoint(1), .EndPoint(0), .EndPoint(1))
                End With
                MsgBox "Entity Handle: " & myWall.Handle & vbCrLf & _
                       "StyleName: " & myWall.StyleName & vbCrLf & _
                       "Height: " & myWall.BaseHeight & "   Width: " & myWall.Width & vbCrLf & _
                       "Length: " & ThisDrawing.Utility.RealToString(myLength, acArchitectural, 2)
            End If
        Next
    End Sub



     



    Public Function Distance(x1 As Variant, y1 As Variant, x2 As Variant, y2 As Variant) As Variant
        Distance = VBA.Sqr((x1 - x2) ^ 2 + (y1 - y2) ^ 2)
    End Function




    Hope that helps,



     



    RLB



    "Andrew Elmore" <> wrote in message news:...

    Can someone give an example of looping through each wall on a drawing and
    display it information (i.e. Length,Width, style name, end cap ect...)

    Andy
     
    Andrew Elmore, Jun 24, 2003
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.