What is wrong with this code?

What is wrong with this code?

Anonymous
Not applicable
991 Views
5 Replies
Message 1 of 6

What is wrong with this code?

Anonymous
Not applicable

Hi

 

I made the following autolisp program to quickly make grid line text. I don't understand why I get the error fixnump nil? Also, Visual Lisp Editor doesn't automatically return to Visual Lisp, and when I click on 'Go to last break source' it gives me the error :CALLBACK-ENTRY?

 

(defun c:gr ()
(setq st (getint "Enter starting grid: "))
(setq p1 (getpoint "Click where to start grid: "))
(setq tz (getreal "Enter text height: "))

(repeat
(command "text" p1 tz 0 (itoa st))
(setq p1 (getpoint "Click on next grid: "))
(setq st (+ 1 st))
)

)

0 Likes
Accepted solutions (2)
992 Views
5 Replies
Replies (5)
Message 2 of 6

rkmcswain
Mentor
Mentor
(repeat) is missing an argument (the number of times you want to repeat)

You also might want to test the current text style for a fixed height. The prompts for the text command vary depending on that.

R.K. McSwain     | CADpanacea | on twitter
0 Likes
Message 3 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

The (repeat) function needs to be given an integer [a "fixed number" abbreviated into the error message] as a first argument, for the number of times to repeat what it's supposed to do.  The (command) function always returns nil, and since that's the first thing after the function name, it's taking what it returns as the number argument.

 

If you want it to repeat continuously until you cancel it, you can use something like

  (while T

instead of

  (repeat

 

That's the simple way.  It can be made more sophisticated, for example with <exit> as a default so that Enter/space will end it, in addition to Escape that you would need to use in the (while) scenario.

Kent Cooper, AIA
0 Likes
Message 4 of 6

Anonymous
Not applicable
I have now used (while), but as you say, the (command) function always returns nil and now the loop exits straight after the (command)??
0 Likes
Message 5 of 6

rkmcswain
Mentor
Mentor
Accepted solution
Did you miss the T as the argument for the (while) in Kent's comment?

(while T
(do_this)
)

T is always true. Of course you could stick your own variable in there, one that you could control the value of.



R.K. McSwain     | CADpanacea | on twitter
0 Likes
Message 6 of 6

stevor
Collaborator
Collaborator

Using that 'while:

 ; some Text loop
 (defun c:gr ( / P1 ST TZ ) ; or not
  (setq st (getint "\n Starting grid Integer: "))
  (setq p1 (getpoint " Start grid Pt: "))
  (setq tz (getreal " Text height: "))
  (while P1
   (command "text" p1 tz 0 (itoa st))
   (setq p1 (getpoint " Next grid Pt: "))
   (setq st (+ 1 st))
  ) (princ" Done. ") (princ)  ) ;

 

And if used often, default values

for ST, TZ and maybe P1 would be

time savers.

S