×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

LISP: If, Not

LISP: If, Not

LISP: If, Not

(OP)
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)

RE: LISP: If, Not

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))

RE: LISP: If, Not

(OP)
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)

RE: LISP: If, Not

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)
 

RE: LISP: If, Not

(OP)
I see, by swapping IMAGENAME and FILENAME I don't have to strip out the file extension and reassemble it.

Thanks much!!.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close