Invalid AutoSavePath

Invalid AutoSavePath

saboh12617
Contributor Contributor
299 Views
4 Replies
Message 1 of 5

Invalid AutoSavePath

saboh12617
Contributor
Contributor

Hello all,

 

Do you know why, using the AutoCAD LT 2025 Help | AutoSavePath Property (ActiveX) | Autodesk, i can not change it to, for instance my desktop :

To make it clear i am certain the path i give is correct, i tried it for other automations and it works, but when i want to change the autosavepath i am facing an issue: I can change it from

%temp% to %temp%/test/ for instance, but it will run an automation error if i target my desktop, which is in read/write as far as i know.

 

Working code :

 

 

 

Sub test()
  Dim z As AcadPreferencesFiles
  Set z = Application.Preferences.Files
  Dim x As String
  x = z.AutoSavePath & "test\"
  
  z.AutoSavePath = x
End Sub

 

 

 

Not working code :

 

 

 

Sub testNotWorking()
  Dim z As AcadPreferencesFiles
  Set z = Application.Preferences.Files
  Dim x As String
  x = "C:\Users\XXXX\Desktop\test\"
  z.AutoSavePath = x
End Sub

 

 

 

0 Likes
Accepted solutions (2)
300 Views
4 Replies
Replies (4)
Message 2 of 5

norman.yuan
Mentor
Mentor

I am not sure I know what you mean by "desktop", when you say "...i can not change it to, for instance my desktop", and " if i target my desktop". Where you tried to run the code you posted from? It certainly cannot run INSIDE AutoCAD LT, because Acad LT DOES NOT support running VBA code. Yes, since ACAD LT 2024, it does support AutoCAD ActiveX/COM API INERNALLY, only via Visual LISP. So, the code you showed is useless with AutoCAD LT. If you have to manipulate autosave path, (or other preferences, for that matter), you need to use VisualLisp to access the COM object Application.AcadPreferences.Files.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 5

Ed__Jobe
Mentor
Mentor
Accepted solution

You pointed to an AutoCAD LT help document. Was that a mistake and you are actually using full AutoCAD, since you said the first code worked? If you can actually run vba, then keep in mind that the backslash is an escape character when passing a string. That means that the character after the backslash has special meaning, e.g. \n means the newline character. Since the backslash and double quote mark have special meaning in programming, preceding them with a backslash passes them as a literal string, e.g. "C:\\Users\\xxxx\\Desktop\\test\\".

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 4 of 5

saboh12617
Contributor
Contributor
Accepted solution

Oh yes sorry i did put the link to the wrong help page, it is just the first one that showed up on google but i am indeed using full AutoCAD.

@ed i first thought of this as well, but i did not know how to escape the "\" in VBA…

I did some tests and for some reason the problem was due to spaces in the directory path. In the last example "XXXX" was like "Paul Palo" and AutoCAD was throwing an error at me. But using VBA' Space function, it worked.

Ie.

Sub testWorking()
  Dim z As AcadPreferencesFiles
  Set z = Application.Preferences.Files

  Dim x As String
  x = "C:\Users\Paul Palo\Desktop\test\"
  ' error here 
  z.AutoSavePath = x
  x = "C:\Users\Paul" & Space(1) & "Palo\Desktop\test\"
  ' no error here 
  z.AutoSavePath = x
End Sub

I reckon the same behavior as in PowerShell commands, maybe internally there are some differences that i am not aware of.

Anyway problem got solved this way. Thanks for your feedbacks, have a good day.

0 Likes
Message 5 of 5

Ed__Jobe
Mentor
Mentor

This is a Windows requirement. All paths that have a space on them must be enclosed in double quotes. As I pointed out last time, you need to escape these too. 
"\”C:\\Users\\Paul Palo\\Desktop\\test\\\”".

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature