converting text coordinates to polyline

converting text coordinates to polyline

mirqalib.m
Enthusiast Enthusiast
3,734 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,735 Views
31 Replies
Replies (31)
Message 2 of 32

Kent1Cooper
Consultant
Consultant

In what format do you have that text?  As a plain text file with multiple lines, and spaces between [what an on-line translator calls] columns?  As a spreadsheet file of some kind?  As something else?

 

If it's all one collective multi-line paste-in, I don't think it can be used that way to do what you want.  I think it would need be in a file of some kind that AutoLisp can read from, and a routine would need to look at every line of text individually, to pull out only the parts you want, and to put them together in a way that it can apply them in a PLINE or LINE command.

 

An example file would be helpful.  For example, do the line numbers ever get to two [or more] digits?  In other words, could a routine read every line starting from the third character, or would it need to start from the first character following a space, wherever that may occur?  Could parcel boundaries ever include arcs?  How would that be indicated in the text?

Kent Cooper, AIA
0 Likes
Message 3 of 32

Sea-Haven
Mentor
Mentor

1 322843.6900 4423242.0197 UTM 39 1 - 2 36.9

x= 322843.6900

y= 4423242.0197

Z= 36.9

 

is that correct ?

0 Likes
Message 4 of 32

Kent1Cooper
Consultant
Consultant

@Sea-Haven wrote:

1 322843.6900 4423242.0197 UTM 39 1 - 2 36.9

x= 322843.6900

y= 4423242.0197

Z= 36.9

 

is that correct ?


If the web translator got it right, they want only the 2nd & 3rd terms, i.e. X and Y.  That's not difficult, but I'm still waiting to see what the format or file type of the text content is.

Kent Cooper, AIA
0 Likes
Message 5 of 32

mirqalib.m
Enthusiast
Enthusiast

Hi. Here 36.9 is not Z. 36.9 distance. I load the text here. I don't need numbers and distances. When I copy the text, they are copied too. At once, these coordinates can be more than five. I know how to combine them in excel and copy the merger and create a parcel in autocad with the pline command. But it takes a long time. Thank you for your attention.

0 Likes
Message 6 of 32

Kent1Cooper
Consultant
Consultant

Minimally tested:

(defun C:PFTF ; = Parcel From Text File
  (/ beforeTab afterTab f 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)))
  (if (setq f (getfiled "Text File for Parcel" "" "txt" 0))
    (progn ; then
      (setq f (open f "r"))
      (while (setq str (read-line f))
        (setq
          X+ (afterTab str)
          X (beforeTab X+)
          Y+ (afterTab X+)
          Y (beforeTab Y+)
          pts (cons (list (atof X) (atof Y)) pts)
        ); setq
      ); while
      (command "_.pline")
      (mapcar 'command pts)
      (command "_close")
      (close f)
    ); progn
  ); if
  (prin1)
)

It did this from your sample file:

Kent1Cooper_0-1688847589236.png

 

It depends on the text file being like your sample, containing only such informational lines, with no header line or anything, and using tabs [9 is the ASCII code for tab] between elements.

 

You could build a starting folder location into the (getfiled) function if you usually keep those files in the same place.  You could still navigate from there to different folder locations when needed.

 

I didn't include turning off Object Snap, but that's advisable.  It could also use some of the other typical enhancements -- set a Layer, *error* handling if Osnap is controlled, etc.

 

Consider whether the drawn direction matters.  This draws it in the reverse order of the lines in the file, but that's easily corrected with a very small amount of additional code, if it matters.

Kent Cooper, AIA
0 Likes
Message 7 of 32

mirqalib.m
Enthusiast
Enthusiast

This code worked. But I am copying the text from another program. It will take time to copy and insert the text and run the code. I am looking for a lisp that draws the text by copying and pasting it directly in autocada.

0 Likes
Message 8 of 32

Kent1Cooper
Consultant
Consultant

@mirqalib.m wrote:

This code worked. But I am copying the text from another program. It will take time to copy and insert the text and run the code. I am looking for a lisp that draws the text by copying and pasting it directly in autocada.


That may be time you need to take.  How did you make the xy.txt file?  By simply pasting what you copied out from the other program into a plain-text editor such as Notepad?  If so, I don't see how what you want can happen by pasting into AutoCAD in that format.

 

In AutoCAD at the Command line, if I just copy the contents of your XY.txt file and paste them in, as should be obvious it starts right off with:

Command: 1 Unknown command "1". Press F1 for help.

Command: 322843.6900 Unknown command "6900". Press F1 for help.

... and so on.  [I don't know why it takes only what follows the decimal point, but regardless....]

 

I can't picture any way to get what you want without something like an intermediary external file and AutoLisp routine to do the fishing for the pieces that are relevant, and the putting of them into the context of some drawing command(s), and the ignoring of the rest.  Since that ignorable stuff is interspersed before and around and between the relevant stuff, it has to be something that can look at each line independently, so I can't imagine how a wholesale pasting of all of it could be interpreted into the right elements, without the content being in a file with separatable lines that it can take one at a time with something like the (read-line) function in my suggested code.

 

I wanted to try pasting wholesale in a way that AutoLisp could use without an external file.  I copied to the clipboard the contents of your sample file.  If I try to put it into a variable by pasting in answer to a (getstring) function, even allowing spaces, I get the first line into the variable, but only the first line, and then it goes back to the Command prompt so the next piece of content sends it into unknown-command mode.

 

There may be a way I don't know about to have it construct such a file out of pasted-in content, and then process that file.  But the way to put text into a file is (write-line), which writes out text strings, so I think it would also depend on (getstring) for input, and that can't take the whole content at once.

 

I'd be interested in anyone else's notions about how to get multiple-line text content like what's in xy.txt collectively into a single variable so AutoLisp could try to do something with it without an external file.

Kent Cooper, AIA
0 Likes
Message 9 of 32

komondormrex
Mentor
Mentor

you may concatenate with formula a string like that in excel using cells with your x and y values, copy/paste it into command line in autocad and hit <enter>.

(command "_pline" "x1,y1" "x2,y2" "x3,y3" "x4,y4" "x5,y5" "_c" )

 

komondormrex_0-1689011506462.png

 

0 Likes
Message 10 of 32

mirqalib.m
Enthusiast
Enthusiast

When I paste the text I copied (command "_pline" "x1,y1" "x2,y2" "x3,y3" "x4,y4" "x5,y5" "_c" ) I want it to fall like this. it could be.

0 Likes
Message 11 of 32

Kent1Cooper
Consultant
Consultant

@komondormrex wrote:

you may concatenate with formula a string like that in excel using cells with your x and y values, copy/paste it into command line in autocad and hit <enter>.


So that means putting it into an Excel file, and extracting the information from the cells to put into a formula string, with the other parts to make it into an AutoCAD command to draw the parcel boundary.  "That will take time" [see Message 7], certainly at least as much time as it will take to put it into the plain-text file they already have [see Message 5] and use a routine that can work with that [see Message 6].  Is there any advantage to going through Excel?

Kent Cooper, AIA
0 Likes
Message 12 of 32

komondormrex
Mentor
Mentor

well, it kinda simpler to copy/paste text from other software into same cells in excel to get a string to copy/paste to autocad, rather than making file(s) with every set of vertices, i humbly suppose. i would certainly do it like that.

0 Likes
Message 13 of 32

Kent1Cooper
Consultant
Consultant

@komondormrex wrote:

well, it kinda simpler to copy/paste text from other software into same cells in excel .... rather than making file(s) ....


Since we don't know anything about what the other software is or in what format it produces what they copy from it, I would not assume that the idea of "same cells" is relevant.  And it still involves making files, and needing something to take only the relevant pieces of information out, and ignore the rest.  @mirqalib.m, can you shed any light?

Kent Cooper, AIA
0 Likes
Message 14 of 32

Sea-Haven
Mentor
Mentor

The file looks like it may have come from a GPS data collector, this is causing problems for people to solve your request, can you post a full file that has not had the points pulled out of it. If it is a text file may be able to read it ignoring incorrect lines.

0 Likes
Message 15 of 32

mirqalib.m
Enthusiast
Enthusiast

Hello. I'm uploading the jpg file of the coordinates I copied here. This is a personal program. I click on the piece and press the right button to bring up this coordinate table. Then I copy over it. As I mentioned above, I used to combine it with the help of excel and switch to autoca, paste the polyline to the command line with the command and make the line there. I want to create a parcel by pasting the text I copied into excel or to the autocadin command line without pasting it elsewhere. Also, these coordinates can be n in number.

0 Likes
Message 16 of 32

komondormrex
Mentor
Mentor

that is exactly what i am talking about

komondormrex_2-1689161867586.png

 

 

 

 

 

0 Likes
Message 17 of 32

mirqalib.m
Enthusiast
Enthusiast

I was doing this. I made the shape above. But I want to do this in autocad.

0 Likes
Message 18 of 32

Kent1Cooper
Consultant
Consultant

@mirqalib.m wrote:

.... I want to create a parcel by pasting the text I copied into excel or to the autocadin command line without pasting it elsewhere. ....


I just don't think it's going to be possible to paste it into the AutoCAD command line without the "elsewhere" ingredient -- re-read Message 8.

Kent Cooper, AIA
0 Likes
Message 19 of 32

komondormrex
Mentor
Mentor

then try this. load it, copy your text to clipboard and run paste_draw_pline command in autocad. it will paste your text and draw a pline with coordinates copied.

 

;*********************************************************************************************************************************

(defun string_to_list (input_string delimiter / delimiter_position output_list)
	(while (setq delimiter_position (vl-string-search delimiter input_string 0))
		(setq output_list (append output_list (list (substr input_string 1 delimiter_position)))
			  input_string (substr input_string (+ 2 delimiter_position))
		)
	)
	(append output_list (list input_string))
)

;*********************************************************************************************************************************

(defun c:paste_draw_pline (/ ename ename_mark_list coordinates_list)
	(setq ename_mark (entlast))
	(command "_pasteclip" (list 0 0))
	(command "_explode" (entlast))
	(while (setq ename (entnext ename_mark))
		(setq ename_mark_list (string_to_list (cdr (assoc 1 (entget ename))) "\t")  
			  coordinates_list (append coordinates_list (list (list (atof (cadr ename_mark_list)) (atof (caddr ename_mark_list)))))
		)
		(entdel ename)
	)
	(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 20 of 32

mirqalib.m
Enthusiast
Enthusiast

making the screen.

0 Likes