Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If Not Lisp

Status
Not open for further replies.

Volk359

Technical User
Jun 30, 2004
395
US
Greetings All,

I thought using if/not used the following logic
Code:
(if (not a)
    (b)
)
Meaning, if 'a' was null (nil?) then do 'b'. Is that not correct?

I wrote a routine to insert an image based on the drawing's filename (image and cad name are the same) however we have a couple of different image types, TIFFs and CALs. What I''d like to do is have the routine check for filename.tif and if it doesn't find it then look for filename.cal.

The following code produces nil:
Code:
(setq filename (getvar "dwgname"))
(setq filename (substr filename 1 (- (strlen fileName) 3)))
(setq filename (strcat (getvar "dwgprefix") filename "tif"))
(if (not filename)
    (setq filename (strcat (getvar "dwgprefix") filename "cal"))
)
(command "image" "a" filename "0,0" "1" "0")

Thanks
 
I seems you've skipped a step where you check whether the file exists. Your test of (if (not filename)) would always be 'nil since you've already set filename to something.

add a line:

(setq Tifname (findfile filename));;finds file/path if present
....then
(if (not Tifname)
(setq filename (strcat (getvar "dwgprefix") filename "cal"))
)
 
Actually it does run fine, I had saved the original cad file in a different directory, so much for paying attention. [blush] I suppose it's a good idea to add the file check first too, but often both the cad and the image are downloaded from our library.

Thanks for the tip!
 
OK, but does it work for a .cal file? It appears to me your if statement would never get to the "cal" line because it doesn't actuallay check if a file exists.
 
Well, it does work without the check. I'm assuming it puts all the pieces together and if the file isn't found the lisp then completes the if/then statement.

I see what you're saying about the check but the lisp works if there's a .tif file but it doesn't check for one first. Maybe I don't completely understand how the if/not statement works.

On the command line if you manually enter the filename and give the incorrect name you don't get an error it says file not found, or whatever, and prompts again for a filename.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top