Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Value must be nonzero

6 REPLIES 6
Reply
Message 1 of 7
kdoug
706 Views, 6 Replies

Value must be nonzero

Hey everyone. Attached is a code that I wrote. I am getting an error and I can't figure out where the error is in the code. If someone would be so kind to take a look and push me in the right direction it would be greatly appreciated. Thanks!

Kdoug
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: kdoug

Well, block insertion scale factors must be non-zero, so I'd look at those
first. Type !Crown on the Command prompt line to see whether it succeeded
in setting that as a numerical value. (You might have to take out the
localizing of variables temporarily to do it.) No one else can test it
without your job-number text file and so on, though someone better versed
than I in referring to external files like this might also have some
suggestions.
--
Kent Cooper


wrote
Hey everyone. Attached is a code that I wrote. I am getting an error and I
can't figure out where the error is in the code. If someone would be so
kind to take a look and push me in the right direction it would be greatly
appreciated. Thanks!

Kdoug
Message 3 of 7
Anonymous
in reply to: kdoug

Offhand, I don't see the cause of the error you cite, but your (while ...)
loop will run indefinitely, since the test is a value that just keeps
incrementing indefinitely.
___

wrote in message news:5177705@discussion.autodesk.com...
Hey everyone. Attached is a code that I wrote. I am getting an error and I
can't figure out where the error is in the code. If someone would be so
kind to take a look and push me in the right direction it would be greatly
appreciated. Thanks!

Kdoug
Message 4 of 7
kdoug
in reply to: kdoug

Thanks for the help. Now when I type in !Crown it is set to "ÿþ3\0000\000" Any Clues? Is this ASCII for 20 ? The external file I want to read is just a bunch of numbers.

Kdoug
Message 5 of 7
Anonymous
in reply to: kdoug

My guess is it's more likely something in the opening and reading of the
external text file. If you run each line by itself, and see whether it
returns something appropriate, maybe you can find where it's going wrong.
--
Kent Cooper


wrote...
Thanks for the help. Now when I type in !Crown it is set to "ÿþ3\0000\000"
Any Clues? Is this ASCII for 20 ? The external file I want to read is just
a bunch of numbers.

Kdoug
Message 6 of 7
Anonymous
in reply to: kdoug

As Paul pointed out, the while is never ending.
By incresing cnt by 1 and using repeat ,you are reading the first
record the first time, then you read the next two, then the next 3, etc.
You are setting crown to what you read to use as a scale factor,
so apparently the file you have has a set of records with different
scale factors. When you reach the end of the file the scale factor
will not be correct. Once you get to the end you continue to try to
read the file, setting the scale factor to whatever garbage it finds at the
end of the file. This is probably where your error is.
Try this (untested)

(defun C:ITE (/ symbol i_point Crown t_type treeno jobno tfnam fnam)
(setq
oldecho (getvar "cmdecho")
oldblip (getvar "blipmode")
oldclyr (getvar "clayer")
)
(setq jobno (substr (getvar "dwgname") 1 5))
(setq tfnam (strcat jobno ".txt"))
(setq i_point (getpoint "\nSelect insertion point: "))
(setq treeno (getint "\nEnter Tree No: "))
(command "insert" symbol i_point Crown Crown "" treeno)
(set cnt 1)

(setq i_point (getpoint "\nSelect insertion point: "))
(setq treeno (getint "\nEnter Tree No: "))
(command "insert" symbol i_point Crown Crown "" treeno)
(setq fnam (open tfnam "r"))
(if (not (tblsearch "LAYER" "EJK_SYMBOL_EXISTING"))
(command "LAYER" "N" "EJK_SYMBOL_EXISTING" "")
)
(setvar "clayer" "EJK_SYMBOL_EXISTING")
(setq symbol "ejk_t_ex_dec_1")
(while
(setq Crown (atoi (read-line fnam)))
(setq i_point (getpoint "\nSelect insertion point: "))
(command "insert" symbol i_point Crown Crown "" treeno)
(setq treeno (+ treeno 1))
)
(close fnam)
(setvar "cmdecho" oldecho)
(setvar "blipmode" oldblip)
(setvar "clayer" oldclyr)
(princ)
)

If you really only have one record in the txt file indicating the
scale factor to use for all inserts and you want the while to
continue until you quit selecting locations, then try this (untested).

(defun C:ITE (/ symbol i_point Crown t_type treeno jobno tfnam fnam)
(setq
oldecho (getvar "cmdecho")
oldblip (getvar "blipmode")
oldclyr (getvar "clayer")
)
(setq jobno (substr (getvar "dwgname") 1 5))
(setq tfnam (strcat jobno ".txt"))
(setq i_point (getpoint "\nSelect insertion point: "))
(setq treeno (getint "\nEnter Tree No: "))
(command "insert" symbol i_point Crown Crown "" treeno)
(set cnt 1)

(setq i_point (getpoint "\nSelect insertion point: "))
(setq treeno (getint "\nEnter Tree No: "))
(command "insert" symbol i_point Crown Crown "" treeno)
(setq fnam (open tfnam "r"))
(if (not (tblsearch "LAYER" "EJK_SYMBOL_EXISTING"))
(command "LAYER" "N" "EJK_SYMBOL_EXISTING" "")
)
(setvar "clayer" "EJK_SYMBOL_EXISTING")
(setq symbol "ejk_t_ex_dec_1")
(setq treeno (getint "\nEnter Tree No: "))
(setq Crown (atoi (read-line fnam)))
(close fnam)
(while
(setq i_point (getpoint "\nSelect insertion point: "))
(command "insert" symbol i_point Crown Crown "" treeno)
(setq treeno (+ treeno 1))
)
(setvar "cmdecho" oldecho)
(setvar "blipmode" oldblip)
(setvar "clayer" oldclyr)
(princ)
)
wrote in message news:5177892@discussion.autodesk.com...
Thanks for the help. Now when I type in !Crown it is set to "ÿþ3\0000\000"
Any Clues? Is this ASCII for 20 ? The external file I want to read is just
a bunch of numbers.

Kdoug
Message 7 of 7
kdoug
in reply to: kdoug

I didn't have a chance yesterday, but I figured out the problem by eliminating the locals and testing. For whatever reason using (findfile was picking up a file other than the text file I wanted. I corrected it by adding:

(setq tfnam (strcat "C:\\EJK_JOBS\\EX_TREE_CROWNS\\" jobno ".txt"))

As for the while loop that is never ending, I've corrected that.

Thanks everyone for you help.

Kdoug

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost