[SOLVED] Lisp – Extracting info from a list of comma separated values


This Content is from Stack Overflow. Question asked by Fizscy

I’ve tried searching this but have yet to find something that suits anything close to my needs. I’m trying to create a Autocad LISP that takes a text file, which is a list of comma-separated values, and place a block at coordinates defined by the list. BUT, only for items on the list where the last entry starts with “HP”

So that’s sounds a bit complex, but the text file is basically a UTM survey output, and looks like this:



The identifier is a variety of values, but I want to extract the Northing,Easting,Elevation, and insert a block (this last part I’ve got) at that location when the identifier begins with “HP”. The list can be long and the number of HPs can be 1 or 5000. I’m assuming there’s a “for x=1:end, do” type of loop than can be made that reuses the same variables over and over.

I’m a newbie to LISP so I’m stuck in that spot between “here are I’ve-never-programmed-before tutorials to make hello world” and “here is a library of the 3000 different commands in alphabetical order”


I believe the functions you are needing to solve this question are open, read-line or read-char, close,strlen, and substr. The first four functions relate to AutoLisp writing and reading a file. The last two functions manipulate the string variables that were pulled from the file. With them, you can find the "HP" within the text. To loop through the same code, three come to my mind: repeat, while, and foreach.

For a list of variables to quickly reference with their descriptions, here’s a good starting point. This particular page has the information broken up by category instead of alphabetical order.


Here are a few tutorials where AutoLisp code is used to write and read other files:

Lastly, here’s an example of AutoLisp writing and reading attributes from and to blocks.


This Question was asked in StackOverflow by Fizscy and Answered by G Beck It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?