Changing Line to Polyline without replacing it

Discussion in 'AutoCAD' started by Frank Jan Koole, Jul 29, 2003.

  1. Hi All,

    I only want to work with polylines so I want a macro that scans the drawing
    for lines and changes them into polylines. I got this far but something is
    wrong. Can somebody point it out to me?

    Sub Line_to_Polyline()
    Dim sstest As AcadSelectionSet
    ReDim ssobjs(0 To ThisDrawing.ModelSpace.Count - 1) As AcadEntity
    Dim I As Integer
    Dim K As Integer
    For I = 0 To ThisDrawing.ModelSpace.Count - 1
    If ThisDrawing.ModelSpace.Item(I).ObjectName = "ACDBLine" Then
    K = K + 1
    Set ssobjs(I) = ThisDrawing.ModelSpace.Item(I)
    End If
    Next

    For I = 1 To K
    sstest.AddItems ssobjs(I)
    sstest.Select acSelectionSetAll
    SendCommand "(sssetfirst nil (ssget " & Chr(34) & "_P" & Chr(34) & ")) "
    SendCommand "pedit y "
    Next I
    End Sub
     
    Frank Jan Koole, Jul 29, 2003
    #1
  2. Frank,

    Here you go... some problems I had when I tried the original code were:
    -- I changed from using "For I =" to "For Each" because it's cleaner
    -- the use of K wasn't quite right. The second loop ran on the first K
    objects in ModelSpace, not just the lines.

    It was a good idea to try using the pre-selected objects with the PEDIT
    command... unfortunately, PEDIT seems to clear the selection when you run
    it... try it by hand, select some lines and run PEDIT ... the selection goes
    away... unfortunate.


    Sub Line_to_Polyline_Revised()
    Dim cmd As String
    Dim curEnt As AcadEntity
    For Each curEnt In ThisDrawing.ModelSpace
    If TypeOf curEnt Is AcadLine Then
    ThisDrawing.SendCommand _
    "pedit " & "(handent """ & _
    curEnt.Handle & """) "
    End If
    Next
    End Sub


    James
     
    James Belshan, Jul 29, 2003
    #2
  3. Thanks James,

    It works great. First of all thanks for your comment, I (and maybe a lot of
    other newbe's) can only learn from it. I only have one comment on your
    comment: in the original code I tried to pre-select and then run the pedit
    command and your right if there are more then 1 lines selected, but I wanted
    to make a selection set filled with only one object. But I'm using your code
    now so it's not necessary anymore.

    Frank
     
    Frank Jan Koole, Jul 30, 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.