Jump to content

Using POINTPLT.LSP to plot X,Y,Z points with alphanumeric labels


psychopomp1

Recommended Posts

Hi,

I came across a Lisp routine which is supposed to let me plot X,Y,Z coordinates and text labels from a text file. I have loaded the Lisp routine into AutoCad 2022 and when i run the routine i am asked to "enter points filename" but no matter what i enter i get the message "too many arguments". Any idea what i'm doing wrong? Below is the contents from the lisp file, thanks

 

; POINTPLT is a simple AutoLSIP program that will plot a coordinate points file
; in AutoCAD.  To run POINTPLT, load POINTPLT.LSP as you would any normal
; AutoLISP file (see AutoCAD Reference Manual), type "POINTPLT" and press
; [Enter].  POINTPLT will first prompt you for an input coordinate filename.
; You must enter a vaild DOS filename at this point.  The input coordinate file
; must be in the following format:
;
;      POINT NO.   NORTHING(y)   EASTING(x)   ELEVATION(z)
;
; A sample input coordinate file (SAMPLE.DAT) is included with POINTPLT.
;
; POINTPLT uses the default (current) text style and layer.  However, the
; current text style must have a defined height (height must not be "0").
;
; If you have any questions or comments concerning POINTS, I may be reached
; via THE SPECTRUM BBS þ (501) 521-5639
;
;-------------------------------------------------------------------------------
; * ERROR Trapping *
;
(defun *ERROR* ()
   (eop)
)
;-------------------------------------------------------------------------------
; * End of program *
;
(defun EOP ()
   (setvar "CMDECHO" POINTSPLT_CE)
   (princ)
)
;-------------------------------------------------------------------------------
; * Main Program *
;
(defun C:POINTPLT ()
   (setq POINTSPLT_CE (getvar "CMDECHO"))
   (setvar "CMDECHO" 0) ;Turn "Command Echo" off

   (prompt "\n ")
   (prompt "\nP O I N T P L T  v1.0 -- Copyright (c) 1992 by Kurtis J. Jones / -Mate Software")
   (prompt "\n ")

   (setq IN_FILE (open (getstring "\nEnter points filename: ") "r"))
   (prompt "\n ")
   (setq POINT_LINE 0) ;Force at least one pass thru the "while" loop
   (while (/= POINT_LINE nil)
      (setq POINT_LINE (read-line IN_FILE)) ;Read POINT_LINE from input file
      (if (/= POINT_LINE nil)
         (progn
            (setq POINT_LINE (strcat "(" POINT_LINE ")")) ;Correct format
            (setq POINT_LINE (read POINT_LINE))           ;Convert to list
            (setq POINT_NO (nth 0 POINT_LINE))            ;Get the point number
            (prompt (strcat "\nPlotting point no. " (itoa POINT_NO)))
            (setq POINT
               (list
                  (nth 2 POINT_LINE) ;Get easting
                  (nth 1 POINT_LINE) ;Get northing
                  (nth 3 POINT_LINE) ;Get elevation
               )
            )
            (command "POINT" POINT)
            (command "TEXT" POINT 0.0 (strcat " " (itoa POINT_NO)))
         )
      )
   )
   (close IN_FILE)
   (prompt "\nPOINTPLT finished")
   (prompt "\n ")
   (eop)
)

 

Edited by SLW210
Added Code Tags!
Link to comment
Share on other sites

Maybe there are space characters in the filename.

Getstring stops reading when it encounters a space character.

 

Maybe this helps.  The T means that getstring will accept space characters.

 (getstring "\nEnter points filename: " T)

Edited by Emmanuel Delay
  • Like 1
Link to comment
Share on other sites

(setq IN_FILE (open (getfiled "\nSelect Points File" (getvar 'DWGPREFIX) "txt" 16) "r"))

 

This will start in the same folder as the drawing change "txt" to the file extension your looking for.

 

--edit--

 

I would also make sure to the file is formatted correctly.

when I make a point its asking for x y z cords in that order but the lisp seems to be pulling  P# y x z.

 

Also Im on BrisCAD so i had to update the text command to work properly

 

Edited by mhupp
  • Like 3
Link to comment
Share on other sites

updated the lisp with the following

- entmake for point and text (faster)

- got rid of nth its slower then then car cadr caddr last

- updated while to combined lines of code

 

Also I don't think the easting and northing are in the right order but left it like the lisp had it. so if your points are in the wrong spot maybe update to below
 

(setq POINT
  (list
    (cadr POINT_LINE) ;Get x
    (caddr POINT_LINE) ;Get y
    (last POINT_LINE) ;Get z
  )
)

 

; POINTPLT is a simple AutoLSIP program that will plot a coordinate points file
; in AutoCAD.  To run POINTPLT, load POINTPLT.LSP as you would any normal
; AutoLISP file (see AutoCAD Reference Manual), type "POINTPLT" and press
; [Enter].  POINTPLT will first prompt you for an input coordinate filename.
; You must enter a vaild DOS filename at this point.  The input coordinate file
; must be in the following format:
;
;      POINT NO.   NORTHING(y)   EASTING(x)   ELEVATION(z)
;
; A sample input coordinate file (SAMPLE.DAT) is included with POINTPLT.
;
; POINTPLT uses the default (current) text style and layer.  However, the
; current text style must have a defined height (height must not be "0").
;
; If you have any questions or comments concerning POINTS, I may be reached
; via THE SPECTRUM BBS þ (501) 521-5639
;
;-------------------------------------------------------------------------------
; * ERROR Trapping *
;
(defun *ERROR* ()
   (eop)
)
;-------------------------------------------------------------------------------
; * End of program *
;
(defun EOP ()
   (setvar "CMDECHO" POINTSPLT_CE)
   (princ)
)
;-------------------------------------------------------------------------------
; * Main Program *
(defun C:POINTPLT (/ IN_FILE POINT_LINE POINT_NO POINT)
  (setq POINTSPLT_CE (getvar "CMDECHO"))
  (setvar "CMDECHO" 0) ;Turn "Command Echo" off
  (prompt "\n\nP O I N T P L T  v1.0 -- Copyright (c) 1992 by Kurtis J. Jones / -Mate Software\n\n")
  (setq IN_FILE (open (getfiled "\nEnter points filename: " (getvar 'DWGPREFIX) "txt" 16) "r"))
  (while (setq POINT_LINE (read (strcat "(" (read-line IN_FILE) ")"))) ;Read POINT_LINE from input file
   (setq POINT_NO (car POINT_LINE))            ;Get the point number
   (prompt (strcat "\nPlotting point no. " (itoa POINT_NO)))
   (setq POINT
     (list
       (caddr POINT_LINE) ;Get easting
       (cadr  POINT_LINE) ;Get northing
       (last POINT_LINE) ;Get elevation
     )
   )
   (entmake (list '(0 . "POINT") (cons 10 POINT)))
   (entmake (list '(0 . "TEXT") (cons 10 POINT) '(40 . 1) (cons 1 (itoa POINT_NO))))
  )
  (close IN_FILE)
  (prompt "\nPOINTPLT finished")
  (prompt "\n ")
  (eop)
)

 

Edited by mhupp
  • Like 4
Link to comment
Share on other sites

@mhupp

Your edited routine works! Thank you! At least I am now prompted to select an input file (previously this was not the case). But some issues when running your routine:

 

1. Easting and Northing are wrong way around, how to correct this? Eg If file contains X, Y, Z then its plotted as Y,X,Z in AutoCAD.

2.  Anyway to also get alpha characters included in labels as well as characters such as underscore and hyphen? At present routine only accepts numbers as labels

3. Anyway to save lisp routine in AutoCAD permanently? At present i have to reload the routine by running APPLOAD command if AutoCAD is closed and then re-opened.

4. Is it possible to draw a small rectangle  or circle (instead of a dot) at the plotted coordinates? The point coordinates will be denoting survey control points so would like a more appropriate symbol

5. Finally, even though the routine plots all points, at the last point it comes with the following error

"plotting point no. <xxxxx> error: bad argument type: stringp nil"

 

Thanks again! (and to other posters as well) 

 

 

Link to comment
Share on other sites

1. look at my post again I bring this up. - fixed

2. fixed tho point names cant have spaces (will mess up the list)

example

"point 1" - no good

"point-1" - good

 

3. appload startup suite (use add not remove just a picture i found online)

image.thumb.png.d6f7060a6cfab4db0f94706115be19a8.png

 

4. PTYPE

5. should be fixed now

 

-edit will update code later

 

; POINTPLT is a simple AutoLSIP program that will plot a coordinate points file
; in AutoCAD.  To run POINTPLT, load POINTPLT.LSP as you would any normal
; AutoLISP file (see AutoCAD Reference Manual), type "POINTPLT" and press
; [Enter].  POINTPLT will first prompt you for an input coordinate filename.
; You must enter a vaild DOS filename at this point.  The input coordinate file
; must be in the following format:
;
;   Point name (no spaces)  (X Cord) (Y Cord)   ELEVATION(z)
;
; A sample input coordinate file (SAMPLE.DAT) is included with POINTPLT.
;
; POINTPLT uses the default (current) text style and layer.  However, the
; current text style must have a defined height (height must not be "0").
;
; If you have any questions or comments concerning POINTS, I may be reached
; via THE SPECTRUM BBS þ (501) 521-5639
;
;-------------------------------------------------------------------------------
; * ERROR Trapping *
;
(defun *ERROR* ()
   (eop)
)
;-------------------------------------------------------------------------------
; * End of program *
;
(defun EOP ()
   (setvar "CMDECHO" POINTSPLT_CE)
   (princ)
)
;-------------------------------------------------------------------------------
; * Main Program *
(defun C:POINTPLT (/ IN_FILE POINT_LINE POINT_NO POINT)
  (setq POINTSPLT_CE (getvar "CMDECHO"))
  (setvar "CMDECHO" 0) ;Turn "Command Echo" off
  (prompt "\n\nP O I N T P L T  v1.0 -- Copyright (c) 1992 by Kurtis J. Jones / -Mate Software\n\n")
  (setq IN_FILE (open (getfiled "\nEnter points filename: " (getvar 'DWGPREFIX) "txt" 16) "r"))
  (while (setq POINT_LINE (read-line IN_FILE))
    (if (eq (length (setq POINT_LINE (read (strcat "(" POINT_LINE ")")))) 4)
      (progn
        (setq POINT_NO (vl-princ-to-string (car POINT_LINE)))
        (prompt (strcat "\nPlotting point no. " POINT_NO))
        (setq POINT
          (list
            (cadr POINT_LINE) ;Get easting
            (caddr  POINT_LINE) ;Get northing
            (last POINT_LINE) ;Get elevation
          )
        )
        (entmake (list '(0 . "POINT") (cons 10 POINT)))
        (entmake (list '(0 . "TEXT") (cons 10 POINT) '(40 . 1) (cons 1 POINT_NO)))
      )
    )
  )
  (close IN_FILE)
  (prompt "\nPOINTPLT finished")
  (eop)
  
)

 

Edited by mhupp
Code Updated
  • Like 1
Link to comment
Share on other sites

Point 1 should work, but with no file to look at, if we look at most feature survey points they have codes that can be alpha, number or alphanumeric etc even smart codes 01F*02F, TR6-3 and so on. 

 

So if doing this all the time you should look at programs that are designed to do this. 1st example of course is CIV3D, look at Stringer Survey - Land Surveying Software or https://civilsurveysolutions.com/

  • Like 1
Link to comment
Share on other sites

15 minutes ago, BIGAL said:

Point 1 should work, but with no file to look at, if we look at most feature survey points they have codes that can be alpha, number or alphanumeric etc even smart codes 01F*02F, TR6-3 and so on.

 

I guess it has something to do with how they build the list.

 

txt file

point 1 100.235  200.374  56.356

 

read-line converts it to one string

"point 1 100.235 200.374 56.356"

 

(read (strcat "(" .... ")"  turns it into a list

 

(point 1 100.235 200.374 56.356) = list of 5 items because of space

 

(car POINT_LINE) = point

(caddr POINT_LINE) = 100.235 ; should be 200.374

(cadr POINT_LINE) = 1 ;should be 100.235

(last POINT_LINE) = 56.356 ;correct

 

I guess you could pull the z y and x in that order using (last) and removing them from the list then anything left convert to point_name?

 

Quote

So if doing this all the time you should look at programs that are designed to do this.

 

Agree

  • Like 2
Link to comment
Share on other sites

@mhupp

You routine now works perfectly...but only with the supplied SAMPLE.TXT file. If i create my own file in the format

 

<PointID> <Easting> <Northing> <Elevation>

(single space between fields)

 

then the routine doesn't work. Any idea what's wrong? I've attached both files SAMPLE.TXT (works) and TEST.TXT (doesn't work)

 

Thank you!

SAMPLE.TXT TEST.TXT

Link to comment
Share on other sites

18 minutes ago, psychopomp1 said:

@mhupp

You routine now works perfectly...but only with the supplied SAMPLE.TXT file. If i create my own file in the format

 

<PointID> <Easting> <Northing> <Elevation>

(single space between fields)

 

then the routine doesn't work. Any idea what's wrong? I've attached both files SAMPLE.TXT (works) and TEST.TXT (doesn't work)

 

Thank you!

SAMPLE.TXT 13.33 kB · 3 downloads TEST.TXT 159 B · 2 downloads

 

you need <elevation> value 

sample has 4 columns, your test.txt has 3 columns.

 

like this

 AB_12 231512 3821172 0
 106-14 231400 3821000 0
 T4001 230099 3821112 0
 Z402 232116 3821400 0
 G4-12 229941 3822612 0
 R101 230169 3824992 0
 B6-312 230788 3820223 0

 

  • Funny 1
Link to comment
Share on other sites

26 minutes ago, psychopomp1 said:

@mhupp You routine now works perfectly...but only with the supplied SAMPLE.TXT file. If i create my own file in the format

 

You're missing info

 

<PointID> <Easting> <Northing> <Elevation>

   AB_12     231512     3821172     <missing>

 

so it makes a list (AB_12  231512  3821172 ) only 3 long

(if (eq (length (setq POINT_LINE (read (strcat "(" POINT_LINE ")")))) 4)
;if list POINT_LINE isn't 4 long do nothing.

 

 

Dang it @exceed beat me by 30 sec!

Edited by mhupp
  • Funny 1
Link to comment
Share on other sites

On 6/8/2022 at 4:00 PM, mhupp said:

.....

2. fixed tho point names cant have spaces (will mess up the list)

example

"point 1" - no good

"point-1" - good

 

 

On 6/9/2022 at 3:32 AM, BIGAL said:

Point 1 should work, but with no file to look at, if we look at most feature survey points they have codes that can be alpha, number or alphanumeric etc even smart codes 01F*02F, TR6-3 and so on. 

...

 

about the point name issue:

if there are spaces ( like @mhupp wrote) or Special Characters (like @BIGAL wrote):

 

1. open the .txt file in excel, and in text import wizard choose "as fixed width".

2. after the file is open select the name column.

3. go to Home -> Find&select -> Replace

4. replace the spaces and/or the Special Characters with appropriate Character (I usually go with "_").

5. save the file (if save is selected the file will remain .TXT) or "save as...", and make sure to save as "Text (Tab Delimited) (*.TXT)"

 

* as a comment I must add that is one of the most simple and useful lisp I've seen lately.

   thanks @psychopomp1 for the post and @mhupp for making it works....

Edited by aridzv
  • Like 2
Link to comment
Share on other sites

Just a minor change to mhupp's code. His version still plots N,E,h whereas the one below plots E,N,h (i swapped cadr and caddr around)

HTH :)

 

; POINTPLT is a simple AutoLSIP program that will plot a coordinate points file
; in AutoCAD.  To run POINTPLT, load POINTPLT.LSP as you would any normal
; AutoLISP file (see AutoCAD Reference Manual), type "POINTPLT" and press
; [Enter].  POINTPLT will first prompt you for an input coordinate filename.
; You must enter a vaild DOS filename at this point.  The input coordinate file
; must be in the following format:
;
;   Point name (no spaces)  (X Cord) (Y Cord)   ELEVATION(z)
;
; A sample input coordinate file (SAMPLE.DAT) is included with POINTPLT.
;
; POINTPLT uses the default (current) text style and layer.  However, the
; current text style must have a defined height (height must not be "0").
;
; If you have any questions or comments concerning POINTS, I may be reached
; via THE SPECTRUM BBS þ (501) 521-5639
;
;-------------------------------------------------------------------------------
; * ERROR Trapping *
;
(defun *ERROR* ()
   (eop)
)
;-------------------------------------------------------------------------------
; * End of program *
;
(defun EOP ()
   (setvar "CMDECHO" POINTSPLT_CE)
   (princ)
)
;-------------------------------------------------------------------------------
; * Main Program *
(defun C:POINTPLT (/ IN_FILE POINT_LINE POINT_NO POINT)
  (setq POINTSPLT_CE (getvar "CMDECHO"))
  (setvar "CMDECHO" 0) ;Turn "Command Echo" off
  (prompt "\n\nP O I N T P L T  v1.0 -- Copyright (c) 1992 by Kurtis J. Jones / -Mate Software\n\n")
  (setq IN_FILE (open (getfiled "\nEnter points filename: " (getvar 'DWGPREFIX) "txt" 16) "r"))
  (while (setq POINT_LINE (read-line IN_FILE))
    (if (eq (length (setq POINT_LINE (read (strcat "(" POINT_LINE ")")))) 4)
      (progn
        (setq POINT_NO (vl-princ-to-string (car POINT_LINE)))
        (prompt (strcat "\nPlotting point no. " POINT_NO))
        (setq POINT
          (list
            (cadr POINT_LINE) ;Get easting
            (caddr  POINT_LINE) ;Get northing
            (last POINT_LINE) ;Get elevation
          )
        )
        (entmake (list '(0 . "POINT") (cons 10 POINT)))
        (entmake (list '(0 . "TEXT") (cons 10 POINT) '(40 . 1) (cons 1 POINT_NO)))
      )
    )
  )
  (close IN_FILE)
  (prompt "\nPOINTPLT finished")
  (eop)
  
)


 

Edited by psychopomp1
added code correctly
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...