Jump to content

[Solved] - Setvar error


MatthewDS

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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:

 

[color=black](command "_SETVAR" "FIELDEVAL" "31")[/color]

Regards,

Link to comment
Share on other sites

If you are unsure as to what type of value a system variable accepts you could use the TYPE function

Command: (type (getvar "TEXTSTYLE"))
STR
Command: (type (getvar "filletrad"))
REAL
Command: (type (getvar "FIELDEVAL"))
INT
Command: (type (getvar "lastpoint"))
LIST

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...