Convert Lines in LWPolylines

Discussion in 'AutoCAD' started by talledo, Jul 2, 2003.

  1. talledo

    talledo Guest

    Hi, I’ve a problem. In my drawing I have a number n of lines. I want t oconvert them into LWPolylines.
    I tried a meythod:

    Public Sub sellinesandconvert()
      Dim sset As AcadSelectionSet
      Dim objline As AcadLine
      Dim lenght As Double
      Dim objpoly As AcadLWPolyline
      Dim vertex(0 To 1) As Double
      Dim points(0 To 3) As Double

    lenght = 0
      Set sset = ThisDrawing.SelectionSets.Add("TEST")
      sset.SelectOnScreen
      Set objline = sset.Item(0)
      If objline.Delta(0) = 0 Then
        lenght = lenght + Abs(objline.Delta(1))
      ElseIf objline.Delta(1) = 0 Then
        lenght = lenght + Abs(objline.Delta(0))
      End If
      points(0) = objline.StartPoint(0)
      points(1) = objline.StartPoint(1)
      points(2) = objline.EndPoint(0)
      points(3) = objline.EndPoint(1)
      Set objpoly = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
      'Delete line
      objline.Delete
      objpoly.Closed = False
       For i = 1 To sset.Count - 1
        Set objline = sset.Item(i)
        If objline.Delta(0) = 0 Then
          lenght = lenght + Abs(objline.Delta(1))
        ElseIf objline.Delta(1) = 0 Then
          lenght = lenght + Abs(objline.Delta(0))
        End If
        vertex(0) = objline.EndPoint(0)
        vertex(1) = objline.EndPoint(1)
        objpoly.AddVertex i + 1, vertex
        'Delete line
        linea.Delete
      Next
      MsgBox "lenght : " & lenghtofpolyline(objpoly), vbOKOnly
      'Delete SelectionSet
      ThisDrawing.SelectionSets.Item("prova").Delete
    End Sub

    This code has a very big problem: I had to select lines in AutoCAD in order. I can’t use the selection window (as more common AutoCAD commands). How can I resolve this? Does anybody has an idea?

    Thank you very much.

    Diego Alejandro Talledo
     
    talledo, Jul 2, 2003
    #1
  2. Mark_Abercrombie, Jul 2, 2003
    #2
  3. See the first paragraph in my previous answer.
     
    Mark_Abercrombie, Jul 3, 2003
    #3
  4. Would you be opposed to an autolisp solution?

    ;JOIN LINES, PLINES & ARCS INTO A SINGLE POLYLINE

    (defun c:join (/ ent n name ss1 etype)
    (setq ss1 (ssget '((-4 . "<OR") (0 . "line") (0 . "arc") (0 . "polyline") (0 .
    "lwpolyline") (-4 . "OR>"))))
    (if ss1
    (progn
    (setq n (sslength ss1)
    name (ssname ss1 0)
    ent (entget name)
    etype (cdr (assoc 0 ent))
    )
    (if (or (= etype "POLYLINE") (= etype "LWPOLYLINE"))
    (command ".pedit" name "j" ss1 "" "")
    (command ".pedit" name "" "j" ss1 "" "")
    )
    )
    (princ "\nNothing selected. ")
    )
    (princ)
    )

    realised that AutoCAD Express Tools 1.9 costs 149$. But I can't spend so much
    money, because I'm a student and I'm writing my application for scolastic level.
    So, have you got any idea?
     
    Chuck Gabriel, Jul 3, 2003
    #4
  5. talledo

    talledo Guest

    Hello, thank you for answering...
    I'm not opposed use Visaul Lisp Routines. Can I run this LISP code from VBA?
    Thank you
    Diego
     
    talledo, Jul 4, 2003
    #5
  6. Technically it's possible (see VLAX on AcadX.com), but I don't know that I
    would recommend it. I'm not sure if it is a good idea to run autolisp
    functions that contain COMMAND calls using VLAX. Frank Oquendo could answer
    that better than I can.
     
    Chuck Gabriel, Jul 4, 2003
    #6
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.