TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: sprunkle on May 24, 2023, 03:48:49 PM
-
I am trying to use foreach for the first time, and I am hoping some of you can help me shed some light on where I am going wrong.
(list "J:/x000" "J:/x100" "J:/x200" "J:/x300" "J:/x400" "J:/x500" "J:/x600" "J:/x700" "J:/x800" "J:/x900")
)
When I check !ofile after this it is nil. Is foreach stopping at the first step if it can't find the file there?
What I am trying to accomplish is to ask for user input for a job number (23-4827 for example), and then have a file open that I will pull data from. The job could be in one of the ten sub-directories listed above. It is actually the 5th character in the job number that dictates which sub-directory will be pulled from, so maybe I should use that to help open the file?
Thanks in advance for any input you may have. I am very new to AutoLISP.
-
I think you don't need foreach at all...
Try something like this :
(setq dir
(car (vl
-remove
-if '
(lambda (x
) (/= (substr x
4 1) (substr JobNum
4 1))) (list "J:/x000" "J:/x100" "J:/x200" "J:/x300" "J:/x400" "J:/x500" "J:/x600" "J:/x700" "J:/x800" "J:/x900"))))
Still, not thoroughly tested and debugged, but should give you some shed of light IMHO...
-
Ribarm, thank you! I changed a couple of things, but that works very well!
(setq dir
(list "J:/x000" "J:/x100" "J:/x200" "J:/x300" "J:/x400" "J:/x500" "J:/x600" "J:/x700" "J:/x800" "J:/x900"))
-
Why not simply -
ofile
(open (strcat "J:/x" (substr JobNum
5 1) "00/" JobNum
"/RoofDes.out") "r"))