LISP Routine Shows Error When Attempting to Run

LISP Routine Shows Error When Attempting to Run

cballett
Explorer Explorer
899 Views
3 Replies
Message 1 of 4

LISP Routine Shows Error When Attempting to Run

cballett
Explorer
Explorer

Hi,

I'm new to the forums and to LISP in general. I am on Windows 11 Pro, AutoCAD 2024 and I have a routine that my predecessor worked on that keeps giving an error dialogue box, and I don't know enough about LISP to find what is going wrong. The routine is to create and assign layers based on our company standards that are in a .CSV file. The LISP code has a portion that creates an error dialogue box when the file isn't found. The perplexing thing is that the .CSV file does exist (in the same folder as the LISP file) and I have been trying to find out if there is an error in the file pathing with no luck. This issue didn't happen with ACAD2023 but I have recently switched to ACAD2024 and it is the only routine that won't work (it may be the only routine that points to an external file). So far, I have:

  • checked the .cuix file to make sure the routine was listed in the tool palette and the ribbon
  • checked ACAD Options > Files > Customization Files to make sure the correct .cuix file was under "Enterprise Customization File"
  • added the folder path with the .CSV file to "Support File Search Path" 
  • removed the default program to open the .CSV file in Windows
  • switched .cuix file and workstation profiles, then switched back.

The only mention of the .CSV file "Master Layer List.CSV" in the LISP code is in reference during the creation of the error dialogue box. The only thing I can think of is that the file path needs to be mentioned in the LISP routine code, but the routine has worked successfully with the same .CSV file in the past. Can someone help me troubleshoot?

 

Thanks in advance

0 Likes
Accepted solutions (2)
900 Views
3 Replies
Replies (3)
Message 2 of 4

CodeDing
Advisor
Advisor
Accepted solution

@cballett ,

 

Welcome to the forums!

 

Looks like you have done a lot of troubleshooting already.

The first thing that comes to mind:

 


@cballett wrote:
  • added the folder path with the .CSV file to "Support File Search Path" 

In addition to having it in the Support File Search Path, I would also add the folder path with the .CSV to the "Trusted Locations".

Then, hit OK to close options dialog, then restart AutoCAD and try again.

Let us know if that helps.

 

Pending Questions:
1) Are you opposed to using a Full Path when searching for the CSV?

 

2) After searching your LSP file briefly, I see your file variable is named "fileName"... I searched your lisp file for that variable name and there are 3 occurrences:

- The 1st occurrence happens inside of a function called "run_me". Here's the line:

(setq fileOpen (open fileName "r"))	

- The 2nd and 3rd occurrences happen inside of a function called "c:aedtlayers". Here's their lines:

(defun c:aetdlayers ( / aDoc colLayers colBlocks colLinestypes olderr fileName dcl_id selSet msflag layerbit flag toggleLayers xrefLayers listXrefs)
.....
(if (not (setq fileName (findfile "Master Layer List.csv")))

...see anything noteworthy? Well, in summary, the "fileName" variable in your "run_me" function is a Global variable and is never defined in the context of your lisp file (unless it's defined in another file somewhere), therefore if it were ever referenced, then it will always evaluate to nil.

Whereas in the 2nd & 3rd instances, it is defined as a Local variable and subsequently defined in the same function. Therefore having the potential to actually be a useful variable.

 

Best,

~DD

Message 3 of 4

cballett
Explorer
Explorer

@CodeDing Thanks for the warm welcome AND the solution! Adding the folder path to "Trusted Locations" worked! I appreciate you combing through the lines of code to bring up those 3 occurrences. My answers are as follows:

1) I am not opposed to using a full path when searching for the file, but this "flow" if you will, was set up to work with OneDrive and looked for a mapped drive label. In this instance, the R: drive is where this file is found. Is that what the lines in the 2nd and 3rd occurrences refer to?

(setq fileOpen (open fileName "r"))

 To reference the local file, would I need to replace "r" with "Master Layer List.csv" ?

 

I think answering your first question gives more context to, and answers, your 2nd and 3rd questions. If I can change the path to reference the specific file, I think I will be ensuring I don't have issues in the future.

 

Thanks again,

-CB

0 Likes
Message 4 of 4

CodeDing
Advisor
Advisor
Accepted solution

Adding the folder path to "Trusted Locations" worked

Glad you got it working

 


1) I am not opposed to using a full path when searching for the file, but this "flow" if you will, was set up to work with OneDrive and looked for a mapped drive label. In this instance, the R: drive is where this file is found.


This brings up more questions, but perhaps only since I don't fully understand your workflow. If you say it's all fixed, no need to go further down the rabbit hole on this one.

 


Is that what the lines in the 2nd and 3rd occurrences refer to?

The 2nd instance of the "fileName" variable is the line where your (defun ...) is created. In that line it is merely defining "fileName" as a local variable (i.e. that variable can only be used/seen inside that one function).

The 3rd instance of the "fileName" variable is "Searching the AutoCAD library and trusted paths for the specified file or directory" (as noted in documentation here)

 


 

(setq fileOpen (open fileName "r"))

 

 To reference the local file, would I need to replace "r" with "Master Layer List.csv" ?


So the line you reference above here is inside the "run_me" function. Which appears to try to perform a lot of tasks. But honestly, I have no idea what happens when the run_me function is called. It could run fine, could error out, could perform only partial tasks... I won't be testing on my end because it would be too intensive for apparently little/no gain. But TBH I would be surprised if the function does not crash when that function is called. 

Sorry, a bit of a tangent there, but this line above appears to be opening a "fileName" that is nil (the "r" means that it is opening the file in read-only mode). But since the fileName appears to be nil, then no file will be opened/read.

 

Best,

~DD