+ Reply to Thread
Page 1 of 4 1 2 3 ... LastLast
Results 1 to 10 of 31
  1. #1
    Junior Member
    Using
    AutoCAD 2004
    Join Date
    Feb 2007
    Posts
    14

    Default Auto cad --> excel

    Registered forum members do not see this ad.

    hi
    I need the help.that, how can i get the polyline length/area in a excel sheet automatically..

    Because, when i am taking the area/length measurement by polyline, i have to copy from the list and paste to the excel cell manually..So, this is taking the lot of time for the measurement of more polylines..

    Pls help me friendsssssss

    Thanks in advance

  2. #2
    Super Moderator
    Computer Details
    rkmcswain's Computer Details
    Operating System:
    Windows 7 Pro x64
    Computer:
    HP ZBook 17
    CPU:
    i7-4810MQ @ 2.80 GHZ
    RAM:
    16GB
    Graphics:
    Nvidia Quadro K4100M
    Primary Storage:
    256GB SSD
    Secondary Storage:
    1TB SATA
    Monitor:
    (2) HP 23"
    Discipline
    Civil
    rkmcswain's Discipline Details
    Discipline
    Civil
    Details
    CAD Manager
    Using
    Civil 3D 2017
    Join Date
    Sep 2005
    Location
    Houston
    Posts
    4,487

    Default

    If you are willing to make a small purchase, take a look at AutoCELL @ http://www.dotsoft.com/autocell.htm

    What you are asking for can also be coded in lisp or VBA if you are comfortable doing this or know someone who is.
    R.K. McSwain
    CAD Panacea | twitter

  3. #3
    Junior Member
    Using
    AutoCAD 2004
    Join Date
    Feb 2007
    Posts
    14

    Default

    Thank you for your reply ..rkmcswain

    Pls help me, anyone, who knows the lisp or VBA for for my need...

    Thanks

  4. #4
    Forum Deity SEANT's Avatar
    Using
    AutoCAD 2014
    Join Date
    Aug 2005
    Location
    Rhode Island
    Posts
    2,462

    Default

    Here is some VBA code cannibalized from a larger routine (i.e., may need further tweaking) that basically does what you request. It automatically selects all closed polylines - Lightweight, 2D (fit or splined) - and sends information to a generic excel file.

    The VBAIDE must have a reference set for your version of Excel.

    Code:
    Option Explicit
    
    Sub PutPLProps2XL()
       If ClosedPLSS Then
          Dim objSS As AcadSelectionSet
          Dim entEntity As AcadEntity
          Dim objExcel As Excel.Application
          Dim objRange As Excel.Range
          Dim entLWPoly As AcadLWPolyline
          Dim ent2DPoly As AcadPolyline
          Dim intCount As Integer
          On Error GoTo errhandler
          Set objExcel = GetObject(, "Excel.Application")
          On Error GoTo 0
          Set objRange = objExcel.ActiveWorkbook.ActiveSheet.Range("A1")
          objRange.value = "Pline Type"
          objRange.Offset(0, 1).value = "Length"
          objRange.Offset(0, 2).value = "Area"
             Set objSS = ThisDrawing.SelectionSets.Item("TempSSet")
             For intCount = 0 To objSS.count - 1
                Set entEntity = objSS.Item(intCount)
                If entEntity.ObjectName = "AcDbPolyline" Then
                   Set entLWPoly = entEntity
                   objRange.Offset(intCount + 1, 0).value = "LWPolyline"
                   objRange.Offset(intCount + 1, 1).value = entLWPoly.Length
                   objRange.Offset(intCount + 1, 2).value = entLWPoly.Area
                Else
                   Set ent2DPoly = entEntity
                   objRange.Offset(intCount + 1, 0).value = "2DPolyline"
                   objRange.Offset(intCount + 1, 1).value = ent2DPoly.Length
                   objRange.Offset(intCount + 1, 2).value = ent2DPoly.Area
                End If
             Next
       End If
       Exit Sub
    errhandler:
       Set objExcel = CreateObject("Excel.Application")
       Resume Next
    End Sub
    
    Function ClosedPLSS() As Boolean
       Dim intCode(19) As Integer
       Dim varData(19) As Variant
       ClosedPLSS = False
       intCode(0) = -4: varData(0) = "<Or"
          intCode(1) = -4: varData(1) = "<And"
             intCode(2) = 0: varData(2) = "POLYLINE" 'or closed PLINES's
             intCode(3) = -4: varData(3) = "&="
             intCode(4) = 70: varData(4) = 1
             intCode(5) = -4: varData(5) = "&"
             intCode(6) = 70: varData(6) = 135
             intCode(7) = -4: varData(7) = "<Not"
                intCode(8) = -4: varData(8) = "&="
                intCode(9) = 70: varData(9) = 8
             intCode(10) = -4: varData(10) = "Not>"
          intCode(11) = -4: varData(11) = "And>"
          
          intCode(12) = -4: varData(12) = "<And"
             intCode(13) = 0: varData(13) = "LWPOLYLINE" 'or closed LWP's
             intCode(14) = -4: varData(14) = "&="
             intCode(15) = 70: varData(15) = 1
             intCode(16) = -4: varData(16) = "&"
             intCode(17) = 70: varData(17) = 129
          intCode(18) = -4: varData(18) = "And>"
       intCode(19) = -4: varData(19) = "Or>"
       
       If FilteredSS(intCode, varData) > 0 Then ClosedPLSS = True
    End Function
    
    Private Sub SSPrep()
    Dim SSS As AcadSelectionSets
       'choose a selection set name for temporary storage and
       'ensure that it does not currently exist
       On Error Resume Next
       Set SSS = ThisDrawing.SelectionSets
          If SSS.count > 0 Then
             SSS.Item("TempSSet").Delete
          End If
    End Sub
    
    Function FilteredSS(Optional grpCode As Variant, Optional dataVal As Variant) As Integer
       Dim TempObjSS As AcadSelectionSet
       SSPrep
       Set TempObjSS = ThisDrawing.SelectionSets.Add("TempSSet")
             'generate selection set
          TempObjSS.Select acSelectionSetAll, , , grpCode, dataVal
       FilteredSS = TempObjSS.count
    End Function

  5. #5
    Junior Member
    Using
    AutoCAD 2004
    Join Date
    Feb 2007
    Posts
    14

    Default

    Thank you for your reply....

    I try your vba but, it shows error... i thing, the reason is excel version...

    I am using the Excel 2002 and auto cad 2004..so, pls help me for this version..

    Thanks & regards

  6. #6
    Forum Deity SEANT's Avatar
    Using
    AutoCAD 2014
    Join Date
    Aug 2005
    Location
    Rhode Island
    Posts
    2,462

    Default

    A reference to the proper vesion of Excel can be set through Tools-Reference menu item (as illustrated). I'm using Excel 2003 so, presumably, you would select the "Microsoft Excel 10.0 Object Library"

    If that was not the cause of the error, post the actual error message and we'll try to work it out.
    Attached Images

  7. #7
    Junior Member
    Using
    AutoCAD 2004
    Join Date
    Feb 2007
    Posts
    14

    Default

    Now, it is working friend.....thanks youuuuuuuuuuuuuu....

  8. #8
    Junior Member
    Using
    AutoCAD 2004
    Join Date
    Feb 2007
    Posts
    14

    Default

    Dear friend Seant...

    Pls help on here...

    Your coding is working welll.

    But, i need the coding for.....

    "Display the selected polyline/s properties (such as layer name, area, length) in a excel sheet..."

    Pls help in this.......


    THANKSSSSSSS

  9. #9
    Forum Deity SEANT's Avatar
    Using
    AutoCAD 2014
    Join Date
    Aug 2005
    Location
    Rhode Island
    Posts
    2,462

    Default

    The code below also records the Layer property of the Plines. A few thing were re-arranged for the new sequence of properties. I also repaired the errorhandler section.

    One note: This routine indescriminately records all closed Plines. A "selected" Pline would require modified code.

    Given that this is a "Tutor" based site, perhaps you should show me how to record the Plines linetype. See how the two code examples changed and the effect in Excel. Now add linetype (.linetype) to the list. Don't hesitate to ask if there are any questions.

    Code:
     Option Explicit
    
    Sub PutPLProps2XL()
       If ClosedPLSS Then
          Dim objSS As AcadSelectionSet
          Dim entEntity As AcadEntity
          Dim objExcel As Excel.Application
          Dim objRange As Excel.Range
          Dim entLWPoly As AcadLWPolyline
          Dim ent2DPoly As AcadPolyline
          Dim intCount As Integer
          On Error GoTo errhandler
          Set objExcel = GetObject(, "Excel.Application")
          On Error GoTo 0
          Set objRange = objExcel.ActiveWorkbook.ActiveSheet.Range("A1")
          objRange.value = "Layer"
          objRange.Offset(0, 1).value = "Pline Type"
          objRange.Offset(0, 2).value = "Length"
          objRange.Offset(0, 3).value = "Area"
             Set objSS = ThisDrawing.SelectionSets.Item("TempSSet")
             For intCount = 0 To objSS.count - 1
                Set entEntity = objSS.Item(intCount)
                If entEntity.ObjectName = "AcDbPolyline" Then
                   Set entLWPoly = entEntity
                   objRange.Offset(intCount + 1, 0).value = entLWPoly.Layer
                   objRange.Offset(intCount + 1, 1).value = "LWPolyline"
                   objRange.Offset(intCount + 1, 2).value = entLWPoly.Length
                   objRange.Offset(intCount + 1, 3).value = entLWPoly.Area
                Else
                   Set ent2DPoly = entEntity
                   objRange.Offset(intCount + 1, 0).value = ent2DPoly.Layer
                   objRange.Offset(intCount + 1, 1).value = "2DPolyline"
                   objRange.Offset(intCount + 1, 2).value = ent2DPoly.Length
                   objRange.Offset(intCount + 1, 3).value = ent2DPoly.Area
                End If
             Next
       End If
       Set objExcel = Nothing
       Exit Sub
    errhandler:
       Err.Clear
       Set objExcel = CreateObject("Excel.Application")
       With objExcel
          .Workbooks.Add
          .Visible = True
          .WindowState = xlMinimized
       End With
       Resume Next
    End Sub
    Function ClosedPLSS() As Boolean
       Dim intCode(19) As Integer
       Dim varData(19) As Variant
       ClosedPLSS = False
       intCode(0) = -4: varData(0) = "<Or"
          intCode(1) = -4: varData(1) = "<And"
             intCode(2) = 0: varData(2) = "POLYLINE" 'or closed PLINES's
             intCode(3) = -4: varData(3) = "&="
             intCode(4) = 70: varData(4) = 1
             intCode(5) = -4: varData(5) = "&"
             intCode(6) = 70: varData(6) = 135
             intCode(7) = -4: varData(7) = "<Not"
                intCode(8) = -4: varData(8) = "&="
                intCode(9) = 70: varData(9) = 8
             intCode(10) = -4: varData(10) = "Not>"
          intCode(11) = -4: varData(11) = "And>"
          
          intCode(12) = -4: varData(12) = "<And"
             intCode(13) = 0: varData(13) = "LWPOLYLINE" 'or closed LWP's
             intCode(14) = -4: varData(14) = "&="
             intCode(15) = 70: varData(15) = 1
             intCode(16) = -4: varData(16) = "&"
             intCode(17) = 70: varData(17) = 129
          intCode(18) = -4: varData(18) = "And>"
       intCode(19) = -4: varData(19) = "Or>"
       
       If FilteredSS(intCode, varData) > 0 Then ClosedPLSS = True
    End Function
    Private Sub SSPrep()
    Dim SSS As AcadSelectionSets
       'choose a selection set name for temporary storage and
       'ensure that it does not currently exist
       On Error Resume Next
       Set SSS = ThisDrawing.SelectionSets
          If SSS.count > 0 Then
             SSS.Item("TempSSet").Delete
          End If
    End Sub
    
    Function FilteredSS(Optional grpCode As Variant, Optional dataVal As Variant) As Integer
       Dim TempObjSS As AcadSelectionSet
       SSPrep
       Set TempObjSS = ThisDrawing.SelectionSets.Add("TempSSet")
             'generate selection set
          TempObjSS.Select acSelectionSetAll, , , grpCode, dataVal
       FilteredSS = TempObjSS.count
    End Function

  10. #10
    Junior Member
    Using
    AutoCAD 2004
    Join Date
    Feb 2007
    Posts
    14

    Default

    Registered forum members do not see this ad.

    Thank you so muchhh...friend seant..

    I will use this coding and sent the feed back and additional needs soon..


    Thanks againnnn

Similar Threads

  1. Auto Regen
    By Lazer in forum AutoCAD Drawing Management & Output
    Replies: 20
    Last Post: 19th Sep 2013, 11:48 am
  2. Learning Auto-Cad
    By Nadiauae in forum AutoCAD Beginners' Area
    Replies: 1
    Last Post: 23rd Aug 2006, 09:13 am
  3. AUTO CAD FOR EEE
    By vishnu_klm in forum AutoCAD Beginners' Area
    Replies: 1
    Last Post: 11th Jul 2006, 04:09 pm
  4. Auto Delete
    By CADtech in forum AutoLISP, Visual LISP & DCL
    Replies: 19
    Last Post: 3rd Dec 2004, 09:53 am
  5. Auto CAD 3d
    By Dennis in forum AutoCAD Beginners' Area
    Replies: 2
    Last Post: 17th Oct 2002, 03:42 pm

Bookmarks

Posting Permissions

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