Ilisp Programming

Hi all.

 

I would like to modify a macro from one of my CAD/CAM software.

This software works in ilisp. I don't know this program at all....

 

To put it simply, this macro copies excel columns and transforms them into rectangles on the cutting software. (AutoCAD type)

 

The problem is that the macro is read backwards. When I have my rectangle list, the first one is the last one on the list etc...

 

Here is the macro attachment, if anyone knows how to modify this, it would be simpa =)

 

Thank you!

 


import.lsp

Here is the file in text for those who can't open it.

 

(SETQ txt (CLIP-GET))
(SETQ YGAP 100)
(IF (NOT txt) (QUIT "*Cancel*"))
(SETQ txt (STRREPLACE txt "\t" " "))
(SETQ txt (STRREPLACE txt "\n" ")("))
(SETQ txt (STRREPLACE txt "\r" ""))
(SETQ txt (STRREPLACE txt "," "."))
(SETQ txt (STRCAT "((" (SUBSTR txt 1 (1- (STRLEN txt))) "))"))
(SETQ txtlist (READ txt))
(SETQ basep (LIST 0 0))
(FOREACH s txtlist
  (SETQ ymax 0)
    (SETQ x (CAR s) y (CADR s))
    (IF (> y ymax) (SETQ ymax y))
    (CAD-RECTANGLE basep (LIST (+ (CAR basep) x) (+ (CADR basep) y)) 7)
  (SETQ basep (LIST 0 (+ (CADR basep) ymax YGAP)))
)
(REDRAW)

 

 

1 Like

Hello, wouldn't there be a little code missing? 

With this code, I have a functional macro that exports the excel in rectangle dxf

 

Why, what will be missing for you?

 

The macro works like this:

 

I type my length and width of parts on excel in 2 columns.

Column A length, column B Width.

Then I make a "copy" of the list and then by clicking on my macro it pastes everything by transforming the data into dimensions in mm

1 Like

When you select the area in XL, classically, you start from the cell at the top left and end at the bottom right. What happens if you do from bottom right to top left, or from bottom left to top right (the goal is to finish the selection at the top)?

By chance, I found some info on this language: http://igems.se/pdf/English-Ilisp.pdf

See page 23 for the PRINC command for the explanation of \t, \n and \r.

Thanks Stef, I had already downloaded this help file.

But I didn't understand anything....

I translated and printed it. I'll read it tonight with a rested head =)

 

I'll keep you posted of course =)

Do you know Lisp (language used for Autocad macros at the beginning)

I added a few comments

(SETQ txt (CLIP-GET)); We retrieve the contents of the clipboard

(SETQ YGAP 100); we initialize

(IF (NOT txt) (QUIT "*Cancel*")) ; We check that the content is not empty
(SETQ txt (STRREPLACE txt "\t" " ")); replace the column separator (tab) with a space
(SETQ txt (STRREPLACE txt "\n" ")(")) ; the change of line is replaced by a )(
(SETQ txt (STRREPLACE txt "\r" "")) ; I don't know what return is (in what is retrieved from the clipboard
(SETQ txt(STRREPLACE txt "," ".")) ; we replace the , by .


(SETQ txt (STRCAT "((" (SUBSTR txt 1 (1- (STRLEN txt))) "))")) ; we complete to have one (at the beginning and one) at the end

(SETQ txtlist (READ txt)); the string of characters is converted into a form that can be understood by the language

(SETQ basep (LIST 0 0)); we initialize

(FOREACH s txtlist
  (SETQ ymax 0)
    (SETQ x (CAR s) y (CADR s))
    (IF (> y ymax) (SETQ ymax y))
    (CAD-RECTANGLE basep (LIST (+ (CAR basep) x) (+ (CADR basep) y)) 7)
  (SETQ basep (LIST 0 (+ (CADR basep) ymax YGAP)))
)
(REDRAW)

The "list" system, characteristic of Lisp, means that by adding the pairs (), we directly retrieve the pairs "s" of coordinates, which are themselves lists.

CAR and CADR allows the sub-parts of the coordinate pair to be extracted. FYI we can combine the a and d to extract a particular element from a list with a lot of elements (typically the result of the "list" command applied to an element or a family of elements (in which case we have a list of lists, and it can go a long way).

I don't know why there is a test on ymax, nor what basep and YGAP are for