While loop error in LISP Routine

While loop error in LISP Routine

jdebruynkops
Explorer Explorer
573 Views
4 Replies
Message 1 of 5

While loop error in LISP Routine

jdebruynkops
Explorer
Explorer

the goal of this LISP routine is to input 3 values: the wattage of a solar module (str), the number of areas (int), and tracker (aka string) type (int) (either a 2 or a 3) and output a series of layers named:

"G-ANNO-GCR_AREA 1_XXX(watts)_XX(strings)" ..., "G-ANNO-GCR_AREA N_XXX(watts)_XX(strings)" depending on the int inputted for number of areas. I'm having trouble getting the code to work, I think its a problem with my while loop. this is the error I am getting:

jdebruynkops_0-1681159058151.png

Here is my code:

 

;;MAKEGCRLAYERS - Lisp routine to replace the tedious process of making GCR Layers
(defun c:MAKEGCRLAYERS()

(setq watts (getstring "\nEnter module wattage :"))
(setq areas_int (getint "\nEnter number of areas :"))
(setq tracker (getstring "\nEnter type of tracker :"))
(setq text " ")


(while (> areas_int 0)
(setq areas_str (itoa areas_int));; makes string version of areas variable
(setq text strcat("G-ANNO-GCR_AREA " areas_str "_" watts "_0" tracker));; combines all strings into correct format
(if (not (tblsearch "layer" text)) (command "-LAYER" "N" text "");; Makes a new layer
(setq areas_int (- areas 1));; decreases areas_int variable by 1
)
)

 

0 Likes
Accepted solutions (1)
574 Views
4 Replies
Replies (4)
Message 2 of 5

GKNIGHT892NE
Enthusiast
Enthusiast

Have you tried to decrease your count outside of the while loop?

0 Likes
Message 3 of 5

andrewpuller3811
Advisor
Advisor

You are missing a closing parenthesis for you if statement.

 

Should it be - 

 

(if (not (tblsearch "layer" text)) (command "-LAYER" "N" text ""));; Makes a new layer

 



If a post provides a fix for your issue, click on "Accept as Solution" to help other users find solutions to problems they might have that are similar to yours.

Andrew Puller
Maitland, NSW, Australia
Windows 11
Intel core i7 11800 @ 2.30 GHz with 32GB Ram
Civil 3d 2023
Message 4 of 5

user181
Mentor
Mentor
Accepted solution

@jdebruynkops wrote:

 

(while (> areas_int 0)
(setq areas_str (itoa areas_int));; makes string version of areas variable
(setq text strcat("G-ANNO-GCR_AREA " areas_str "_" watts "_0" tracker));; combines all strings into correct format
(if (not (tblsearch "layer" text)) (command "-LAYER" "N" text "");; Makes a new layer
(setq areas_int (- areas 1));; decreases areas_int variable by 1
)
)

 


I see three problems, see below.  Did my response in your last post help, you never replied?

 

(setq text (strcat"G-ANNO-GCR_AREA " areas_str "_" watts "_0" tracker));;   The parenthesis needs to be before strcat 
(if (not (tblsearch "layer" text)) (command "-LAYER" "N" text ""));;   You forgot a parenthesis at the end
(setq areas_int (- areas_int 1));;   You didn't put _int after areas

EESignature


0 Likes
Message 5 of 5

jdebruynkops
Explorer
Explorer

You my friend are an autolisp genius!

0 Likes