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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LISP: If, Not 1

Status
Not open for further replies.

Volk359

Technical User
Jun 30, 2004
395
0
0
US
Greetings all,

I've created a lisp routine to automatically repath an image that had already been inserted but where the path/filename was incorrect. It works fine but the problem is the image type isn't always the same, i.e. sometimes they are a .TIF and others they are a .CAL.

I included an IF NOT command where if it didn't find filename.CAL then go find filename.TIF. Seems to me I have the syntax correct but apparently not because if it doesn't find the .CAL it just quits. Likewise if I swap the CAL and TIF it will only find the TIF but not the CAL.

Any suggestions?

Thanks,

Keith

Code:
(setq imagename (getvar "dwgname"))
(setq imagename (substr imagename 1 (- (strlen imageName) 4)))
(setq filename (strcat (getvar "dwgprefix") imagename ".cal"))
(if (not filename)
    (setq filename (strcat (getvar "dwgprefix") filename ".tif"))
)
(command "image" "p" imagename filename)
 
It seems you don't have the routine actually looking if the "filename" exists, you just assign it a string/name, so it would never be 'nil'

Maybe changing one line to the following will do it;

(if (not (findfile filename))
 
OK, that seems to work except it's looking for filename.CAL.TIF. I inserted the line to strip out the last three characters and put the whole thing together properly but I get:

Unknown command "C:\DOCUMENTS AND SETTINGS\me\DESKTOP\filename.cal". Press F1 for help.
nil

Code:
(setq imagename (getvar "dwgname"))
(setq imagename (substr imagename 1 (- (strlen imageName) 4)))
(setq filename (strcat (getvar "dwgprefix") imagename ".cal"))
(if (not (findfile filename))
    (setq imagename (substr imagename 1 (- (strlen imageName) 4)))
    (setq filename (strcat (getvar "dwgprefix") filename ".tif"))
)
(command "image" "p" imagename filename)
 
I think your "if" got messed up, you wanted 2 statements to occur if not. Slightly different coding:

Code:
(setq imagename (getvar "dwgname"))
(setq imagename (substr imagename 1 (- (strlen imageName) 4)))
(setq filename (strcat (getvar "dwgprefix") imagename ".cal"))
(if (not (findfile filename))
    (setq filename (strcat (getvar "dwgprefix") imagename ".tif"))
)
(command "image" "p" imagename filename)
 
I see, by swapping IMAGENAME and FILENAME I don't have to strip out the file extension and reassemble it.

Thanks much!!.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top