converting text coordinates to polyline

converting text coordinates to polyline

mirqalib.m
Enthusiast Enthusiast
3,720 Views
31 Replies
Message 1 of 32

converting text coordinates to polyline

mirqalib.m
Enthusiast
Enthusiast

Hello. I have a text that I have shown below. When I copy this text and paste it on the autocad command line, I want a polyline line with the x-y coordinates in the second and third columns there. So I want a lisp that will create a five-point parcel. I need help with this. Thank you in advance.

1 670828.0000 4433484.0000 UTM 39 1 - 2 36.9
2 670915.0000 4433441.0000 UTM 39 2 - 3 12.9

3 670879.0000 4433356.0000 UTM 39 3 - 4 6.3

0 Likes
Accepted solutions (2)
3,721 Views
31 Replies
Replies (31)
Message 21 of 32

komondormrex
Mentor
Mentor

seems you have tabs as delimiters in your mtext in autocad. check update above.

0 Likes
Message 22 of 32

mirqalib.m
Enthusiast
Enthusiast

the above coordinates are falling. After a few tries. Others are having problems with the coordinates I copied and pasted. Or the line appears in the distance. I can't reach it.

0 Likes
Message 23 of 32

komondormrex
Mentor
Mentor

make a couple of txt files from failing coordinates and post them here. i mean copy your coordinates and paste them into txt file and save it.

0 Likes
Message 24 of 32

mirqalib.m
Enthusiast
Enthusiast

Yes, I copied the text above, and in the first one, the coordinates appear on the screen as they are. In the second try, the result is reached. That is, it draws. But the other coordinates I copied do not draw.

0 Likes
Message 25 of 32

mirqalib.m
Enthusiast
Enthusiast

Yes, I copied the text above, and in the first one, the coordinates appear on the screen as they are. In the second try, the result is reached. That is, it draws. But the other coordinates I copied do not draw.

0 Likes
Message 26 of 32

komondormrex
Mentor
Mentor
Accepted solution

supposing first three value will stay in ONE text, check this.

 

 

 

(defun c:paste_draw_pline (/ ename_mark text_object ename_mark_list coordinates_list)
	(setq ename_mark (vla-get-count (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object)))))) 
	(command "_pasteclip" (list 0 0))
	(vla-put-width (vlax-ename->vla-object (entlast)) 0)
	(command "_explode" (entlast))
	(repeat (- (vla-get-count (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))) ename_mark)
		(setq ename_mark_list  (read (strcat "(" (vla-get-textstring (setq text_object (vla-item (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
											        	 ename_mark
											       )
									     )
						         )
						     ")"
					     )
				       )
		      coordinates_list (append coordinates_list (list (list (cadr ename_mark_list) (caddr ename_mark_list))))
		)
		(vla-erase text_object)
	)
	(vla-put-closed
		(vla-addlightweightpolyline (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
									(vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 1 (* 2 (length coordinates_list)))) 
														 (apply 'append coordinates_list)
									)
		)
		:vlax-true
	)
	(princ)
)

 

 

 

0 Likes
Message 27 of 32

mirqalib.m
Enthusiast
Enthusiast

thanks.it works.but again the coordinates stick to the screen. Sticks to the 0.0 point. succeeds on subsequent attempts

0 Likes
Message 28 of 32

komondormrex
Mentor
Mentor
Accepted solution

the problem was due to newly created dwg file with nil entlast. check upgrade above.

0 Likes
Message 29 of 32

Kent1Cooper
Consultant
Consultant

The idea of pasting the copied content into the drawing, rather than into the Command line, that @komondormrex used in Message 19, would not have occurred to me, but is just the way of getting multi-line content in that I wondered whether someone would think of.

Doing that, I found that Exploding the resulting Mtext as they did causes complications, because the tabs get changed to varying numbers of spaces [not even the same number in the same position in different lines].  And if it's sufficiently longer, pulling the text content out of entity data would be complicated by its being split up among more than one data entry [DXF codes 3 and 1, not just 1 when it's short enough].

BUT the (getpropertyvalue) approach for getting the text content keeps it all in one string no matter how long, and preserves the tabs, and has new-line characters inside the one string, instead of being separate strings for each line.

So here's a way to use those benefits, again starting with your having first put content from the other program [as in your xy.txt file] into the clipboard:

(defun C:TEST (/ beforeTab afterTab afterNL str X+ X Y+ Y pts)
  (defun beforeTab (str) (substr str 1 (vl-string-position 9 str)))
  (defun afterTab (str) (substr str (+ (vl-string-position 9 str) 2)))
  (defun afterNL (str) (substr str (+ (vl-string-position 10 str) 2)))
  (command "_.pasteclip" (getvar 'viewctr))
  (setq str (getpropertyvalue (entlast) "Text"))
  (entdel (entlast))
  (while (vl-string-position 10 str); still any new-line character(s)?
    (setq
      X+ (afterTab str) X (beforeTab X+)
      Y+ (afterTab X+) Y (beforeTab Y+)
      pts (cons (list (atof X) (atof Y)) pts)
      str (afterNL X+); to next line [skip UTM etc.]
    ); setq
  ); while
  (setq ; for last line remaining
    X+ (afterTab str) X (beforeTab X+)
    Y+ (afterTab X+) Y (beforeTab Y+)
    pts (cons (list (atof X) (atof Y)) pts)
  ); setq
  (command "_.pline")
  (mapcar 'command pts)
  (command "_close" "_.zoom" "_object" (entlast) "")
  (prin1)
)

[Turn off running Osnap first, or that can be built in, along with other usual features.]

Kent Cooper, AIA
0 Likes
Message 30 of 32

mirqalib.m
Enthusiast
Enthusiast
Thank you.It was very successful.
0 Likes
Message 31 of 32

mirqalib.m
Enthusiast
Enthusiast
thank you for the trouble.
0 Likes
Message 32 of 32

komondormrex
Mentor
Mentor

your welcome)

0 Likes