TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: MeasureUp on March 26, 2013, 12:43:46 AM

Title: Loading a file
Post by: MeasureUp on March 26, 2013, 12:43:46 AM
It makes me frustrated.
Your helps are much appreciated.

If I enter this on the command line:
Code: [Select]
(findfile "E:\\Test.vlx")
it returns:
Quote
"E:\\Test.vlx"

Then I load this file by entering this on the command line"
Code: [Select]
(load "E:\\Test.vlx")
it returns:
Quote
nil
It tells me that the file is not loaded.
Title: Re: Loading a file
Post by: BlackBox on March 26, 2013, 12:54:54 AM
From the help:

Quote
Return Values

Unspecified, if successful. If load fails, it returns the value of onfailure; if onfailure is not defined, failure results in an error message.

Have you considered that Nil is simply being returned as you do not currently have an ending (princ) in the last routine being loaded? Do your commands/routines work?

What happens when you include the onFailure parameter:

Code: [Select]
(load "E:\\Test.vlx" (progn (prompt "\n** Load failed ** ") (princ)))
Title: Re: Loading a file
Post by: MeasureUp on March 26, 2013, 01:02:04 AM
It returns:
Quote
** Load failed ** nil
Title: Re: Loading a file
Post by: BlackBox on March 26, 2013, 02:44:18 AM
It returns:
Quote
** Load failed ** nil

Just wanted to be certain; time to debug your source-code.
Title: Re: Loading a file
Post by: dgorsman on March 26, 2013, 10:26:42 AM
Check the definition of (load...), specifically what the return value is: Unspecified if successful.  If it fails, it returns the [onfailure] argument.

So it appears to be working properly.
Title: Re: Loading a file
Post by: andrew_nao on March 26, 2013, 11:33:41 AM
It makes me frustrated.
Your helps are much appreciated.

If I enter this on the command line:
Code: [Select]
(findfile "E:\\Test.vlx")
it returns:
Quote
"E:\\Test.vlx"

Then I load this file by entering this on the command line"
Code: [Select]
(load "E:\\Test.vlx")
it returns:
Quote
nil
It tells me that the file is not loaded.

if you know the path of the file, why tell to findfile?

(load (findfile "test.lsp"))

provided you have the file path in the acad search path.

if you know the file path, there is no need to find the file just have it load from the path
Title: Re: Loading a file
Post by: ronjonp on March 26, 2013, 12:03:05 PM
^^ IMO .. it's good to check that the file can be found before trying to load it...

(if (findfile "E:\\Test.vlx") (load "E:\\Test.vlx"))
Title: Re: Loading a file
Post by: dgorsman on March 26, 2013, 12:38:14 PM
^^ IMO .. it's good to check that the file can be found before trying to load it...

(if (findfile "E:\\Test.vlx") (load "E:\\Test.vlx"))

+1, especially if the [onfailure] argument is omitted - the (load ...) call will error out in that case.  So either (findfile...) and (load filename), or no (findfile...) and (load filename "Hey I failed").
Title: Re: Loading a file
Post by: MeasureUp on March 26, 2013, 09:47:34 PM
^^ IMO .. it's good to check that the file can be found before trying to load it...

(if (findfile "E:\\Test.vlx") (load "E:\\Test.vlx"))
Yes. This is what I am doing.
And thanks to everyone.

Problem solved as I found there is a logical error on the "IF" condition in my "FINDFILE" code.