Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Name and export multiple polyline coordinates

25 REPLIES 25
SOLVED
Reply
Message 1 of 26
ni-ramir
2328 Views, 25 Replies

Name and export multiple polyline coordinates

Hi all,

 

I'm looking for an lsp that can export the coordinates of the segments of multiple polylines at once. I also need to name each polyline so that I can identify them in my drawing. Is there any way to do this? I've seen the posts on the Multiple Polyline Export Challenge post, but here I need something more (the name of the area inside the polyline). Here's an example of how I wish the output could be (txt, csv or xls).

Thank you so much for your help.

 

AREA SEG. START X START Y END X END Y 
AREA1 1 1028709.2752 1034581.4480 1028711.4463 1034621.5743
AREA1 2 1028711.4463 1034621.5743 1028759.7528 1034617.7786
AREA1 3 1028759.7528 1034617.7786 1028774.4076 1034583.6170
AREA1 4 1028774.4076 1034583.6170 1028754.3251 1034533.1879
AREA1 5 1028754.3251 1034533.1879 1028704.3902 1034531.5612
AREA1 6 1028704.3902 1034531.5612 1028709.2752 1034581.4480
AREA2 1 1028701.6764 1034497.3996 1028717.4167 1034507.1601
AREA2 2 1028717.4167 1034507.1601 1028735.8709 1034474.6252
AREA2 3 1028735.8709 1034474.6252 1028715.7884 1034444.2593
AREA2 4 1028715.7884 1034444.2593 1028683.2222 1034457.2733
AREA2 5 1028683.2222 1034457.2733 1028670.1957 1034491.9771
AREA2 6 1028670.1957 1034491.9771 1028688.6499 1034511.4980
AREA2 7 1028688.6499 1034511.4980 1028701.6764 1034497.3996
AREA3 1 1028784.7202 1034443.1748 1028831.9413 1034423.1117
AREA3 2 1028831.9413 1034423.1117 1028806.9738 1034399.7950
AREA3 3 1028806.9738 1034399.7950 1028784.7202 1034443.1748

25 REPLIES 25
Message 21 of 26
ni-ramir
in reply to: Kent1Cooper

If you want I can upload the file as a 2004 Autocad File.
Message 22 of 26
Kent1Cooper
in reply to: ni-ramir


@ni-ramir wrote:
Hi Kent. Thanks, it worked. I didn't have the folder c:/Temp/ created. I got one more question. If I have the polylines already named, how can I make the extraction with those names? (For example, street names, or park names that are set to the areas previously).

Are the names "attached" in some way to the Polylines that define the areas, or are they just Text entities, presumably inside or near the Polylines?

Kent Cooper, AIA
Message 23 of 26
ni-ramir
in reply to: Kent1Cooper

With your lisp, after exporting the data, I modify the names that are given to the areas of the polylines (Area 1, Area 2, etc. to 22nd ST, Park NR, etc.). It would be really greta if I could export the data again with the new names edited by me.
Message 24 of 26
pbejse
in reply to: ni-ramir


@ni-ramir wrote:
Hi pbejse, I just found out that it works only for three polylines, or areas. How can I make it work for every polyline I make in the drawing? It's the only thing missing.

I see. Try the attached modified lisp code ni-ramir. Think it should work now.

 

 

Message 25 of 26
Kent1Cooper
in reply to: ni-ramir


@ni-ramir wrote:
With your lisp, after exporting the data, I modify the names that are given to the areas of the polylines (Area 1, Area 2, etc. to 22nd ST, Park NR, etc.). It would be really greta if I could export the data again with the new names edited by me.

The following does that, in limited testing.  It does require that you edit the content of all the area labels you want to within the one text-editing command that it calls up, inside the routine.  It leaves the original file [with areas called "Area1" etc.], and makes an additional file with a "2" on the end of the otherwise-same file name, imposing the changed area label content on each appropriate line.

 

(defun C:PSL ; = Polyline Segment Listing
  (/ file ss plinc pl verts seginc txtElist txtClist file1 file2 txtline area# txtent)
  (setq
    file (open (strcat "C:/temp/" (substr (getvar 'dwgname) 1 (- (strlen (getvar 'dwgname)) 4)) "-PlSegs.txt") "w")
      ;; YOUR FILE PATH AND NAMING STANDARD --^
    ss (ssget '((0 . "LWPOLYLINE")))
    plinc -1
  ); setq
  (write-line (strcat (getvar 'dwgname) " Polyline Segments:") file); [optional]
  (write-line "AREA  SEG.  START X  START Y  END X  END Y" file)
  (if ss
    (repeat (sslength ss)
      (setq
        pl (ssname ss (setq plinc (1+ plinc)))
        verts (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget pl)))
        seginc 0
      ); setq
      (repeat (1- (length verts))
        (write-line
          (strcat
            "Area" (itoa (1+ plinc)) "  " (itoa (1+ seginc)) "  "
            (rtos (car (nth seginc verts)) 2 4) " " (rtos (cadr (nth seginc verts)) 2 4) "  "
            (rtos (car (nth (setq seginc (1+ seginc)) verts)) 2 4) " " (rtos (cadr (nth seginc verts)) 2 4)
          ); strcat
          file
        ); write-line
      ); repeat
      (if (vlax-curve-isClosed pl)
        (write-line
          (strcat
            "Area" (itoa (1+ plinc)) "  " (itoa (1+ seginc)) "  "
            (rtos (car (last verts)) 2 4) " " (rtos (cadr (last verts)) 2 4) "  "
            (rtos (car (nth 0 verts)) 2 4) " " (rtos (cadr (nth 0 verts)) 2 4)
          ); strcat
          file
        ); write-line
      ); if [closed]
      (vla-getboundingbox (vlax-ename->vla-object PL) 'minpt 'maxpt)
      (command "_.text" "_style" "ROMANS" "mc" "_none" ;;; <-- YOUR STYLE NAME
        (mapcar '/ (mapcar '+ (vlax-safearray->list minpt) (vlax-safearray->list maxpt)) '(2 2 2))
        1.0 0 (setq txt (strcat "Area" (itoa (1+ plinc))));;; <-- YOUR HEIGHT at beginning [omit for fixed-height Style]
      ); command
      (setq
        txtElist (cons (entlast) txtElist); Text entity
        txtClist (cons txt txtClist); its text content
      ); setq
    ); repeat
  ); if
  (close file)
  (command "_.ddedit") (while (> (getvar 'cmdactive) 0) (command pause)); change Text label contents
  (setq
    file1 (open (strcat "C:/temp/" (substr (getvar 'dwgname) 1 (- (strlen (getvar 'dwgname)) 4)) "-PlSegs.txt") "r")
    file2 (open (strcat "C:/temp/" (substr (getvar 'dwgname) 1 (- (strlen (getvar 'dwgname)) 4)) "-PlSegs2.txt") "w")
      ;; YOUR FILE PATH AND NAMING STANDARD --^ [both lines]
  ); setq
  (while (setq txtline (read-line file1))
    (if (wcmatch (substr txtline 1 5) "Area#"); after initial two lines
      (setq
        area# (substr txtline 1 (vl-string-search " " txtline)); "Area" plus integer [one or more digits]
        txtent (nth (vl-position area# txtClist) txtElist); the Text label entity
        txtline (vl-string-subst (cdr (assoc 1 (entget txtent))) area# txtline); replace designator with its current content
      ); setq
    ); if
    (write-line txtline file2); put revised line into other file
  ); while
  (close file1)
  (close file2)
  (princ)
); defun

Kent Cooper, AIA
Message 26 of 26
ni-ramir
in reply to: Kent1Cooper

Kent and pbejse, Thank you so much for tour solutions! Both of them work like a charm! 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost