Convert standard polylines to lwpolylines

Discussion in 'AutoCAD' started by Nashy28, Mar 14, 2005.

  1. Nashy28

    Nashy28 Guest

    Hi All,

    I am having some trouble using the CONVERTPOLY function. When I run it
    to convert all the polylines into LWpolines in my drawings it returns
    "0 polylines converted". I am thinking this is because it does not
    convert the lines inside all the block references in the drawing.
    I have written some code to iterate through the block collection and
    draw a lwpolyline where a polyline is and delete the polyline and
    thereby converting them.
    I can create the coordinate array ok but when I pass it to the
    AddLightWeightPolyline I get an error.

    Here is the code:

    -----------------Start Code----------------------

    Private Sub ConvertPolyLine()
    Dim objEntity As AcadEntity
    Dim ssCurrent As AcadSelectionSet
    Dim FilterCodes(0) As Integer
    Dim FilterValues(0) As Variant
    Dim objBlock As AcadBlock
    Dim pline As AcadPolyline
    Dim lwpline As AcadLWPolyline
    Dim vCoordinates() As Double
    Dim LayName As String, lWeight As Integer
    Dim i As Integer, j As Integer, iArrayCount As Integer

    On Error Resume Next

    Set ssCurrent = ThisDrawing.SelectionSets.Add("ssCurrent")
    If Err Then Set ssCurrent =
    ThisDrawing.SelectionSets.Item("ssCurrent")

    On Error GoTo Done

    FilterCodes(0) = 0
    FilterValues(0) = "INSERT"

    ssCurrent.Select acSelectionSetAll, , , FilterCodes, FilterValues

    'Convert polylines in block collection
    For Each objBlock In ThisDrawing.Blocks
    For Each objEntity In objBlock
    If TypeOf objEntity Is AcadPolyline Then
    Set pline = objEntity
    If pline.Visible = True Then
    ReDim vCoordinates(UBound(pline.Coordinates))
    LayName = pline.Layer
    lWeight = pline.Lineweight

    'Build vCoordinates array
    iArrayCount = 0
    j = 0
    For i = 0 To UBound(pline.Coordinates) Step 3
    If Not pline.Coordinates(i) = "" Then
    vCoordinates(j) = pline.Coordinates(i)
    vCoordinates(j + 1) = pline.Coordinates(i +
    1)
    j = j + 2
    iArrayCount = iArrayCount + 1
    End If
    Next

    ReDim Preserve vCoordinates(UBound(vCoordinates) -
    iArrayCount)

    'Errors here!!
    lwpline =
    objBlock.AddLightWeightPolyline(vCoordinates)

    lwpline.Layer = LayName
    lwpline.Lineweight = lWeight
    lwpline.Update

    objEntity.Delete
    End If
    End If
    Next
    Next


    'Convert any polyline inserted inside drawing
    For Each objEntity In ssCurrent
    If TypeOf objEntity Is AcadPolyline Then
    Set pline = objEntity

    ReDim vCoordinates(UBound(pline.Coordinates))
    LayName = pline.Layer
    lWeight = pline.Lineweight

    iArrayCount = 0
    j = 0
    For i = 0 To UBound(pline.Coordinates) Step 3
    If Not pline.Coordinates(i) = "" Then
    vCoordinates(j) = pline.Coordinates(i)
    vCoordinates(j + 1) = pline.Coordinates(i + 1)
    j = j + 2
    iArrayCount = iArrayCount + 1
    End If
    Next

    ReDim Preserve vCoordinates(UBound(vCoordinates) -
    iArrayCount)

    lwpline = objBlock.AddLightWeightPolyline(vCoordinates)

    lwpline.Layer = LayName
    lwpline.Lineweight = lWeight
    lwpline.Update

    objEntity.Delete
    End If
    Next

    ThisDrawing.Regen True
    MsgBox "Finished Polyline Conversion"

    Done:
    If Not ssCurrent Is Nothing Then
    ssCurrent.Delete
    End If
    If Err Then
    MsgBox Err.Number & ": " & Err.Description
    End If
    End Sub

    --------------------End Code------------------------

    This has been bugging me for days.
    Any ideas on this code or another more practical way to achieve goal
    would be appreciated.

    Thanks in advance,

    Chris Nash
    RetailSolutions international Pty Ltd
     
    Nashy28, Mar 14, 2005
    #1
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.