Convert system variable name to text

Convert system variable name to text

carlos_m_gil_p
Advocate Advocate
1,426 Views
15 Replies
Message 1 of 16

Convert system variable name to text

carlos_m_gil_p
Advocate
Advocate

Hello boys how are you.
I wanted to ask you, how can I convert the name of a system variable to text?

 

I have tried various options and none of them work for me.

 

(vl-prin1-to-string UCSNAME)
(vl-princ-to-string UCSNAME)
(strcat "\"" UCSNAME "\"")

 

I just want to write the name of the system variable and it returns me:

 

"UCSNAME"

 

Thank you very much in what you can help me.


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
1,427 Views
15 Replies
Replies (15)
Message 2 of 16

pbejse
Mentor
Mentor

@carlos_m_gil_p wrote:

I just want to write the name of the system variable and it returns me:

 

 

The system variable name ? or its value?  if you know the system variable name you can just type it as it is "UCSNAME"

 

(strcat "UCSNAME: " (getvar "UCSNAME"))

 

 

 

0 Likes
Message 3 of 16

carlos_m_gil_p
Advocate
Advocate

Hi @pbejse , thank you for your answer.
I don't want its value.
I want to convert is the name of the variable.


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
Message 4 of 16

pbejse
Mentor
Mentor

@carlos_m_gil_p wrote:

Hi @pbejse , thank you for your answer.
I don't want its value.
I want to convert is the name of the variable.


(vl-symbol-name 'USERNAME)
or
(vl-symbol-name (quote USERNAME))
Message 5 of 16

Kent1Cooper
Consultant
Consultant

I don't understand....  What do you want to do with it?  All suggestions so far require putting the name into some code, but if you have to include the name in whatever you're doing, can't you just use the name, period?  If you want it in a variable, put it in one:
(setq YourVariableName "UCSNAME")

If you want to use that somehow not as a text string [without the quotation marks]:

(setq YourVariableName (read "UCSNAME"))

Or am I completely missing the boat?

Kent Cooper, AIA
0 Likes
Message 6 of 16

john.uhden
Mentor
Mentor

Although I see no purpose, perhaps he wants to do something like...

(foreach var '("UCSNAME" "CLAYER" "PLINEWID")
  (set (read var)(getvar var))
)

But he was looking at it as having to convert the symbol to a string...

(foreach var '(ucsname clayer plinewid)
  (set var (getvar (vl-symbol-name var)))
)

BTW, what does "missing the boat" mean?

  You lost your boat?

  You sold your boat and you miss it?

  You didn't make it onto the boat? (It set sail without you)

  Your cannonball shot fell short of the enemy ship?

  You'll be getting no gravy for your turkey?

John F. Uhden

Message 7 of 16

carlos_m_gil_p
Advocate
Advocate

Hi everybody how are you.
Thank you for all the help provided and your teachings.
I need it for something personal, like printing on the screen the names of the variables that I use the most, to keep them in mind.
But I didn't want to be typing all the quotes.
But it couldn't do it because it wasn't a text string.
But now I realize that in other functions that I used to extract the value of the variable it does not work for me.
For example:

 

 

(setq val (nv UCSNAME))

(defun nv (v) 
  (vlax-variant-value 
  (vla-GetVariable 
    (vla-get-activedocument (vlax-get-acad-object))
    (vl-symbol-name (quote v)))))

 

 

What I want to avoid is having to put quotes and apostrophe.


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
Message 8 of 16

Kent1Cooper
Consultant
Consultant

@carlos_m_gil_p wrote:

....

What I want to avoid is having to put quotes and apostrophe.


I'm not sure whether that means you already know this, but you don't need to put double-quotes at both ends.  A single apostrophe at the beginning only is sufficient in either (getvar) or (setvar) functions:

  (getvar 'ucsname)

The last time I looked, Help for one of those functions used the double-quotes at both ends in its example(s), and for the other used the apostrophe at the beginning only, but either way works in either function.

Kent Cooper, AIA
0 Likes
Message 9 of 16

Sea-Haven
Mentor
Mentor

Maybe something like this, could have a two value list ((layer clayer) (layout ctab).... if filletrad then 3 values in list

 

 

 

(defun c:myvars ()
(alert (strcat "Variables"
"\nCurrent tab " (getvar 'ctab)
"\nCurrent layer " (getvar 'clayer)
"\nCurrent ucs " (getvar 'ucsname)
"\nCurrent radius " (rtos (getvar 'filletrad) 2 3)
"\nCurrent hatch " (getvar 'hpname)
)
)
)

 

 

0 Likes
Message 10 of 16

pbejse
Mentor
Mentor

@carlos_m_gil_p wrote:
..
(setq val (nv UCSNAME))

But it couldn't do it because it wasn't a text string.

...


Clear this up for us, what is the source of it?  Assuming this is the argument, how if is this pass to the subfunction?

Is it define during run-time as a result of an operation?  If its not a string or hard-coded item on your code, then what is it?

 


@carlos_m_gil_p wrote:

I need it for something personal, like printing on the screen the names of the variables that I use the most,


 

And here's another thing, are you referring to the system variables of your own defined variables?

 

0 Likes
Message 11 of 16

carlos_m_gil_p
Advocate
Advocate

Hello thanks for everyone's responses.
I just wanted to do a command to remember the variables that I use the most.
With the pbejse option it worked fine, for what I needed. (vl-symbol-name (quote UCSNAME))

Previously I did it like this. (setq val (nv "UCSNAME")) placing the quotes and it worked.

Now I thought that it would not be necessary to place quotes, nor to place an apostrophe, it is more comfortable to write only the word and that the function takes care of everything.


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
Message 12 of 16

pbejse
Mentor
Mentor

@john.uhden wrote:

BTW, what does "missing the boat" mean?

  You lost your boat?

  You sold your boat and you miss it?

  You didn't make it onto the boat? (It set sail without you)

  Your cannonball shot fell short of the enemy ship?

  You'll be getting no gravy for your turkey?


 

As always, John ask the quesions nobody else thought of asking, but I do want to know the answer to that too 🙂

 

 

0 Likes
Message 13 of 16

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:

BTW, what does "missing the boat" mean?

  You lost your boat?

  You sold your boat and you miss it?

  You didn't make it onto the boat? (It set sail without you)

  Your cannonball shot fell short of the enemy ship?

  You'll be getting no gravy for your turkey?


Maybe it's a regional thing, but it's the third one, as a metaphor for being [to use other metaphors] "left in the dust" -- the "train of thought" escapes me.

Kent Cooper, AIA
0 Likes
Message 14 of 16

Kent1Cooper
Consultant
Consultant

@carlos_m_gil_p wrote:

....
I need it for ... printing on the screen the names of the variables that I use the most, to keep them in mind....


So I still don't get it.  Presumably under that description, you would not be typing them in [whether in quotation marks or with preceding apostrophes or neither], but something, somehow, would be keeping track for you, and it would notify you about which you have used most often.  How would you invoke whatever such a reminder would be?  A Tool Palette button?  A keystroke combination?  A custom command?

 

Or, if it's just an index of the ones you like to use so you don't forget what they're called, and not a record of those you have used recently, again, how would you invoke it?  Whether it pops up as an (alert) or Notepad is started up in a text file, or some other method, then presumably you would need to type up the list only once, and perhaps edit it occasionally.  If that's the idea, what does it really matter whether you need to include quotation marks?  The time you and we have spent in this discussion is far more than would be needed to include a couple more keystrokes in an enormously long list of variables.

 

Or how about taping a piece of paper to the side of your monitor?

Kent Cooper, AIA
0 Likes
Message 15 of 16

Sea-Haven
Mentor
Mentor

I agree with you Kent if you must know make a list of correct values (("osmode" 47).... then just read list and make a string using strcat that you use with an alert, it will only display the ones that are different. Not a difficult lisp task.

str= "osmode is 0 not 47 \nucsname is myroad not World" and so on. (alert str)

 

Hey look at what is built in "sysvarmonitor"

 

screenshot354.png

 

 

 

 

 

0 Likes
Message 16 of 16

carlos_m_gil_p
Advocate
Advocate

Hello, how are you, thanks for everyone's responses.
They are absolutely right, I am going to write all of them, it is not much difference, because it is only once that I have to do it.
Thank you again for your time and dedication.
Greetings to all.


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes