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
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
Solved by pbejse. Go to Solution.
@ni-ramir wrote:
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
Can you please save your drawing to somethiong like 2009 version, <tried to convert but there's a "warning message">
@ni-ramir wrote:
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).
AREA SEG. START X START Y END X END Y
AREA1 1 1028709.2752 1034581.4480 1028711.4463 1034621.5743
(defun c:Ltc (/ strnum _inside-p text ss Pline Txtinside i e dwgtocsv hit writcsv pts _pts spc cntr ) ; Label to CSV ;;; pBeFeb20014 ;;; ;;; http://en.wikipedia.org/wiki/Point_in_polygon ;;; ;;; even-odd rule ;;; (defun _inside-p (pt ent *spc* / YoRay len) (setq YoRay (vlax-invoke *spc* 'AddRay pt (polar pt 0 1) ) ) (setq len (length (vlax-invoke YoRay 'intersectwith ent acextendnone ) ) ) (vla-delete YoRay) (not (zerop (rem len 2))) ) (setq spc (vlax-get (vla-get-ActiveLayout (setq aDoc (vla-get-activedocument (vlax-get-acad-object))) ) 'Block ) _r (lambda (v) (rtos v 2 2)) dz (getvar 'dimzin) ) (setvar 'Dimzin 0) (if (and (= 1 (getvar 'Dwgtitled)) (setq text nil Pline nil Txtinside nil ss (ssget "_X" (list '(0 . "TEXT,LWPOLYLINE") '(8 . "vias_polylineas") (cons 410 (getvar 'ctab)) ) ) ) ) (progn (repeat (setq i (sslength ss)) (setq e (vlax-ename->vla-object (ssname ss (setq i (1- i))))) (if (eq "AcDbText" (vla-get-ObjectName e)) (setq text (cons (list e (vlax-get e 'InsertionPoint)) text)) (setq Pline (cons e Pline)) ) ) (foreach itm text (if (setq hit (vl-some '(lambda (pl) (if (_inside-p (cadr itm) pl spc) (list (car itm) pl) ) ) pline ) ) (setq Txtinside (cons hit Txtinside) ) ) ) (setq dwgtocsv (strcat (getvar 'Dwgprefix) (vl-filename-base (getvar 'DWgname)) ".csv" ) ) (setq writcsv (open dwgtocsv "w")) (write-line (strcat "AREA,SEG.,START X,START Y,END X,END Y") writcsv ) (foreach tx Txtinside (setq _pts nil label (vla-get-textstring (car tx)) pts (vlax-get (cadr tx) 'Coordinates) ) (while (setq a (car pts) b (cdr pts) ) (setq _pts (cons (list a (car b)) _pts)) (setq pts (cdr b)) ) (setq cntr 0) (mapcar '(lambda (c d) (write-line (setq prnc (strcat label "," (itoa (setq cntr (1+ cntr))) "," (_r (car c)) "," (_r (cadr c)) "," (_r (car d)) "," (_r (cadr d)) ) ) writcsv ) (princ (vl-string-translate "," " " prnc)) ) _pts (cdr _pts) ) ) (close writcsv) ;(textscr) (startapp "notepad" dwgtocsv) ) ) (setvar 'Dimzin dz) (princ) )
command: ltc
HTH
@ni-ramir wrote:
....
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. ... I need ... (the name of the area inside the polyline). Here's an example of how I wish the output could be (txt, csv or xls).
....
AREA SEG. START X START Y END X END Y
AREA1 1 1028709.2752 1034581.4480 1028711.4463 1034621.5743
....
Here's a version that makes a .txt file:
(defun C:PSL ; = Polyline Segment Listing
(/ file ss plinc pl verts seginc)
(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 (strcat "Area " (itoa (1+ plinc)));;; <-- YOUR HEIGHT at beginning [omit for fixed-height Style]
); command
); repeat
); if
(close file)
(princ)
); defun
I'm attaching a new file with more information. It has some streets defined as polylines.
@ni-ramir wrote:
Kent1Cooper thanks for your reply! I get this error when running the lisp: ; error: bad argument type: streamp nil
It works for me, and in a different drawing and with a greater number of closed Polylines than I tested it with.
A Search for STREAMP brought up several threads. It's probably a result of trying to write to a file that doesn't exist. That could be because you have misspelled something in the file path. Or it could be that the file was opened before but you cancelled before finishing the routine, and the file was not properly closed, in which case it won't be able to open it again. Try copying out and pasting in just the (open) line, and be sure it doesn't return nil, which would mean it couldn't open the file. If it crashed before, and that file was opened somehow but never closed, you may need to close and re-open AutoCAD to clear it. The routine could have a check built into it that the file was successfully opened, if you like.
[I couldn't test your drawing to try it, because I'm in an older version of AutoCAD, and need to use DWG TrueView converter to open newer-version drawings, but it won't convert drawings created in an Educational version.]