Author Topic: Loading a file  (Read 1971 times)

0 Members and 1 Guest are viewing this topic.

MeasureUp

  • Bull Frog
  • Posts: 461
Loading a file
« 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.

BlackBox

  • King Gator
  • Posts: 3770
Re: Loading a file
« Reply #1 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)))
"How we think determines what we do, and what we do determines what we get."

MeasureUp

  • Bull Frog
  • Posts: 461
Re: Loading a file
« Reply #2 on: March 26, 2013, 01:02:04 AM »
It returns:
Quote
** Load failed ** nil

BlackBox

  • King Gator
  • Posts: 3770
Re: Loading a file
« Reply #3 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.
"How we think determines what we do, and what we do determines what we get."

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Loading a file
« Reply #4 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.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

andrew_nao

  • Guest
Re: Loading a file
« Reply #5 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
« Last Edit: March 26, 2013, 11:38:00 AM by andrew_nao »

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Loading a file
« Reply #6 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"))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Loading a file
« Reply #7 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").
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

MeasureUp

  • Bull Frog
  • Posts: 461
Re: Loading a file
« Reply #8 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.