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
2331 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 2 of 26
devitg
in reply to: ni-ramir

Upload a sample dwg 

Message 3 of 26
ni-ramir
in reply to: devitg

Here's the dwg attached with the three polylines. Thanks!

Message 4 of 26
devitg
in reply to: ni-ramir

Seem to be  you speak spanish, me too,  please contact me.  

Message 5 of 26
ni-ramir
in reply to: devitg

can't it be through the forum?
Message 6 of 26
devitg
in reply to: ni-ramir

Yes.

 

Message 7 of 26
ni-ramir
in reply to: devitg

Ok perfecto! Me podrías ayudar con eso?
Message 8 of 26
devitg
in reply to: ni-ramir

No
Message 9 of 26
ni-ramir
in reply to: devitg

devitg If you're not going to help then why are you replying to my post? Thanks for nothing.

Does anyone else know how I could do this? I'ld really appreciate your help please.
Message 10 of 26
pbejse
in reply to: ni-ramir


@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">

 

Message 11 of 26
ni-ramir
in reply to: pbejse

Sure! Attached is the file saved as a 2007 version.

Message 12 of 26
pbejse
in reply to: ni-ramir


@ni-ramir wrote:

Sure! Attached is the file saved as a 2007 version.


Ok, i'll have a look-see, and please be patient ni-ramir 🙂

Message 13 of 26
pbejse
in reply to: ni-ramir


@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

Message 14 of 26
ni-ramir
in reply to: pbejse

Thank you pbejse!! It works GREAT!!
Message 15 of 26
Kent1Cooper
in reply to: ni-ramir


@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

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

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.
Message 17 of 26
ni-ramir
in reply to: Kent1Cooper

Kent1Cooper thanks for your reply! I get this error when running the lisp: ; error: bad argument type: streamp nil
Message 18 of 26
ni-ramir
in reply to: ni-ramir

I'm attaching a new file with more information. It has some streets defined as polylines.

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


@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.]

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

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).

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

Post to forums  

Autodesk Design & Make Report

”Boost