Lisp to plot polylines or lines with specified length and azimuth at coordinates

Lisp to plot polylines or lines with specified length and azimuth at coordinates

rcmather8279
Explorer Explorer
682 Views
9 Replies
Message 1 of 10

Lisp to plot polylines or lines with specified length and azimuth at coordinates

rcmather8279
Explorer
Explorer

Hello,

 

First time posting here and relatively new to Lisps. I have a list of coordinates, each with a specific azimuth angle, and I have a separate list of lengths associated with the coordinates. Normally, I would draw a pline at the coordinates, use the @, enter the angle and length. This becomes repetitive when working with 50+ pairs of coordinates.

 

Is there a lisp or process I can use that incorporates my excel list of coordinates, azimuths, and lengths?

 

 

Example: 

I need plotted: 200' pline at 50,0 on a 270° azimuth

100' pline at 90,90 on a 10° azimuth, etc.

 

These lines should all be individual lines.

Thanks in advance! 

-Rob

0 Likes
Accepted solutions (2)
683 Views
9 Replies
Replies (9)
Message 2 of 10

Kent1Cooper
Consultant
Consultant

That should be possible.  Post a [small] example of a file, converted/exported in Excel to .csv format so that AutoLisp will be able to read it.

Kent Cooper, AIA
0 Likes
Message 3 of 10

rcmather8279
Explorer
Explorer

I've attached a csv and a sample CAD file. I would like to be able to use the csv to re-produce what I drew in CAD.

 

Thank you for looking into this!

0 Likes
Message 4 of 10

Kent1Cooper
Consultant
Consultant
Accepted solution

This, in simplest terms, seems to do that [minimally tested]:

 

(defun C:PLCSV (/ file txt cp x y a l)
  (setq file (open "X:\\YOUR\\PATH\\AND\\FILENAME.CSV" "r"));; <-- EDIT!
  (read-line file) ; header
  (while (setq txt (read-line file))
    (setq
      cp (vl-string-position 44 txt); = comma position
      x (substr txt 1 cp)
      txt (substr txt (+ cp 2))
      cp (vl-string-position 44 txt)
      y (substr txt 1 cp)
      txt (substr txt (+ cp 2))
      cp (vl-string-position 44 txt)
      a (substr txt 1 cp)
      l (substr txt (+ (vl-string-position 44 txt) 2))
    ); setq
    (command "_.pline" (strcat x "," y) (strcat "@" l "<" a) "")
  ); while
  (close file)
  (princ)
)

 

EDIT the drive/filepath/filename part to suit.  Turn running Object Snaps off [that can be built in if you like, as well as all the other usual enhancements].

Kent Cooper, AIA
0 Likes
Message 5 of 10

rcmather8279
Explorer
Explorer

I am getting this in the command line. Not sure why, but it seems to be unable to find the csv file.

 

; error: bad argument type: FILE nil

 

 

0 Likes
Message 6 of 10

rcmather8279
Explorer
Explorer

For reference, I saved the csv to my path, and added it in the lsp

 

(defun C:PLCSV (/ file txt cp x y a l)
(setq file (open "F:\Temp\Rob\STATION-AZIMUTH-LENGTH.csv" "r"));; <-- EDIT!
(read-line file) ; header
(while (setq txt (read-line file))
(setq
cp (vl-string-position 44 txt); = comma position
x (substr txt 1 cp)
txt (substr txt (+ cp 2))
cp (vl-string-position 44 txt)
y (substr txt 1 cp)
txt (substr txt (+ cp 2))
cp (vl-string-position 44 txt)
a (substr txt 1 cp)
l (substr txt (+ (vl-string-position 44 txt) 2))
); setq
(command "_.pline" (strcat x "," y) (strcat "@" l "<" a) "")
); while
(close file)
(princ)
)

0 Likes
Message 7 of 10

Kent1Cooper
Consultant
Consultant
Accepted solution

Double up the backslashes, or change them to forward slashes.  That's necessary for filepaths in AutoLisp.

Kent Cooper, AIA
0 Likes
Message 8 of 10

Patchy
Mentor
Mentor

I tested this, if the .csv has a long name it didn't work until I made it simple 1 character name and it works fine.

I haven't try to find out the limits of the name.

0 Likes
Message 9 of 10

devitg
Advisor
Advisor

@rcmather8279 

 

test this way 

 

(setq file (GETFILED  "\nSelect your CSV  " "" "csv" 8))
         (setq open-file(open file "r")));; <-- EDIT!
  (setq header(read-line open-file)) ; header)
  (while (setq txt (read-line open-file))
(setq
      cp (vl-string-position 44 txt); = comma position
      x (substr txt 1 cp)
      txt (substr txt (+ cp 2))
      cp (vl-string-position 44 txt)
      y (substr txt 1 cp)
      txt (substr txt (+ cp 2))
      cp (vl-string-position 44 txt)
      a (substr txt 1 cp)
      l (substr txt (+ (vl-string-position 44 txt) 2))
    ); setq
    (command "_.line" (strcat x "," y) (strcat "@" l "<" a) "")
  ); while
  (close open-file)
  (princ)
Message 10 of 10

Sea-Haven
Mentor
Mentor

If you always save to same directory can save a few clicks

 

(setq file (GETFILED "\nSelect your CSV " "F:\\Temp\\Rob\\" "csv" 8))

0 Likes