acad.lsp

acad.lsp

ScottBolton-67
Participant Participant
899 Views
18 Replies
Message 1 of 19

acad.lsp

ScottBolton-67
Participant
Participant

Hi, chaps.

 

I have the code,

 

(strcat "C:\\Users\\" (getvar "USERNAME") "\\blue\\...")

 

in my acad.lsp but it gives the error,

 

Regenerating model.

; error: bad argument type: (or stringp symbolp): (STRCAT "C:\\Users\\" (GETVAR "USERNAME") "\\blue\\...")

AutoCAD menu utilities loaded.

 

at startup.

 

Anybody know why? (I also tried using (getenv) but got the same (or stringp symbolp) error.)

 

0 Likes
Accepted solutions (1)
900 Views
18 Replies
Replies (18)
Message 2 of 19

paullimapa
Mentor
Mentor

no such variable called username

but username is an environment variable

so change the code to:

(strcat "C:\\Users\\" (getenv "USERNAME") "\\blue\\...")

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 19

Kent1Cooper
Consultant
Consultant

There is no "username" System Variable.

Kent Cooper, AIA
0 Likes
Message 4 of 19

pendean
Community Legend
Community Legend

@Kent1Cooper wrote:

There is no "username" System Variable.


Give them a try at the commandline, they report my OS login name here in AutoCAD 2023-2025 (but only LT versions HELP list is as a variable)

(getenv "USERNAME")

(getvar "USERNAME")

USERNAME

 

pendean_0-1731617595846.png

 

pendean_1-1731617750496.png

 

0 Likes
Message 5 of 19

pendean
Community Legend
Community Legend

@ScottBolton-67 What is it you are trying to do or activate or show with that exactly?

0 Likes
Message 6 of 19

pkenewell6347
Advocate
Advocate

Have you tried pasting the line directly to the command line? It works correctly for me. What version of AutoCAD are you using?

 

(strcat "C:\\Users\\" (getvar "USERNAME") "\\blue\\...")

 

 

0 Likes
Message 7 of 19

pendean
Community Legend
Community Legend

@pkenewell6347 wrote:

...It works correctly for me....


Works how? To do what? All I get at the comamndline is 

"C:\\Users\\MYLOGINNAMEHERE\\blue\\..."

0 Likes
Message 8 of 19

pkenewell6347
Advocate
Advocate

?

0 Likes
Message 9 of 19

pkenewell6347
Advocate
Advocate

It seems to me that the OP is trying to find their profile folder in windows? I don't know. All I was doing was confirming it worked in my system (AutoCAD 2025), and trying to figure out why it was not working for the OP. Perhaps he is using a much older version of AutoCAD? Maybe the install is corrupted? I wasn't trying to determine what he was doing, just whether it should work or not.

0 Likes
Message 10 of 19

paullimapa
Mentor
Mentor

Though username may exists as system variable in LT, there was no lisp back in 2020...only staring in 2024LT.

But as for AutoCAD the username system variable did not exist prior to 2023.

So older versions would yield this error:

paullimapa_0-1731689591051.png

Perhaps @ScottBolton-67 OP encountered this error when trying to load acad.lsp in versions prior to 2023?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 11 of 19

pendean
Community Legend
Community Legend

@paullimapa wrote:

Though username may exists as system variable in LT, there was no lisp back in 2020...only staring in 2024LT...


LT versions of AutoCAD have always had a USERNAME variable, it used to reside in OPTIONS as an item you could enter until it was changed in the last decade to capture the user's OS log-in instead. It has nothing to do with the introduction of LISP into LT. Came in handy back when using the PLOTSTAMP on all plots to be user and department specific for those of us that need it.

 

Good point on pre-2023 full AutoCAD, I no longer run anything older to have checked it there.

 

0 Likes
Message 12 of 19

ScottBolton-67
Participant
Participant

So, we've established that (getvar "USERNAME") is valid and it yields the same result as (getvar "LOGINNAME").

 

On the command line, or in the VL Console, both 

(strcat (getenv "UserProfile") "\\sbTOOLS\\...") and
(strcat "C:\\Users\\" (getvar "USERNAME") "\\sbTOOLS\\...")

yield the same result: "C:\\Users\\NLA417\\sbTOOLS\\..." in my case.

The problem arises when it is run from the acad.lsp file:

; error: bad argument type: (or stringp symbolp): (STRCAT (GETENV "UserProfile") "\\sbTOOLS\\...") and

; error: bad argument type: (or stringp symbolp): (STRCAT "C:\\Users\\" (GETVAR "USERNAME") "\\sbTOOLS\\...")

 

I want it loading here because I add that location, sbTOOLS, to my TRUSTEDPATHS,

 

(setvar "TRUSTEDPATHS" (strcat bT_paths ";" bT_nth))

0 Likes
Message 13 of 19

paullimapa
Mentor
Mentor

as a test lets try a different system variable and see if you get a successful response:

(STRCAT "C:\\Users\\" (GETVAR "ctab") "\\sbTOOLS\\...")

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 14 of 19

pkenewell6347
Advocate
Advocate

@ScottBolton-67 wrote:

The problem arises when it is run from the acad.lsp file:

; error: bad argument type: (or stringp symbolp): (STRCAT (GETENV "UserProfile") "\\sbTOOLS\\...") and

; error: bad argument type: (or stringp symbolp): (STRCAT "C:\\Users\\" (GETVAR "USERNAME") "\\sbTOOLS\\...")

 

I want it loading here because I add that location, sbTOOLS, to my TRUSTEDPATHS,

 

(setvar "TRUSTEDPATHS" (strcat bT_paths ";" bT_nth))


Interesting. Question: Do you just run it from acad,lsp, or do you have it within an "S::STARTUP" defun? Perhaps the system variable has not initialized. If you put it in an "S::STARTUP" defun, it waits until last after everything initializes. Also - you should be using acaddoc.lsp instead of acad.lsp if you want this to load in every dwg file.

 

Look at this for more info (scroll down a bit for info on S::STARTUP, but I recommend reading the whole thing):

https://help.autodesk.com/view/ACD/2024/ENU/?guid=GUID-FDB4038D-1620-4A56-8824-D37729D42520

Message 15 of 19

Kent1Cooper
Consultant
Consultant

@pendean wrote:...

Good point on pre-2023 full AutoCAD, I no longer run anything older to have checked it there.


I am currently at an Acad2020 [full vanilla] installation, where (getvar "USERNAME") returns nil.

Kent Cooper, AIA
Message 16 of 19

ec-cad
Collaborator
Collaborator

R2021 vanilla.

(getvar "USERNAME") ; returns nil

(getvar "LOGINNAME") ; returns my name

 

ECCAD

0 Likes
Message 17 of 19

Sea-Haven
Mentor
Mentor

Bricscad V24, (getvar "LOGINNAME") ; returns my name

0 Likes
Message 18 of 19

ScottBolton-67
Participant
Participant
Accepted solution

Thanks for the S::STARTUP tip.

I run it from the acad.lsp, but if I put it in acaddoc.lsp instead it runs fine.

Message 19 of 19

Sea-Haven
Mentor
Mentor

Just a comment I never touch acad & acaddoc.lsp rather use appload and add a custom lisp to the start up suite. I find this easier as the custom lisp is saved with my other lisps. When you do an upgrade just redo the appload, no go searching for acaddoc.

0 Likes