3

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:

1000,Easting,Northing,Elevation,Identifier
1001,Easting,Northing,Elevation,Identifier

Etc.

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"

Will Ness
  • 70,110
  • 9
  • 98
  • 181
Fizscy
  • 41
  • 3
  • 1
    Hi, in your input file are each entries separated by a newline or a space character? I think Autodesk forums have more active users than here (also, see https://blog.draftsperson.net/autolisp-lesson-8-looping/ or https://www.afralisp.net/autolisp/tutorials/program-looping.php, or https://forums.augi.com/showthread.php?169829-AutoLISP-101-Loops-Discussion). I think you should try first to define small functions and test them often to see how it behaves, and progressively build up your solution. Don't hesitate to post your attempts if anything is blocking you. – coredump Sep 19 '22 at 09:29
  • Each entry is separated by a new line. I figure there's a regex element, and the looping, and that's the big hurdle for me right now. I'll take a look at those though (time is not an issue, this is my own undertaking to rewrite a company script that the original writer left without notes or uncompiled code) – Fizscy Sep 19 '22 at 13:39

2 Answers2

1

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.

https://help.solidworks.com/2022/English/api/draftsightlispreference/html/lisp_functions_overview.htm

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.

https://github.com/GitHubUser5376/AttributeImportExport

G Beck
  • 131
  • 1
  • 14
  • Although this isn't related directly to the question presented, the tools I use while I write in AutoLisp is the Visual Studio Code editor with the Common Lisp extension. – G Beck Sep 29 '22 at 22:22
0

You can use Lee-Mac's Reacd-CSV function to get a list of the csv values. And for the "HP" detection yes you might have to go through(using loop options mentioned above like while, repeat,foreach) each and use (substr Identifier 1 2) to validate

Gayathri
  • 69
  • 8