[Solved] - Setvar error
I was having some trouble with a very simple setvar command in a lisp script, as such:(setvar "FIELDEVAL" "31");
which was giving me this error:
AutoCADvariable setting rejected: "CMDECHO" nil
It turns out that you cannot have quotes around the 31, and that it should have read:
(setvar "FIELDEVAL" 31); This is fixed now
I looked through my code and found places where I had used quotes to enclose variables, so maybe you can do it with some variables and not others?Does anybody have any input on this?
For example, this seemed to work:
(setvar "TEXTSTYLE" "Some-Style");
Hopefully this helps somebody in the future. System Variables are of different data types whether it be Double, Integer, String, etc.
A reference for these can be found using the System variable editor (Sysvdlg) in AutoCAD, or another reference such as this.
As for the error you are receiving, that is due to an unlocalised error handler within a routine loaded on your system. The best policy for you error handler (after making sure it's localized) would be to check and make sure the the variable has a value before trying to set a variable with said value.
eg.
At some point in time in the routine.
(setq OldCmdecho (getvar 'cmdecho))In your error handler, you would check before trying to set with:
(if OldCmdecho (setvar 'cmdecho OldCmdecho))or
(and OldCmdecho (setvar 'cmdecho OldCmdecho))
Both will check the variable before trying to set with it.
There are other fancier ways, but these are the simplest. To be able to ignore the data type of a system variable may use the below approach that will allow you to use only strings:
(command "_SETVAR" "FIELDEVAL" "31")Regards, If you are unsure as to what type of value a system variable accepts you could use the TYPE function
Command: (type (getvar "TEXTSTYLE"))STRCommand: (type (getvar "filletrad"))REALCommand: (type (getvar "FIELDEVAL"))INTCommand: (type (getvar "lastpoint"))LIST
页:
[1]