+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 28
  1. #1
    Full Member
    Using
    Civil 3D 2012
    Join Date
    Jan 2009
    Posts
    56

    Default How to read polyline vert to file with name?

    Registered forum members do not see this ad.

    Hello,

    I have problem to make lsp file, that will read vertices of polilyine x,y,z coordinates to txt file with named polyline.
    I have a bunch of polyline and i need to mark them with name and attach x,y,z coordinates of them.
    So basicly i need to pick the polilyine, then must ask me the name of polilyine then record in to the txt file with the name and coordinates x,y,z. I have a lot of them so i need to be asked for another polyline and again and again and put to same txt file.

    any suggestions?

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,743

    Default

    Perhaps this?

    Code:
    (defun c:plco (/ File oFile pLin pStr nlist pLen wLine)
        (if    (setq File (getfiled "Create a Text File" "C:\\" "txt" 9))
        (progn
            (setq oFile (open file "W"))
            (while (setq pLin (ssget ":S"
                         (list (cons 0 "LWPOLYLINE,POLYLINE")
                           (cons 410 (getvar "CTAB"))
                         ) ;_  end list
                      ) ;_  end ssget
               ) ;_  end setq
            (sssetfirst nil pLin)
            (if (/= (setq pStr (getstring t "\nSpecify Name for Selected Polyline >> ")) "")
                (progn (foreach x (entget (ssname pLin 0))
                       (if (eq 10 (car x))
                       (setq nlist (cons (cdr x) nlist))
                       ) ;_  end if
                   ) ;_  end foreach
                   (setq pLen (length nlist))
                   (while (not (minusp (setq pLen (1- pLen))))
                       (setq wLine (strcat (rtos (car (nth pLen nlist)) 2 2)
                               ","
                               (rtos (cadr (nth pLen nlist)) 2 2)
                           ) ;_  end strcat
                       ) ;_  end setq
                       (if (caddr (nth pLen nlist))
                       (strcat wLine "," (rtos (caddr (nth pLen nlist)) 2 2))
                       ) ;_  end if
                   ) ;_  end while
                   (write-line (strcat pStr "\t" wLine) oFile)
                ) ;_  end progn
                (princ "\n<!> No Line Name Specified. <!>")
            ) ;_  end if
            (sssetfirst nil)
            ) ;_  end while
            (close oFile)
        ) ;_  end progn
        (princ "\n<!> No File Selected. <!> ")
        ) ;_  end if
        (princ)
    ) ;_  end defun
    Last edited by Lee Mac; 12th Jan 2009 at 07:12 pm.
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  3. #3
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,743

    Default

    Sorry, my mistake, initial post would only read first vertex.

    Code:
    (defun c:plco (/ File oFile pLin pStr nlist pLen wLine wfLine)
        (if    (setq File (getfiled "Create a Text File" "C:\\" "txt" 9))
        (progn
            (setq oFile (open file "W"))
            (while (setq pLin (ssget ":S" (list (cons 0 "LWPOLYLINE") (cons 410 (getvar "CTAB")))))
            (sssetfirst nil pLin)
            (if (/= (setq pStr (getstring t "\nSpecify Name for Selected Polyline >> ")) "")
                (progn (foreach x (entget (ssname pLin 0))
                       (if (eq 10 (car x))
                       (setq nlist (cons (cdr x) nlist))))
            (setq nlist (reverse nlist) pLen (length nlist) wfLine "")
                   (while (not (minusp (setq pLen (1- pLen))))
                       (setq wLine (strcat (rtos (car (nth pLen nlist)) 2 2) ","
                               (rtos (cadr (nth pLen nlist)) 2 2)))
                       (if (caddr (nth pLen nlist))
                       (strcat wLine "," (rtos (caddr (nth pLen nlist)) 2 2)))
               (setq wfLine (strcat wLine "\t" wfLine))
                   ) ;_  end while
                   (write-line (strcat pStr "\t" wfLine) oFile)
                ) ;_  end progn
                (princ "\n<!> No Line Name Specified. <!>")
            ) ;_  end if
            (sssetfirst nil)
            ) ;_  end while
            (close oFile)
        ) ;_  end progn
        (princ "\n<!> No File Selected. <!> ")
        ) ;_  end if
        (princ))
    Last edited by Lee Mac; 12th Jan 2009 at 07:45 pm.
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  4. #4
    Forum Deity
    Using
    not specified
    Join Date
    Jul 2004
    Location
    Anchorage, Alaska
    Posts
    2,074

    Default

    Lee,

    It doesn't appear this code would work for "polylines"? I see they can be selected, but code seems to use just group code 10 for vertices (so works for 'lwpolylinwes'). To get vertices of a regular (heavyweight) polyline you'll need a different method, such as stepping through with 'entnext'. Seeing that the OP asked for z values as well, he might even want it to work for 3d polylines.

  5. #5
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,743

    Default

    Sorry Carl, will sort it.
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  6. #6
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,743

    Default

    Ok, try this:

    Code:
    (defun c:plco (/ File oFile pLin pStr pEnt nlist pLen wLine wfLine vPt wvLine)
        (if    (setq File (getfiled "Create a Text File" "C:\\" "txt" 9))
        (progn
            (setq oFile (open file "W"))
            (while (setq pLin (ssget ":S" (list (cons 0 "LWPOLYLINE,POLYLINE") (cons 410 (getvar "CTAB")))))
            (sssetfirst nil pLin)
            (if (/= (setq pStr (getstring t "\nSpecify Name for Selected Polyline >> ")) "")
                (progn
                (setq pEnt (ssname pLin 0))
                (cond ((= "LWPOLYLINE" (cdr (assoc 0 (entget pEnt))))
                       (foreach    x (entget pEnt)
                       (if (eq 10 (car x))
                           (setq nlist (cons (cdr x) nlist))
                       ) ;_  end if
                       ) ;_  end foreach
                       (setq nlist  (reverse nlist)
                         pLen   (length nlist)
                         wfLine ""
                       ) ;_  end setq
                       (while (not (minusp (setq pLen (1- pLen))))
                       (setq wLine (strcat (rtos (car (nth pLen nlist)) 2 2)
                                   ","
                                   (rtos (cadr (nth pLen nlist)) 2 2)
                               ) ;_  end strcat
                       ) ;_  end setq
                       (setq wfLine (strcat wLine "\t" wfLine))
                       ) ;_  end while
                       (write-line (strcat pStr "\t" wfLine) oFile)
                      )
                      ((= "POLYLINE" (cdr (assoc 0 (entget pEnt))))
                       (setq wvLine ""
                         pEnt   (entnext pEnt)
                       ) ;_  end setq
                       (while (/= (cdr (assoc 0 (entget pEnt))) "SEQEND")
                       (setq vPt    (cdr (assoc 10 (entget pEnt)))
                         wvLine    (strcat    (rtos (car vPt) 2 2)
                                ","
                                (rtos (cadr vPt) 2 2)
                                ","
                                (rtos (caddr vPt) 2 2)
                                "\t"
                                wvLine
                            ) ;_  end strcat
                         pEnt    (entnext pEnt)
                       ) ;_  end setq
                       ) ;_  end while
                       (write-line (strcat pStr "\t" wvLine) oFile)
                      )
                ) ;_  end cond
                ) ;_  end progn
                (princ "\n<!> No Line Name Specified. <!>")
            ) ;_  end if
            (sssetfirst nil)
            ) ;_  end while
            (close oFile)
        ) ;_  end progn
        (princ "\n<!> No File Selected. <!> ")
        ) ;_  end if
        (princ)
    ) ;_  end defun
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  7. #7
    Full Member
    Using
    Civil 3D 2012
    Join Date
    Jan 2009
    Posts
    56

    Default

    thx Lee Mac, works perfect. This is what i need. thx again

  8. #8
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,743

    Default

    Excellent, glad it worked OK for you.

    I had to mess around with it a bit to work with 3DPolylines, as I normally only work in 2D - but got it working in the end
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  9. #9
    Full Member
    Using
    Civil 3D 2012
    Join Date
    Jan 2009
    Posts
    56

    Default

    Lee mac:

    sorry it doesnt work like a charm, i notice that if i had a lot of polilys , coordinates get in mess, basicly the first poly is OK then the second poly had 2 times more vertex, i try to corect this but i didnt succses.
    any idea. & also if can be in front of coordinates the name of poly?

    thx

  10. #10
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,743

    Default

    Registered forum members do not see this ad.

    I'll have a look at it
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

Similar Threads

  1. Is it possible to read a STL (lithography) file using AutoCAD2008?
    By aprasad in forum AutoCAD 3D Modelling & Rendering
    Replies: 1
    Last Post: 14th Aug 2008, 01:24 am
  2. cui read only?
    By hazardman in forum AutoCAD Drawing Management & Output
    Replies: 2
    Last Post: 26th May 2007, 06:14 pm
  3. Is it possible to make a read-only sysvar a read/write var?
    By whatispunk in forum AutoCAD General
    Replies: 1
    Last Post: 11th Mar 2006, 11:49 am

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