Results 1 to 1 of 1

Thread: Calculating length of lines on the polylines

  1. #1
    Woo! Hoo! my 1st post
    Join Date
    2016-08
    Posts
    1
    Login to Give a bone
    0

    Default Calculating length of lines on the polylines

    Hello everyone

    I found this code and edited it. It can be listed all polylines with their areas and length on the excel, i want to also calculate to length of line on the these polylines. What should i need to do ?

    As example,

    Capture.PNG

    LWPoly nr Layer Area Length Door length
    1 Wall01 20 18 1.5
    2 Wall02 30 22 2


    Code:
    --------------------------------------------------------------
    Option Explicit
    
    Sub PickLwPolysAndGetData()
        
    'for Excel sheet managing purposes
    Dim MySht As Worksheet
    Dim MyCell As Range
    
    'for Autocad application managing purposes
    Dim ACAD As AcadApplication
    Dim ThisDrawing As AcadDocument
    Dim LWPoly As AcadLWPolyline
    Dim mtext As AcadMText
    
    ' for selection set purposes
    Dim ssetObj As AcadSelectionSet
    Dim gpCode(0) As Integer
    Dim dataValue(0) As Variant
    
    'for general variables managing purposes
    Dim iRow As Long
    Dim LWArea As Double, LWPerimeter As Double, LWLayer As Variant, amtext As Variant
    
    
    ' Autocad Session handling
        On Error Resume Next
        Set ACAD = GetObject(, "AutoCAD.Application")
        On Error GoTo 0
        If ACAD Is Nothing Then
            Set ACAD = New AcadApplication
            ACAD.Visible = True
        End If
        Set ThisDrawing = ACAD.ActiveDocument
          
    
    ' selecting LwPolylines on screen by selelection set filtering method
        ' managing potential selection set exsistence
        On Error Resume Next
        Set ssetObj = ThisDrawing.SelectionSets.Item("LWPolySSET")
        If Err Then Set ssetObj = ThisDrawing.SelectionSets.Add("LWPolySSET")
        On Error GoTo 0
        ssetObj.Clear
        
        'setting filtering critera
        gpCode(0) = 0
        dataValue(0) = "LWPOLYLINE"
        
        'selecting LWPolylines
        ssetObj.SelectOnScreen gpCode, dataValue
    
    ' processing LWPolylines
    
        If ssetObj.Count > 0 Then
        
            ' writing sheet headings
            Set MySht = ActiveSheet
            Set MyCell = MySht.Cells(1, 1)
            With MyCell
                .Offset(0, 0).Value = "LWPoly nr"
                .Offset(0, 1).Value = "Layer"
                .Offset(0, 2).Value = "Area"
                .Offset(0, 3) = "Length"
            End With
            
            'clearing previous written data
            iRow = MySht.Cells(MySht.Rows.Count, 1).End(xlUp).Row
            If iRow > 1 Then MyCell.Offset(1, 0).Resize(iRow - 1, 3).Clear
            
            'retrieving LWPolys data and writing them on worksheet
            iRow = 1
            For Each LWPoly In ssetObj
                'retrieving LWPoly data
                With LWPoly
                    LWArea = .Area
                    LWPerimeter = .Length
                    LWLayer = .Layer
                     
                End With
               
               
               
                                
                
                ' writing LWPoly data
                With MyCell
                    .Offset(iRow, 0).Value = "LWPoly nr." & iRow
                    .Offset(iRow, 1).Value = LWLayer
                    .Offset(iRow, 2).Value = LWArea
                    .Offset(iRow, 3).Value = LWPerimeter
                    
                End With
                iRow = iRow + 1
            Next LWPoly
            
        End If
    
    ' cleaning up before ending
        ssetObj.Delete
        Set ssetObj = Nothing
        Set ThisDrawing = Nothing
        Set ACAD = Nothing
    
    End Sub
    
    ------------------------------------------------------------
    Last edited by rkmcswain; 2016-08-16 at 11:28 AM.

Similar Threads

  1. Replies: 1
    Last Post: 2016-06-14, 01:31 PM
  2. Polylines and Total Length
    By revit.wishlist1942 in forum Revit Architecture - Wish List
    Replies: 3
    Last Post: 2012-06-13, 08:10 PM
  3. RAC 2009 - Scheduling & Calculating Linear Length of Curb
    By designviz in forum Revit Architecture - General
    Replies: 40
    Last Post: 2009-09-26, 05:46 PM
  4. calculating total length of solids in dwg
    By cwjean76 in forum AutoCAD 3D (2007 and above)
    Replies: 3
    Last Post: 2009-05-26, 07:25 PM
  5. Calculating total length of lines
    By wmmccully in forum AutoCAD General
    Replies: 3
    Last Post: 2006-01-18, 03:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •